├── README.md ├── Source ├── CMakeLists.txt ├── SIMDCosts.hpp ├── SIMDTypes.hpp ├── AugRieGeoClawSolver.hpp ├── WavePropagationSolver.hpp ├── SIMDDefinitions.hpp ├── FWaveVecSolver.hpp ├── HybridWaveSolver.hpp ├── FWaveCUDASolver.hpp ├── FWaveSolver.hpp ├── HLLEFunSolver.hpp ├── AugRieCUDASolver.hpp └── AugRieFunSolver.hpp ├── .gitignore ├── CMakeLists.txt ├── .clang-format └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | SWE-Solvers 2 | =========== 3 | 4 | Solvers for the Shallow Water Equations. 5 | -------------------------------------------------------------------------------- /Source/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(${META_PROJECT_NAME} INTERFACE) 2 | 3 | file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*") 4 | source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) 5 | target_sources(${META_PROJECT_NAME} INTERFACE ${SOURCES}) 6 | target_include_directories(${META_PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) 7 | 8 | target_include_directories(${META_PROJECT_NAME} 9 | INTERFACE 10 | "$" 11 | "$") 12 | 13 | option(ENABLE_AUGMENTED_RIEMANN_EIGEN_COEFFICIENTS "Enable augmented Riemann eigen coefficients" OFF) 14 | if(ENABLE_AUGMENTED_RIEMANN_EIGEN_COEFFICIENTS) 15 | target_compile_definitions(${META_PROJECT_NAME} INTERFACE ENABLE_AUGMENTED_RIEMANN_EIGEN_COEFFICIENTS) 16 | endif() 17 | 18 | add_custom_target(${META_PROJECT_NAME}- SOURCES ${SOURCES}) 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | *.ko 10 | *.elf 11 | 12 | # Linker output 13 | *.ilk 14 | *.map 15 | *.exp 16 | 17 | # Precompiled Headers 18 | *.gch 19 | *.pch 20 | 21 | # Compiled Dynamic libraries 22 | *.so 23 | *.dylib 24 | *.dll 25 | 26 | # Fortran module files 27 | *.mod 28 | *.smod 29 | 30 | # Compiled Static libraries 31 | *.lai 32 | *.la 33 | *.a 34 | *.lib 35 | 36 | # Executables 37 | *.exe 38 | *.out 39 | *.app 40 | *.i*86 41 | *.x86_64 42 | *.hex 43 | 44 | # Debug files 45 | *.dSYM/ 46 | *.su 47 | *.idb 48 | *.pdb 49 | 50 | # Kernel Module Compile Results 51 | *.mod* 52 | *.cmd 53 | .tmp_versions/ 54 | modules.order 55 | Module.symvers 56 | Mkfile.old 57 | dkms.conf 58 | 59 | # CUDA 60 | *.i 61 | *.ii 62 | *.gpu 63 | *.ptx 64 | *.cubin 65 | *.fatbin 66 | 67 | # Generated documentation 68 | html/* 69 | 70 | # Misc 71 | .DS_Store 72 | .vscode/* 73 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.21) 2 | 3 | set(META_PROJECT_NAME "SWE-Solvers") 4 | set(META_PROJECT_DESCRIPTION "Solvers for the Shallow Water Equations") 5 | set(META_AUTHOR_ORGANIZATION "Technische Universitaet Muenchen") 6 | set(META_AUTHOR_DOMAIN "https://github.com/TUM-I5/SWE-Solvers") 7 | set(META_VERSION_REVISION "${GIT_COMMIT_HASH_SHORT}") 8 | set(META_GIT_BRANCH "${GIT_BRANCH}") 9 | set(META_GIT_HASH "${GIT_COMMIT_HASH}") 10 | message(STATUS "On Git Branch: ${GIT_BRANCH} (${GIT_COMMIT_HASH})") 11 | 12 | set(CMAKE_CXX_STANDARD 20) 13 | set(CMAKE_CXX_STANDARD_REQUIRED TRUE) 14 | set(CMAKE_CXX_VISIBILITY_PRESET hidden) 15 | set(CMAKE_CXX_VISIBILITY_INLINES_HIDDEN YES) 16 | set(CMAKE_CXX_EXTENSIONS OFF) 17 | set(META_COMPILER_VERSION "${CMAKE_SYSTEM_NAME} ${CMAKE_CXX_COMPILER_ID} (${CMAKE_CXX_COMPILER_VERSION})") 18 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 19 | set(CMAKE_POSITION_INDEPENDENT_CODE OFF) 20 | 21 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 22 | set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${META_PROJECT_NAME}) 23 | 24 | project(${META_PROJECT_NAME} 25 | DESCRIPTION ${META_PROJECT_DESCRIPTION} 26 | HOMEPAGE_URL ${META_AUTHOR_DOMAIN} 27 | LANGUAGES C CXX 28 | ) 29 | file(WRITE "${PROJECT_BINARY_DIR}/.gitignore" "*") 30 | 31 | add_subdirectory(Source) 32 | -------------------------------------------------------------------------------- /Source/SIMDCosts.hpp: -------------------------------------------------------------------------------- 1 | /***********************************************************************************/ /** 2 | * 3 | * \file SIMD_COSTS.hpp 4 | * 5 | * \brief Contains latency costs 6 | *for the intrinsics used for the 7 | *vectorization 8 | * 9 | * \author Wolfgang Hölzl 10 | *(hoelzlw), hoelzlw AT in.tum.de 11 | * 12 | **************************************************************************************/ 13 | 14 | #pragma once 15 | 16 | #ifndef SIMD_COSTS_H 17 | #define SIMD_COSTS_H 18 | 19 | #ifdef COUNTFLOPS 20 | 21 | #ifndef SIMD_TYPES_H 22 | #error "SIMD_COSTS included without SIMD_TYPES! Never include this file directly! Include it only via SIMD_TYPES!" 23 | #endif /* defined SIMD_TYPES_H */ 24 | 25 | #define COSTS_ADDS 1 26 | #define COSTS_SUBS 1 27 | #define COSTS_MULS 1 28 | #define COSTS_DIVS 1 29 | #define COSTS_SQRTS 1 30 | 31 | #define COSTS_MAXS 1 32 | #define COSTS_MINS 1 33 | 34 | #define COSTS_CMPS 0 35 | 36 | #define COSTS_ANDS 0 37 | #define COSTS_ORS 0 38 | 39 | #define COSTS_FABSS 1 40 | 41 | #if defined VECTOR_SSE4_FLOAT32 42 | #define COSTS_ADDV 4 43 | #define COSTS_SUBV 4 44 | #define COSTS_MULV 4 45 | #define COSTS_DIVV 4 46 | #define COSTS_SQRTV 4 47 | 48 | #define COSTS_LOADU 0 49 | #define COSTS_STOREU 0 50 | #define COSTS_SETV_R 0 51 | #define COSTS_SETV_I 0 52 | #define COSTS_ZEROV_R 0 53 | #define COSTS_ZEROV_I 0 54 | 55 | #define COSTS_MAXV 4 56 | #define COSTS_MINV 4 57 | 58 | #define COSTS_CMP_LT 0 59 | #define COSTS_CMP_LE 0 60 | #define COSTS_CMP_GT 0 61 | #define COSTS_CMP_GE 0 62 | 63 | #define COSTS_CMP_EQ_I 0 64 | 65 | #define COSTS_ANDV_R 0 66 | #define COSTS_ORV_R 0 67 | #define COSTS_XORV_R 0 68 | #define COSTS_ORV_I 0 69 | #define COSTS_ANDNOTV_R 0 70 | 71 | #define COSTS_BLENDV 0 72 | #define COSTS_BLENDV_I 0 73 | #define COSTS_MOVEMASK 0 74 | #define COSTS_SHIFT_LEFT 0 75 | 76 | #define COSTS_FABS 4 77 | #define COSTS_NOTV_R 0 78 | #define COSTS_NOTV_I 0 79 | #elif defined VECTOR_SSE4_FLOAT64 80 | #error "SSE4 with double precision not implemented at the moment" 81 | #elif defined VECTOR_AVX_FLOAT32 82 | #define COSTS_ADDV 8 83 | #define COSTS_SUBV 8 84 | #define COSTS_MULV 8 85 | #define COSTS_DIVV 8 86 | #define COSTS_SQRTV 8 87 | 88 | #define COSTS_LOADU 0 89 | #define COSTS_STOREU 0 90 | #define COSTS_SETV_R 0 91 | #define COSTS_SETV_I 0 92 | #define COSTS_ZEROV_R 0 93 | #define COSTS_ZEROV_I 0 94 | 95 | #define COSTS_MAXV 8 96 | #define COSTS_MINV 8 97 | 98 | #define COSTS_CMP_LT 0 99 | #define COSTS_CMP_LE 0 100 | #define COSTS_CMP_GT 0 101 | #define COSTS_CMP_GE 0 102 | #define COSTS_CMP_EQ_I 0 103 | 104 | #define COSTS_ANDV_R 0 105 | #define COSTS_ORV_R 0 106 | #define COSTS_XORV_R 0 107 | #define COSTS_ORV_I 0 108 | #define COSTS_ANDNOTV_R 0 109 | 110 | #define COSTS_BLENDV 0 111 | #define COSTS_BLENDV_I 0 112 | #define COSTS_MOVEMASK 0 113 | #define COSTS_SHIFT_LEFT 0 114 | 115 | #define COSTS_FABS 8 116 | #define COSTS_NOTV_R 0 117 | #define COSTS_NOTV_I 0 118 | #elif defined VECTOR_AVX_FLOAT64 119 | #error "AVX with double precision not implemented at the moment" 120 | #else /* no vectorization type defined */ 121 | #pragma message "SIMD-Costs included, but no Vector-Type defined." 122 | #endif 123 | 124 | #endif /* not defined COUNTFLOPS */ 125 | 126 | #endif /* #ifndef SIMD_COSTS_H */ 127 | -------------------------------------------------------------------------------- /Source/SIMDTypes.hpp: -------------------------------------------------------------------------------- 1 | /***********************************************************************************/ /** 2 | * 3 | * \file SIMD_TYPES.hpp 4 | * 5 | * \brief Defines the length of 6 | *the vectors and the 7 | *corresponding functions 8 | * 9 | * \author Wolfgang Hölzl 10 | *(hoelzlw), hoelzlw AT in.tum.de 11 | * 12 | **************************************************************************************/ 13 | 14 | #pragma once 15 | 16 | #ifndef SIMD_TYPES_H 17 | #define SIMD_TYPES_H 18 | 19 | /* 20 | * Check, whether the function definitions are already included. 21 | * If yes, this denotes an error. 22 | * 23 | * The SIMD_DEFINITIONS.hpp-file needs the control macros set in this file to work properly. 24 | */ 25 | #ifdef SIMD_DEFINITIONS_H 26 | #error \ 27 | "SIMD Definitions already included! Never include that file directly! Include it only via including SIMD_TYPES (this file!)" 28 | #endif /* defined SIMD_DEFINITIONS_H */ 29 | 30 | /* 31 | * Check, whether a solver is chosen, that uses the macros in this file. 32 | */ 33 | #if not WAVE_PROPAGATION_SOLVER == 5 34 | #pragma message "SIMD macros included but non-vectorized solver specified" 35 | #endif /* not WAVE_PROPAGATION_SOLVER == 5 */ 36 | 37 | /* 38 | * Care about precision. 39 | * Use single precision as default. 40 | * 41 | * Additionally, declare the macro SHIFT_SIGN_RIGHT to work properly with 32 and 64 bit. 42 | * Note the INTENTIONALLY FORGOTTEN semicolon at the end of the SHIFT_SIGN_RIGHT-definitions. 43 | * This forces the user to write the semicolon himself! 44 | */ 45 | #if defined FLOAT64 46 | #pragma message "Using double as type for real numbers" 47 | typedef double real; 48 | #pragma message "Using unsigned long long as type for integer numbers" 49 | typedef unsigned long long integer; 50 | 51 | #define SHIFT_SIGN_RIGHT(x) \ 52 | static_cast(static_cast(1) << (static_cast(64) - static_cast(x))) 53 | #else /* not defined FLOAT64 */ 54 | #pragma message "Using float as type for real numbers" 55 | typedef float real; 56 | #pragma message "Using unsigned int as type for integer numbers" 57 | typedef unsigned int integer; 58 | 59 | #define SHIFT_SIGN_RIGHT(x) (1 << (32 - static_cast(x))) 60 | #endif /* not defined FLOAT64 */ 61 | 62 | /* 63 | * Set control macros 64 | * 65 | * Declare the vector length 66 | * Additionally declare a configuration specific macro of the form 67 | * VECTOR_extension_precision 68 | * 69 | * Moreover, declare an integer, representing the number, 70 | * which is returned by the instruction MOVEMASK, if the instruction is called on a vector with ALL SIGN BITS set 71 | * Use is as 72 | * 73 | * const real_vector vector = CONDITION(operand_a, operand_b); 74 | * 75 | * if (MOVEMASK(vector) == VECTOR_FULL_MASK) { 76 | * // all components fullfill the condition 77 | * } else { 78 | * // some components do not fullfill the condition 79 | * } 80 | */ 81 | #if (defined __SSE4_1__ and not defined __AVX__) or (defined __AVX__ and defined AVX128) 82 | #pragma message "Using SSE4.1 for vectorization" 83 | #include 84 | 85 | typedef __m128i integer_vector; 86 | #if defined FLOAT64 87 | #define VECTOR_LENGTH 2 88 | #define VECTOR_SSE4_FLOAT64 89 | #define VECTOR_FULL_MASK 0x00000003 90 | 91 | typedef __m128d real_vector; 92 | #pragma message "Using vectors of 2 doubles" 93 | #else /* not defined FLOAT64 */ 94 | #define VECTOR_LENGTH 4 95 | #define VECTOR_SSE4_FLOAT32 96 | #define VECTOR_FULL_MASK 0x0000000F 97 | 98 | typedef __m128 real_vector; 99 | #pragma message "Using vectors of 4 floats" 100 | #endif /* not defined FLOAT64 */ 101 | #elif defined __AVX__ 102 | #pragma message "Using AVX for vectorization" 103 | #include 104 | 105 | typedef __m256i integer_vector; 106 | #if defined FLOAT64 107 | #define VECTOR_LENGTH 4 108 | #define VECTOR_AVX_FLOAT64 109 | #define VECTOR_FULL_MASK 0x0000000F 110 | 111 | typedef __m256d real_vector; 112 | #pragma message "Using vectors of 4 doubles" 113 | #else /* not defined FLOAT64 */ 114 | #define VECTOR_LENGTH 8 115 | #define VECTOR_AVX_FLOAT32 116 | #define VECTOR_FULL_MASK 0x000000FF 117 | 118 | typedef __m256 real_vector; 119 | #pragma message "Using vectors of 8 floats" 120 | #endif /* not defined FLOAT64 */ 121 | #else /* not defined __SSE4__ and not defined __AVX__ */ 122 | #pragma message "Using no vectorization at all" 123 | #define VECTOR_LENGTH 1 124 | #define VECTOR_NOVEC 125 | #endif /* not defined __SSE4__ and not defined __AVX__ */ 126 | 127 | /* 128 | * Control macros are set 129 | * 130 | * Include the function macros 131 | */ 132 | #include "SIMD_DEFINITIONS.hpp" 133 | 134 | /* 135 | * Include the cost macros if flop counting is demanded 136 | */ 137 | #if defined COUNTFLOPS 138 | #include "SIMD_COSTS.hpp" 139 | #endif /* defined COUNTFLOPS */ 140 | 141 | #endif /* #ifndef SIMD_TYPES_H */ 142 | -------------------------------------------------------------------------------- /Source/AugRieGeoClawSolver.hpp: -------------------------------------------------------------------------------- 1 | /** @file This file is part of the swe_solvers repository: https://github.com/TUM-I5/swe_solvers 2 | * 3 | * @author Alexander Breuer (breuera AT in.tum.de, http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer) 4 | * 5 | * @section LICENSE 6 | * This software was developed at Technische Universitaet Muenchen, who is the owner of the software. 7 | * 8 | * According to good scientific practice, publications on results achieved in whole or in part due to this software 9 | * should cite at least one paper or referring to an URL presenting the this software software. 10 | * 11 | * The owner wishes to make the software available to all users to use, reproduce, modify, distribute and redistribute 12 | * also for commercial purposes under the following conditions of the original BSD license. Linking this software module 13 | * statically or dynamically with other modules is making a combined work based on this software. Thus, the terms and 14 | * conditions of this license cover the whole combination. As a special exception, the copyright holders of this 15 | * software give you permission to link it with independent modules or to instantiate templates and macros from this 16 | * software's source files to produce an executable, regardless of the license terms of these independent modules, and 17 | * to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each 18 | * linked independent module, the terms and conditions of this license of that module. 19 | * 20 | * Copyright (c) 2012 21 | * Technische Universitaet Muenchen 22 | * Department of Informatics 23 | * Chair of Scientific Computing 24 | * http://www5.in.tum.de/ 25 | * 26 | * All rights reserved. 27 | * 28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the 29 | * following conditions are met: 30 | * 31 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following 32 | * disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the 33 | * following disclaimer in the documentation and/or other materials provided with the distribution. All advertising 34 | * materials mentioning features or use of this software must display the following acknowledgement: This product 35 | * includes software developed by the Technische Universitaet Muenchen (TUM), Germany, and its contributors. Neither the 36 | * name of the Technische Universitaet Muenchen, Munich, Germany nor the names of its contributors may be used to 37 | * endorse or promote products derived from this software without specific prior written permission. 38 | * 39 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 40 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 41 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 43 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 44 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 45 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 46 | * 47 | * @section DESCRIPTION 48 | * Binds GeoClaw's augmented solver to C. 49 | * 50 | * @section ACKNOWLEDGMENTS 51 | * Special thanks go to R.J. LeVeque and D.L. George for publishing their code. 52 | */ 53 | 54 | // number of f-waves in the Problem (2 shock linearization = 2, augmented = 3) 55 | #ifndef NUMBER_OF_FWAVES 56 | #define NUMBER_OF_FWAVES 3 57 | #endif 58 | 59 | /** 60 | * Extern declaration of the c_bing_geoclaw_riemann_aug_JCP routine (fixed arrays). 61 | * 62 | * @param i_maxNumberOfRiemannIterations maximum number Riemann iterations (solver might iterate over the Riemann 63 | * problem one day, currently fixed to 1) 64 | * @param i_variablesLeft array containing variables of the left cell: $(h_l, hu_l, b_l)^T$ 65 | * @param i_variablesRight array containing variables of the right cell: $(h_l, hu_l, b_l)^T$ 66 | * @param i_dryTol dry tolerance (definition of wet/dry cells). 67 | * @param i_g gravity constant (typically 9.81). 68 | * @param o_netUpdatesLeft will be set to: Net-update for the height(0)/normal momentum(1)/parallel momentum(2) of the 69 | * cell on the left side of the edge. 70 | * @param o_netUpdatesRight will be set to: Net-update for the height(0)/normal momentum(1)/parallel momentum(2) of the 71 | * cell on the right side of the edge. 72 | * @param o_waveSpeeds will be set to: (linearized) wave speeds -> Should be used in the CFL-condition. 73 | */ 74 | extern "C" void c_bind_geoclaw_riemann_aug_JCP( 75 | const int& i_maxNumberOfRiemannIterations, 76 | const double i_variablesLeft[3], 77 | const double i_variablesRight[3], 78 | const double& i_dryTol, 79 | const double& i_g, 80 | double o_netUpdatesLeft[3], 81 | double o_netUpdatesRight[3], 82 | double o_waveSpeeds[NUMBER_OF_FWAVES] 83 | #if AUGMENTED_RIEMANN_EIGEN_COEFFICIENTS 84 | , 85 | double o_eigenCoefficients[NUMBER_OF_FWAVES] 86 | #endif 87 | ); 88 | 89 | /** 90 | * Extern declaration of the c_bing_geoclaw_riemann_aug_JCP routine (pointers). 91 | * 92 | * @param i_maxNumberOfRiemannIterations maximum number Riemann iterations (solver might iterate over the Riemann 93 | * problem one day, currently fixed to 1) 94 | * @param i_variablesLeft array containing variables of the left cell: $(h_l, hu_l, b_l)^T$ 95 | * @param i_variablesRight array containing variables of the right cell: $(h_l, hu_l, b_l)^T$ 96 | * @param i_dryTol dry tolerance (definition of wet/dry cells). 97 | * @param i_g gravity constant (typically 9.81). 98 | * @param o_netUpdatesLeft will be set to: Net-update for the height(0)/normal momentum(1)/parallel momentum(2) of the 99 | * cell on the left side of the edge. 100 | * @param o_netUpdatesRight will be set to: Net-update for the height(0)/normal momentum(1)/parallel momentum(2) of the 101 | * cell on the right side of the edge. 102 | * @param o_waveSpeeds will be set to: (linearized) wave speeds -> Should be used in the CFL-condition. 103 | */ 104 | extern "C" void c_bind_geoclaw_riemann_aug_JCP( 105 | const int& i_maxNumberOfRiemannIterations, 106 | const double* i_variablesLeft, 107 | const double* i_variablesRight, 108 | const double& i_dryTol, 109 | const double& i_g, 110 | double* o_netUpdatesLeft, 111 | double* o_netUpdatesRight, 112 | double* o_waveSpeeds 113 | #if AUGMENTED_RIEMANN_EIGEN_COEFFICIENTS 114 | , 115 | double* o_eigenCoefficients 116 | #endif 117 | ); 118 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: LLVM 4 | AccessModifierOffset: -2 5 | AlignAfterOpenBracket: BlockIndent 6 | AlignArrayOfStructures: None 7 | AlignConsecutiveMacros: None 8 | AlignConsecutiveAssignments: true 9 | AlignConsecutiveBitFields: None 10 | AlignConsecutiveDeclarations: true 11 | AlignEscapedNewlines: DontAlign 12 | AlignOperands: Align 13 | AlignTrailingComments: true 14 | AllowAllArgumentsOnNextLine: true 15 | AllowAllParametersOfDeclarationOnNextLine: true 16 | AllowShortEnumsOnASingleLine: true 17 | AllowShortBlocksOnASingleLine: Never 18 | AllowShortCaseLabelsOnASingleLine: false 19 | AllowShortFunctionsOnASingleLine: All 20 | AllowShortLambdasOnASingleLine: All 21 | AllowShortIfStatementsOnASingleLine: Never 22 | AllowShortLoopsOnASingleLine: false 23 | AlwaysBreakAfterDefinitionReturnType: None 24 | AlwaysBreakAfterReturnType: None 25 | AlwaysBreakBeforeMultilineStrings: false 26 | AlwaysBreakTemplateDeclarations: Yes 27 | AttributeMacros: 28 | - __capability 29 | BinPackArguments: false 30 | BinPackParameters: false 31 | BraceWrapping: 32 | AfterCaseLabel: false 33 | AfterClass: false 34 | AfterControlStatement: Never 35 | AfterEnum: false 36 | AfterFunction: false 37 | AfterNamespace: false 38 | AfterObjCDeclaration: false 39 | AfterStruct: false 40 | AfterUnion: false 41 | AfterExternBlock: false 42 | BeforeCatch: false 43 | BeforeElse: false 44 | BeforeLambdaBody: false 45 | BeforeWhile: false 46 | IndentBraces: false 47 | SplitEmptyFunction: true 48 | SplitEmptyRecord: true 49 | SplitEmptyNamespace: true 50 | BreakBeforeBinaryOperators: All 51 | BreakBeforeConceptDeclarations: true 52 | BreakBeforeBraces: Attach 53 | BreakBeforeInheritanceComma: false 54 | BreakInheritanceList: AfterColon 55 | BreakBeforeTernaryOperators: true 56 | BreakConstructorInitializersBeforeComma: false 57 | BreakConstructorInitializers: AfterColon 58 | BreakAfterJavaFieldAnnotations: false 59 | BreakStringLiterals: true 60 | ColumnLimit: 120 61 | CommentPragmas: '^ IWYU pragma:' 62 | QualifierAlignment: Left 63 | CompactNamespaces: false 64 | ConstructorInitializerIndentWidth: 2 65 | ContinuationIndentWidth: 2 66 | Cpp11BracedListStyle: true 67 | DeriveLineEnding: true 68 | DerivePointerAlignment: false 69 | DisableFormat: false 70 | EmptyLineAfterAccessModifier: Never 71 | EmptyLineBeforeAccessModifier: LogicalBlock 72 | ExperimentalAutoDetectBinPacking: false 73 | PackConstructorInitializers: Never 74 | BasedOnStyle: '' 75 | ConstructorInitializerAllOnOneLineOrOnePerLine: false 76 | AllowAllConstructorInitializersOnNextLine: true 77 | FixNamespaceComments: true 78 | ForEachMacros: 79 | - foreach 80 | - Q_FOREACH 81 | - BOOST_FOREACH 82 | IfMacros: 83 | - KJ_IF_MAYBE 84 | IncludeBlocks: Regroup 85 | IncludeCategories: 86 | IncludeCategories: 87 | - Regex: '"StdAfx.(h|hpp)"' # 0 / 88 | Priority: -1 89 | SortPriority: -1 90 | CaseSensitive: false 91 | - Regex: '<[^/]*>' # 0 / 92 | Priority: 1 93 | SortPriority: 1 94 | CaseSensitive: false 95 | - Regex: '<[^/]+/[^/]+>' # 1 / 96 | Priority: 1 97 | SortPriority: 2 98 | CaseSensitive: false 99 | - Regex: '<([^/]+/){2}[^/]+>' # 2 / 100 | Priority: 1 101 | SortPriority: 3 102 | CaseSensitive: false 103 | - Regex: '<([^/]+/){3}[^/]+>' # 3 / 104 | Priority: 1 105 | SortPriority: 4 106 | CaseSensitive: false 107 | - Regex: '<([^/]+/){4}[^/]+>' # 4 / 108 | Priority: 1 109 | SortPriority: 5 110 | CaseSensitive: false 111 | - Regex: '<([^/]+/){5}[^/]+>' # 5 / 112 | Priority: 1 113 | SortPriority: 6 114 | CaseSensitive: false 115 | - Regex: '<([^/]+/){6,}[^/]+>' # 6 and up / 116 | Priority: 1 117 | SortPriority: 7 118 | CaseSensitive: false 119 | - Regex: '"[^/]*"' # 0 / 120 | Priority: 2 121 | SortPriority: 8 122 | CaseSensitive: false 123 | IncludeIsMainRegex: '(_test)?$' 124 | IncludeIsMainSourceRegex: '' 125 | IndentAccessModifiers: false 126 | IndentCaseLabels: false 127 | IndentCaseBlocks: false 128 | IndentGotoLabels: true 129 | IndentPPDirectives: None 130 | IndentExternBlock: AfterExternBlock 131 | IndentRequires: false 132 | IndentWidth: 2 133 | IndentWrappedFunctionNames: true 134 | #Needs clang format 15 135 | #IndentRequiresClause: true 136 | InsertTrailingCommas: None 137 | JavaScriptQuotes: Leave 138 | JavaScriptWrapImports: true 139 | KeepEmptyLinesAtTheStartOfBlocks: true 140 | LambdaBodyIndentation: Signature 141 | MacroBlockBegin: '' 142 | MacroBlockEnd: '' 143 | MaxEmptyLinesToKeep: 1 144 | NamespaceIndentation: All 145 | ObjCBinPackProtocolList: Auto 146 | ObjCBlockIndentWidth: 2 147 | ObjCBreakBeforeNestedBlockParam: true 148 | ObjCSpaceAfterProperty: false 149 | ObjCSpaceBeforeProtocolList: true 150 | PenaltyBreakAssignment: 10000 151 | PenaltyBreakBeforeFirstCallParameter: 0 152 | PenaltyBreakComment: 300 153 | PenaltyBreakFirstLessLess: 100 154 | PenaltyBreakOpenParenthesis: 0 155 | PenaltyBreakString: 100 156 | PenaltyBreakTemplateDeclaration: 100 157 | PenaltyExcessCharacter: 1000 158 | PenaltyReturnTypeOnItsOwnLine: 10000 159 | PenaltyIndentedWhitespace: 100 160 | PointerAlignment: Left 161 | PPIndentWidth: -1 162 | ReferenceAlignment: Pointer 163 | ReflowComments: true 164 | RemoveBracesLLVM: false 165 | SeparateDefinitionBlocks: Leave 166 | ShortNamespaceLines: 0 167 | SortIncludes: CaseInsensitive 168 | SortJavaStaticImport: Before 169 | SortUsingDeclarations: true 170 | SpaceAfterCStyleCast: false 171 | SpaceAfterLogicalNot: false 172 | SpaceAfterTemplateKeyword: true 173 | SpaceBeforeAssignmentOperators: true 174 | SpaceBeforeCaseColon: false 175 | SpaceBeforeCpp11BracedList: false 176 | SpaceBeforeCtorInitializerColon: false 177 | SpaceBeforeInheritanceColon: false 178 | SpaceBeforeParens: ControlStatements 179 | SpaceBeforeParensOptions: 180 | AfterControlStatements: true 181 | AfterForeachMacros: true 182 | AfterFunctionDefinitionName: false 183 | AfterFunctionDeclarationName: false 184 | AfterIfMacros: true 185 | AfterOverloadedOperator: false 186 | BeforeNonEmptyParentheses: false 187 | SpaceAroundPointerQualifiers: Default 188 | SpaceBeforeRangeBasedForLoopColon: true 189 | SpaceInEmptyBlock: false 190 | SpaceInEmptyParentheses: false 191 | SpacesBeforeTrailingComments: 1 192 | SpacesInAngles: Never 193 | SpacesInConditionalStatement: false 194 | SpacesInContainerLiterals: true 195 | SpacesInCStyleCastParentheses: false 196 | SpacesInContainerLiterals: false 197 | SpacesInLineCommentPrefix: 198 | Minimum: 1 199 | Maximum: -1 200 | SpacesInParentheses: false 201 | SpacesInSquareBrackets: false 202 | SpaceBeforeSquareBrackets: false 203 | BitFieldColonSpacing: Both 204 | Standard: Latest 205 | StatementAttributeLikeMacros: 206 | - Q_EMIT 207 | StatementMacros: 208 | - Q_UNUSED 209 | - QT_REQUIRE_VERSION 210 | TabWidth: 4 211 | UseCRLF: false 212 | UseTab: Never 213 | WhitespaceSensitiveMacros: 214 | - STRINGIZE 215 | - PP_STRINGIZE 216 | - BOOST_PP_STRINGIZE 217 | - NS_SWIFT_NAME 218 | - CF_SWIFT_NAME 219 | ... 220 | -------------------------------------------------------------------------------- /Source/WavePropagationSolver.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Solvers { 4 | 5 | /** 6 | * Abstract wave propagation solver for the Shallow Water Equations. 7 | * 8 | * T should be double or float. 9 | */ 10 | template 11 | class WavePropagationSolver { 12 | // protected: 13 | public: 14 | T dryTol_; //! Numerical definition of "dry". 15 | const T gravity_; //! Gravity constant. 16 | const T zeroTol_; //! Numerical definition of zero. 17 | 18 | #if 0 19 | //! Parameters for computeNetUpdates. 20 | T h_[2]; 21 | T hu_[2]; 22 | T b_[2]; 23 | T u_[2]; 24 | 25 | #define hLeft_ (h_[0]) 26 | #define hRight_ (h_[1]) 27 | 28 | #define huLeft_ (hu_[0]) 29 | #define huRight_ (hu_[1]) 30 | 31 | #define bLeft_ (b_[0]) 32 | #define bRight_ (b_[1]) 33 | 34 | #define uLeft_ (u_[0]) 35 | #define uRight_ (u_[1]) 36 | #else 37 | //! Edge-local variables. 38 | T hLeft_; //! Height on the left side of the edge (could change during execution). 39 | T hRight_; //! Height on the right side of the edge (could change during execution). 40 | T huLeft_; //! Momentum on the left side of the edge (could change during execution). 41 | T huRight_; //! Momentum on the right side of the edge (could change during execution). 42 | T bLeft_; //! Bathymetry on the left side of the edge (could change during execution). 43 | T bRight_; //! Bathymetry on the right side of the edge (could change during execution). 44 | T uLeft_; //! Velocity on the left side of the edge (computed by determineWetDryState). 45 | T uRight_; //! Velocity on the right side of the edge (computed by determineWetDryState). 46 | #endif 47 | 48 | /** 49 | * The wet/dry state of the Riemann-problem. 50 | */ 51 | enum WetDryState { 52 | DryDry, /**< Both cells are dry. */ 53 | WetWet, /**< Both cells are wet. */ 54 | WetDryInundation, /**< 1st cell: wet, 2nd cell: dry. 1st cell lies higher than the 2nd one. */ 55 | WetDryWall, /**< 1st cell: wet, 2nd cell: dry. 1st cell lies lower than the 2nd one. Momentum is not large enough 56 | to overcome the difference. */ 57 | WetDryWallInundation, /**< 1st cell: wet, 2nd cell: dry. 1st cell lies lower than the 2nd one. Momentum is large 58 | enough to overcome the difference. */ 59 | DryWetInundation, /**< 1st cell: dry, 2nd cell: wet. 1st cell lies lower than the 2nd one. */ 60 | DryWetWall, /**< 1st cell: dry, 2nd cell: wet. 1st cell lies higher than the 2nd one. Momentum is not large enough 61 | to overcome the difference. */ 62 | DryWetWallInundation /**< 1st cell: dry, 2nd cell: wet. 1st cell lies higher than the 2nd one. Momentum is large 63 | enough to overcome the difference. */ 64 | }; 65 | 66 | WetDryState wetDryState_; //! wet/dry state of our Riemann-problem (determined by determineWetDryState). 67 | 68 | //! Determine the wet/dry-state and set local values if we have to. 69 | virtual void determineWetDryState() = 0; 70 | 71 | /** 72 | * Constructor of a wave propagation solver. 73 | * 74 | * @param gravity gravity constant. 75 | * @param dryTolerance numerical definition of "dry". 76 | * @param zeroTolerance numerical definition of zero. 77 | */ 78 | WavePropagationSolver(T dryTolerance, T gravity, T zeroTolerance): 79 | dryTol_(dryTolerance), 80 | gravity_(gravity), 81 | zeroTol_(zeroTolerance) {} 82 | 83 | /** 84 | * Store parameters to member variables. 85 | * 86 | * @param hLeft height on the left side of the edge. 87 | * @param hRight height on the right side of the edge. 88 | * @param huLeft momentum on the left side of the edge. 89 | * @param huRight momentum on the right side of the edge. 90 | * @param bLeft bathymetry on the left side of the edge. 91 | * @param bRight bathymetry on the right side of the edge. 92 | */ 93 | void storeParameters( 94 | const T& hLeft, const T& hRight, const T& huLeft, const T& huRight, const T& bLeft, const T& bRight 95 | ) { 96 | hLeft_ = hLeft; 97 | hRight_ = hRight; 98 | 99 | huLeft_ = huLeft; 100 | huRight_ = huRight; 101 | 102 | bLeft_ = bLeft; 103 | bRight_ = bRight; 104 | } 105 | 106 | /** 107 | * Store parameters to member variables. 108 | * 109 | * @param hLeft height on the left side of the edge. 110 | * @param hRight height on the right side of the edge. 111 | * @param huLeft momentum on the left side of the edge. 112 | * @param huRight momentum on the right side of the edge. 113 | * @param bLeft bathymetry on the left side of the edge. 114 | * @param bRight bathymetry on the right side of the edge. 115 | * @param uLeft velocity on the left side of the edge. 116 | * @param uRight velocity on the right side of the edge. 117 | */ 118 | void storeParameters( 119 | const T& hLeft, 120 | const T& hRight, 121 | const T& huLeft, 122 | const T& huRight, 123 | const T& bLeft, 124 | const T& bRight, 125 | const T& uLeft, 126 | const T& uRight 127 | ) { 128 | storeParameters(hLeft, hRight, huLeft, huRight, bLeft, bRight); 129 | 130 | uLeft_ = uLeft; 131 | uRight_ = uRight; 132 | } 133 | 134 | public: 135 | virtual ~WavePropagationSolver() = default; 136 | 137 | /** 138 | * Compute net updates for the cell on the left/right side of the edge. 139 | * This is the default method every standalone wave propagation solver should provide. 140 | * 141 | * @param hLeft height on the left side of the edge. 142 | * @param hRight height on the right side of the edge. 143 | * @param huLeft momentum on the left side of the edge. 144 | * @param huRight momentum on the right side of the edge. 145 | * @param bLeft bathymetry on the left side of the edge. 146 | * @param bRight bathymetry on the right side of the edge. 147 | * 148 | * @param o_hUpdateLeft will be set to: Net-update for the height of the cell on the left side of the edge. 149 | * @param o_hUpdateRight will be set to: Net-update for the height of the cell on the right side of the edge. 150 | * @param o_huUpdateLeft will be set to: Net-update for the momentum of the cell on the left side of the edge. 151 | * @param o_huUpdateRight will be set to: Net-update for the momentum of the cell on the right side of the edge. 152 | * @param o_maxWaveSpeed will be set to: Maximum (linearized) wave speed -> Should be used in the CFL-condition. 153 | */ 154 | virtual void computeNetUpdates( 155 | const T& hLeft, 156 | const T& hRight, 157 | const T& huLeft, 158 | const T& huRight, 159 | const T& bLeft, 160 | const T& bRight, 161 | T& o_hUpdateLeft, 162 | T& o_hUpdateRight, 163 | T& o_huUpdateLeft, 164 | T& o_huUpdateRight, 165 | T& o_maxWaveSpeed 166 | #ifdef ENABLE_AUGMENTED_RIEMANN_EIGEN_COEFFICIENTS 167 | , 168 | T o_eigenCoefficients[3] 169 | #endif 170 | ) = 0; 171 | 172 | /** 173 | * Sets the dry tolerance of the solver. 174 | * 175 | * @param dryTolerance dry tolerance. 176 | */ 177 | void setDryTolerance(const T dryTolerance) { dryTol_ = dryTolerance; } 178 | 179 | #undef hLeft 180 | #undef hRight 181 | 182 | #undef huLeft 183 | #undef huRight 184 | 185 | #undef bLeft 186 | #undef bRight 187 | 188 | #undef uLeft 189 | #undef uRight 190 | }; 191 | 192 | } // namespace Solvers 193 | -------------------------------------------------------------------------------- /Source/SIMDDefinitions.hpp: -------------------------------------------------------------------------------- 1 | /***********************************************************************************/ /** 2 | * 3 | * \file SIMD_DEFINITIONS.hpp 4 | * 5 | * \brief Contains macro 6 | *definitions for the intrinsics 7 | *used for the vectorization 8 | * 9 | * \author Wolfgang Hölzl 10 | *(hoelzlw), hoelzlw AT in.tum.de 11 | * 12 | **************************************************************************************/ 13 | 14 | #pragma once 15 | 16 | #ifndef SIMD_DEFINITIONS_H 17 | #define SIMD_DEFINITIONS_H 18 | 19 | #include 20 | #include 21 | 22 | /* 23 | * Check whether the file SIMD_TYPES.hpp has been included. 24 | * This file (SIMD_DEFINITIONS.hpp) needs some macros to be set properly by that file (SIMD_TYPES.hpp). 25 | */ 26 | #ifndef SIMD_TYPES_H 27 | #error "SIMD_DEFINITIONS included without SIMD_TYPES! Never include this file directly! Include it only via SIMD_TYPES!" 28 | #endif /* defined SIMD_TYPES_H */ 29 | 30 | #if defined VECTOR_SSE4_FLOAT32 31 | /* 32 | * Map single precision SSE intrinsics 33 | */ 34 | #define ADDV _mm_add_ps 35 | #define SUBV _mm_sub_ps 36 | #define MULV _mm_mul_ps 37 | #define DIVV _mm_div_ps 38 | #define SQRTV _mm_sqrt_ps 39 | 40 | #define LOADU _mm_loadu_ps 41 | #define STOREU _mm_storeu_ps 42 | #define SETV_R _mm_set1_ps 43 | #define SETV_I _mm_set1_epi32 44 | #define ZEROV_R _mm_setzero_ps 45 | #define ZEROV_I _mm_setzero_si128 46 | 47 | #define MAXV _mm_max_ps 48 | #define MINV _mm_min_ps 49 | 50 | #define CMP_LT _mm_cmplt_ps 51 | #define CMP_LE _mm_cmple_ps 52 | #define CMP_GT _mm_cmpgt_ps 53 | #define CMP_GE _mm_cmpge_ps 54 | 55 | #define CMP_EQ_I _mm_cmpeq_epi32 56 | #define CMP_EQ_R _mm_cmpeq_ps 57 | 58 | #define ANDV_R _mm_and_ps 59 | #define ORV_R _mm_or_ps 60 | #define XORV_R _mm_xor_ps 61 | #define ORV_I _mm_or_si128 62 | #define NOTV_R not_ps 63 | #define NOTV_I not_si128 64 | #define ANDNOTV_R _mm_andnot_ps 65 | 66 | #define BLENDV _mm_blendv_ps 67 | #define BLENDV_I(else_part, if_part, mask) \ 68 | CAST_REAL_TO_INT_V(_mm_blendv_ps(CAST_INT_TO_REAL_V(else_part), CAST_INT_TO_REAL_V(if_part), mask)) 69 | #define MOVEMASK _mm_movemask_ps 70 | #define SHIFT_LEFT _mm_slli_epi32 71 | 72 | #define CAST_INT_TO_REAL_V _mm_castsi128_ps 73 | #define CAST_REAL_TO_INT_V _mm_castps_si128 74 | #define FABS fabs_ps 75 | 76 | /* 77 | * Compute the absolute value of a vector by forcing the sign bit to be zero 78 | */ 79 | inline __m128 fabs_ps(const __m128 x) { 80 | static const __m128 sign_mask = CAST_INT_TO_REAL_V(_mm_set1_epi32(1 << 31)); 81 | return _mm_andnot_ps(sign_mask, x); 82 | } 83 | 84 | /* 85 | * Bitwise NOT operation for integers 86 | */ 87 | inline __m128i not_si128(const __m128i x) { 88 | static const __m128i mask = _mm_set1_epi32(~0); 89 | return CAST_REAL_TO_INT_V(_mm_xor_ps(CAST_INT_TO_REAL_V(mask), CAST_INT_TO_REAL_V(x))); 90 | } 91 | 92 | /* 93 | * Bitwise NOT operation for reals 94 | */ 95 | inline __m128 not_ps(const __m128 x) { 96 | static const __m128i mask = _mm_set1_epi32(~0); 97 | return _mm_xor_ps(CAST_INT_TO_REAL_V(mask), x); 98 | } 99 | 100 | /* 101 | * Check, whether a real_vector contains infinity or NaN 102 | */ 103 | inline bool checkVector(const __m128 x) { 104 | static const real_vector infinity = SETV_R(std ::numeric_limits::infinity()); 105 | return MOVEMASK(ANDV_R(CMP_EQ_R(x, x), NOTV_R(CMP_EQ_R(x, infinity)))) == VECTOR_FULL_MASK; 106 | } 107 | #elif defined VECTOR_SSE4_FLOAT64 108 | /* 109 | * Map double precision SSE intrinsics 110 | */ 111 | #error "SSE4 with double precision not implemented at the moment" 112 | #elif defined VECTOR_AVX_FLOAT32 113 | /* 114 | * Map single precision AVX intrinsics 115 | */ 116 | #define ADDV _mm256_add_ps 117 | #define SUBV _mm256_sub_ps 118 | #define MULV _mm256_mul_ps 119 | #define DIVV _mm256_div_ps 120 | #define SQRTV _mm256_sqrt_ps 121 | 122 | #define LOADU _mm256_loadu_ps 123 | #define STOREU _mm256_storeu_ps 124 | #define SETV_R _mm256_set1_ps 125 | #define SETV_I _mm256_set1_epi32 126 | #define ZEROV_R _mm256_setzero_ps 127 | #define ZEROV_I _mm256_setzero_si256 128 | 129 | #define MAXV _mm256_max_ps 130 | #define MINV _mm256_min_ps 131 | 132 | #define CMP_LT(x, y) _mm256_cmp_ps((x), (y), _CMP_LT_OS) 133 | #define CMP_LE(x, y) _mm256_cmp_ps((x), (y), _CMP_LE_OS) 134 | #define CMP_GT(x, y) _mm256_cmp_ps((x), (y), _CMP_GT_OS) 135 | #define CMP_GE(x, y) _mm256_cmp_ps((x), (y), _CMP_GE_OS) 136 | 137 | #define CMP_EQ_R(x, y) _mm256_cmp_ps((x), (y), _CMP_EQ_OS) 138 | 139 | /* 140 | * Define test for equality of integers 141 | * Replace with 142 | * 143 | * #define CMP_EQ_I(x, y) _mm256_cmpeq_epi32((x), (y)) 144 | * 145 | * when running with AVX2 146 | */ 147 | static inline __m256i CMP_EQ_I(const __m256i a, const __m256i b) { 148 | __m256i out = ZEROV_I(); 149 | const integer* const p = reinterpret_cast(&a); 150 | const integer* const q = reinterpret_cast(&b); 151 | integer* const r = reinterpret_cast(&out); 152 | 153 | for (int i = 0; i < VECTOR_LENGTH; ++i) { 154 | r[i] = p[i] == q[i] ? 0xFFFFFFFF : 0; 155 | } 156 | 157 | return out; 158 | } 159 | 160 | #define ANDV_R _mm256_and_ps 161 | #define ORV_R _mm256_or_ps 162 | #define XORV_R _mm256_xor_ps 163 | #define ORV_I(x, y) CAST_REAL_TO_INT_V(_mm256_or_ps(CAST_INT_TO_REAL_V(x), CAST_INT_TO_REAL_V(y))) 164 | 165 | #define NOTV_R not_ps 166 | #define NOTV_I not_si256 167 | #define ANDNOTV_R _mm256_andnot_ps 168 | 169 | #define BLENDV _mm256_blendv_ps 170 | #define BLENDV_I(else_part, if_part, mask) \ 171 | CAST_REAL_TO_INT_V(_mm256_blendv_ps(CAST_INT_TO_REAL_V(else_part), CAST_INT_TO_REAL_V(if_part), mask)) 172 | #define MOVEMASK _mm256_movemask_ps 173 | 174 | /* 175 | * Define left shifting for integers 176 | * Replace with 177 | * 178 | * #define SHIFT_LEFT(x, y) _mm256_slli_epi32((x), (y)) 179 | * 180 | * when running with AVX2 181 | */ 182 | static inline __m256i SHIFT_LEFT(const __m256i x, const integer y) { 183 | __m256i out = ZEROV_I(); 184 | const integer* const p = reinterpret_cast(&x); 185 | integer* const q = reinterpret_cast(&out); 186 | 187 | for (int i = 0; i < VECTOR_LENGTH; ++i) { 188 | q[i] = p[i] << y; 189 | } 190 | 191 | return out; 192 | } 193 | 194 | #define CAST_INT_TO_REAL_V _mm256_castsi256_ps 195 | #define CAST_REAL_TO_INT_V _mm256_castps_si256 196 | #define FABS fabs_ps 197 | 198 | /* 199 | * Compute the absolute value of a vector by forcing the sign bit to be zero 200 | */ 201 | inline __m256 fabs_ps(const __m256 x) { 202 | static const __m256 sign_mask = CAST_INT_TO_REAL_V(_mm256_set1_epi32(1 << 31)); 203 | return _mm256_andnot_ps(sign_mask, x); 204 | } 205 | 206 | /* 207 | * Bitwise NOT operation for integers 208 | */ 209 | inline __m256i not_si256(const __m256i x) { 210 | static const __m256i mask = _mm256_set1_epi32(0xFFFFFFFF); 211 | return CAST_REAL_TO_INT_V(_mm256_xor_ps(CAST_INT_TO_REAL_V(mask), CAST_INT_TO_REAL_V(x))); 212 | } 213 | 214 | /* 215 | * Bitwise NOT operation for reals 216 | */ 217 | inline __m256 not_ps(const __m256 x) { 218 | static const __m256i mask = _mm256_set1_epi32(0xFFFFFFFF); 219 | return _mm256_xor_ps(CAST_INT_TO_REAL_V(mask), x); 220 | } 221 | 222 | /* 223 | * Check, whether a real_vector contains infinity or NaN 224 | */ 225 | inline bool checkVector(const __m256 x) { 226 | static const real_vector infinity = SETV_R(std ::numeric_limits::infinity()); 227 | return MOVEMASK(ANDV_R(CMP_EQ_R(x, x), NOTV_R(CMP_EQ_R(x, infinity)))) == VECTOR_FULL_MASK; 228 | } 229 | #elif defined VECTOR_AVX_FLOAT64 230 | /* 231 | * Map double precision AVX intrinsics 232 | */ 233 | #error "AVX with double precision not implemented at the moment" 234 | #else /* no vectorization type defined */ 235 | /* 236 | * No vectorization demanded. 237 | * Do nothing, but inform the user 238 | */ 239 | #pragma message "SIMD-Definitions included, but no Vector-Type defined." 240 | #endif 241 | 242 | #endif /* #ifndef SIMD_DEFINITIONS_H */ 243 | -------------------------------------------------------------------------------- /Source/FWaveVecSolver.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * FWaveVecSolver.hpp 3 | * 4 | **** 5 | **** This is a vectorizable C++ implementation of the F-Wave solver (FWaveSolver.hpp). 6 | **** 7 | * 8 | * Created on: Nov 13, 2012 9 | * Last Update: Dec 28, 2013 10 | * 11 | **** 12 | * 13 | * Author: Sebastian Rettenberger 14 | * Homepage: http://www5.in.tum.de/wiki/index.php/Sebastian_Rettenberger,_M.Sc. 15 | * E-Mail: rettenbs AT in.tum.de 16 | * Some optimzations: Michael Bader 17 | * Homepage: http://www5.in.tum.de/wiki/index.php/Michael_Bader 18 | * E-Mail: bader AT in.tum.de 19 | * 20 | **** 21 | * 22 | * (Main) Literature: 23 | * 24 | * @article{bale2002wave, 25 | * title={A wave propagation method for conservation laws and balance laws with spatially varying flux 26 | *functions}, author={Bale, D.S. and LeVeque, R.J. and Mitran, S. and Rossmanith, J.A.}, journal={SIAM Journal on 27 | *Scientific Computing}, volume={24}, number={3}, pages={955--978}, year={2002}} 28 | * 29 | * @book{leveque2002finite, 30 | * Author = {LeVeque, R. J.}, 31 | * Publisher = {Cambridge University Press}, 32 | * Title = {Finite Volume Methods for Hyperbolic Problems}, 33 | * Volume = {31}, 34 | * Year = {2002}} 35 | * 36 | * @webpage{levequeclawpack, 37 | * Author = {LeVeque, R. J.}, 38 | * Lastchecked = {January, 05, 2011}, 39 | * Title = {Clawpack Sofware}, 40 | * Url = {https://github.com/clawpack/clawpack-4.x/blob/master/geoclaw/2d/lib}} 41 | * 42 | **** 43 | */ 44 | 45 | #pragma once 46 | 47 | #include 48 | 49 | namespace Solvers { 50 | 51 | template 52 | class FWaveVecSolver { 53 | private: 54 | const T dryTol_; 55 | const T zeroTol_; 56 | const T halfGravity_; 57 | const T sqrtGravity_; 58 | 59 | public: 60 | /** 61 | * FWaveVec Constructor, takes three problem parameters 62 | * @param dryTol "dry tolerance": if the water height falls below dryTol, wall boundary conditions are applied 63 | * (default value is 100) 64 | * @param gravity takes the value of the gravity constant (default value is 9.81 m/s^2) 65 | * @param zeroTol computed f-waves with an absolute value < zeroTol are treated as static waves (default value is 66 | * 10^{-7}) 67 | */ 68 | FWaveVecSolver(T dryTol = T(1.0), T gravity = T(9.81), T zeroTol = T(0.0000001)): 69 | dryTol_(dryTol), 70 | zeroTol_(zeroTol), 71 | halfGravity_(T(0.5) * gravity), 72 | sqrtGravity_(std::sqrt(gravity)) {} 73 | 74 | /** 75 | * Takes the water height, discharge and bathymatry in the left and right cell 76 | * and computes net updates (left and right going waves) according to the f-wave approach. 77 | * It also returns the maximum wave speed. 78 | */ 79 | #ifdef ENABLE_VECTORIZATION 80 | #pragma omp declare simd 81 | #endif 82 | void computeNetUpdates( 83 | T hLeft, 84 | T hRight, 85 | T huLeft, 86 | T huRight, 87 | T bLeft, 88 | T bRight, 89 | T& o_hUpdateLeft, 90 | T& o_hUpdateRight, 91 | T& o_huUpdateLeft, 92 | T& o_huUpdateRight, 93 | T& o_maxWaveSpeed 94 | ) const { 95 | if (hLeft >= dryTol_) { 96 | if (hRight < dryTol_) { 97 | // Dry/Wet case 98 | // Set values according to wall boundary condition 99 | hRight = hLeft; 100 | huRight = -huLeft; 101 | bRight = bLeft; 102 | } 103 | } else if (hRight >= dryTol_) { 104 | // Wet/Dry case 105 | // Set values according to wall boundary condition 106 | hLeft = hRight; 107 | huLeft = -huRight; 108 | bLeft = bRight; 109 | } else { 110 | // Dry/Dry case 111 | // Set dummy values such that the result is zero 112 | hLeft = dryTol_; 113 | huLeft = T(0.0); 114 | bLeft = T(0.0); 115 | hRight = dryTol_; 116 | huRight = T(0.0); 117 | bRight = T(0.0); 118 | } 119 | 120 | // Velocity on the left side of the edge 121 | T uLeft = huLeft / hLeft; // 1 FLOP (div) 122 | // Velocity on the right side of the edge 123 | T uRight = huRight / hRight; // 1 FLOP (div) 124 | 125 | /// Wave speeds of the f-waves 126 | T waveSpeeds0 = T(0.0); 127 | T waveSpeeds1 = T(0.0); 128 | 129 | fWaveComputeWaveSpeeds( 130 | hLeft, hRight, huLeft, huRight, uLeft, uRight, bLeft, bRight, waveSpeeds0, waveSpeeds1 131 | ); // 20 FLOPs (incl. 3 sqrt, 1 div, 2 min/max) 132 | 133 | // Variables to store the two f-waves 134 | T fWaves0 = T(0.0); 135 | T fWaves1 = T(0.0); 136 | 137 | // Compute the decomposition into f-waves 138 | fWaveComputeWaveDecomposition( 139 | hLeft, hRight, huLeft, huRight, uLeft, uRight, bLeft, bRight, waveSpeeds0, waveSpeeds1, fWaves0, fWaves1 140 | ); // 23 FLOPs (incl. 1 div) 141 | 142 | // Compute the net-updates 143 | o_hUpdateLeft = T(0.0); 144 | o_hUpdateRight = T(0.0); 145 | o_huUpdateLeft = T(0.0); 146 | o_huUpdateRight = T(0.0); 147 | 148 | // 1st wave family 149 | if (waveSpeeds0 < -zeroTol_) { // Left going 150 | o_hUpdateLeft += fWaves0; 151 | o_huUpdateLeft += fWaves0 * waveSpeeds0; // 3 FLOPs (assume left going wave ...) 152 | } else if (waveSpeeds0 > zeroTol_) { // Right going 153 | o_hUpdateRight += fWaves0; 154 | o_huUpdateRight += fWaves0 * waveSpeeds0; 155 | } else { // Split waves, if waveSpeeds0 close to 0 156 | o_hUpdateLeft += T(0.5) * fWaves0; 157 | o_huUpdateLeft += T(0.5) * fWaves0 * waveSpeeds0; 158 | o_hUpdateRight += T(0.5) * fWaves0; 159 | o_huUpdateRight += T(0.5) * fWaves0 * waveSpeeds0; 160 | } 161 | 162 | // 2nd wave family 163 | if (waveSpeeds1 > zeroTol_) { // Right going 164 | o_hUpdateRight += fWaves1; 165 | o_huUpdateRight += fWaves1 * waveSpeeds1; // 3 FLOPs (assume right going wave ...) 166 | } else if (waveSpeeds1 < -zeroTol_) { // Left going 167 | o_hUpdateLeft += fWaves1; 168 | o_huUpdateLeft += fWaves1 * waveSpeeds1; 169 | } else { // Split waves 170 | o_hUpdateLeft += T(0.5) * fWaves1; 171 | o_huUpdateLeft += T(0.5) * fWaves1 * waveSpeeds1; 172 | o_hUpdateRight += T(0.5) * fWaves1; 173 | o_huUpdateRight += T(0.5) * fWaves1 * waveSpeeds1; 174 | } 175 | 176 | // Compute maximum wave speed (-> CFL-condition) 177 | o_maxWaveSpeed = std::max(std::abs(waveSpeeds0), std::abs(waveSpeeds1)); // 3 FLOPs (2 abs, 1 max) 178 | 179 | // ======================== 180 | // 54 FLOPs (3 sqrt, 4 div, 2 abs, 3 min/max) 181 | } 182 | 183 | #ifdef ENABLE_VECTORIZATION 184 | #pragma omp declare simd 185 | #endif 186 | void fWaveComputeWaveSpeeds( 187 | const T hLeft, 188 | const T hRight, 189 | const T huLeft, 190 | const T huRight, 191 | const T uLeft, 192 | const T uRight, 193 | const T bLeft, 194 | const T bRight, 195 | T& o_waveSpeed0, 196 | T& o_waveSpeed1 197 | ) const { 198 | // Helper variables for sqrt of h: 199 | T sqrtHLeft = std::sqrt(hLeft); // 1 FLOP (sqrt) 200 | T sqrtHRight = std::sqrt(hRight); // 1 FLOP (sqrt) 201 | 202 | // Compute eigenvalues of the jacobian matrices in states Q_{i-1} and Q_{i} 203 | T characteristicSpeed0 = uLeft - sqrtGravity_ * sqrtHLeft; // 2 FLOPs 204 | T characteristicSpeed1 = uRight + sqrtGravity_ * sqrtHRight; // 2 FLOPs 205 | 206 | // Compute "Roe averages" 207 | T hRoe = T(0.5) * (hRight + hLeft); // 2 FLOPs 208 | T sqrtHRoe = std::sqrt(hRoe); // 1 FLOP (sqrt) 209 | T uRoe = uLeft * sqrtHRoe + uRight * sqrtHRight; // 3 FLOPs 210 | uRoe /= sqrtHLeft + sqrtHRight; // 2 FLOPs (1 div) 211 | 212 | // Compute "Roe speeds" from Roe averages 213 | T roeSpeed0 = uRoe - sqrtGravity_ * sqrtHRoe; // 2 FLOPs 214 | T roeSpeed1 = uRoe + sqrtGravity_ * sqrtHRoe; // 2 FLOPs 215 | 216 | // Compute Eindfeldt speeds (returned as output parameters) 217 | o_waveSpeed0 = std::min(characteristicSpeed0, roeSpeed0); // 1 FLOP (min) 218 | o_waveSpeed1 = std::max(characteristicSpeed1, roeSpeed1); // 1 FLOP (max) 219 | 220 | // ============== 221 | // 20 FLOPs (incl. 3 sqrt, 1 div, 2 min/max) 222 | } 223 | 224 | #ifdef ENABLE_VECTORIZATION 225 | #pragma omp declare simd 226 | #endif 227 | void fWaveComputeWaveDecomposition( 228 | const T hLeft, 229 | const T hRight, 230 | const T huLeft, 231 | const T huRight, 232 | const T uLeft, 233 | const T uRight, 234 | const T bLeft, 235 | const T bRight, 236 | const T waveSpeed0, 237 | const T waveSpeed1, 238 | T& o_fWave0, 239 | T& o_fWave1 240 | ) const { 241 | // Calculate modified (bathymetry) flux difference 242 | // f(Q_i) - f(Q_{i-1}) -> serve as right hand sides 243 | T fDif0 = huRight - huLeft; // 1 FLOP 244 | T fDif1 = huRight * uRight + halfGravity_ * hRight * hRight 245 | - (huLeft * uLeft + halfGravity_ * hLeft * hLeft); // 9 FLOPs 246 | 247 | // \delta x \Psi[2] 248 | fDif1 += halfGravity_ * (hRight + hLeft) * (bRight - bLeft); // 5 FLOPs 249 | 250 | // Solve linear system of equations to obtain f-waves: 251 | // ( 1 1 ) ( o_fWave0 ) = ( fDif0 ) 252 | // ( waveSpeed0 waveSpeed1 ) ( o_fWave1 ) ( fDif1 ) 253 | 254 | // Compute the inverse of the wave speed difference: 255 | T inverseSpeedDiff = T(1.0) / (waveSpeed1 - waveSpeed0); // 2 FLOPs (1 div) 256 | // Compute f-waves: 257 | o_fWave0 = (waveSpeed1 * fDif0 - fDif1) * inverseSpeedDiff; // 3 FLOPs 258 | o_fWave1 = (-waveSpeed0 * fDif0 + fDif1) * inverseSpeedDiff; // 3 FLOPs 259 | 260 | // ========= 261 | // 23 FLOPs in total (incl. 1 div) 262 | } 263 | }; 264 | 265 | } // namespace Solvers 266 | -------------------------------------------------------------------------------- /Source/HybridWaveSolver.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Hybrid.hpp 3 | * 4 | **** 5 | **** Hybrid Riemann Solver for the Shallow Water Equation 6 | **** 7 | * 8 | * Created on: Jan 04, 2012 9 | * Last Update: Feb 20, 2012 10 | * 11 | **** 12 | * 13 | * Author: Alexander Breuer 14 | * Homepage: http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer 15 | * E-Mail: breuera AT in.tum.de 16 | * 17 | **** 18 | * 19 | * (Main) Literature: 20 | * 21 | * @webpage{levequeclawpack, 22 | * Author = {LeVeque, R. J.}, 23 | * Lastchecked = {January, 05, 2011}, 24 | * Title = {Clawpack Sofware}, 25 | * Url = {https://github.com/dlgeorge/clawpack-4.x/blob/master/geoclaw/2d/lib/rpn2ez_fast_geo.f}} 26 | * 27 | * TODO: Where to find literature about hybrid-solvers? 28 | * 29 | **** 30 | * 31 | * Acknowledgments: 32 | * Special thanks go to R.J. LeVeque and D.L. George for publishing their code 33 | * and the corresponding documentation (-> Literature). 34 | */ 35 | 36 | #ifndef HYBRID_HPP_ 37 | #define HYBRID_HPP_ 38 | 39 | #include "AugRie.hpp" 40 | #include "FWave.hpp" 41 | 42 | #ifndef NDEBUG 43 | #include 44 | #endif 45 | 46 | namespace solver { 47 | template 48 | class Hybrid; 49 | } // namespace solver 50 | 51 | /** 52 | * Hybrid Wave Propagation Solver. 53 | * Combines the "simple" f-Wave approach with the more complex Augmented Riemann Solver. 54 | * 55 | * T should be double or float. 56 | */ 57 | template 58 | class solver::Hybrid { 59 | private: 60 | //! gravity constant. 61 | const T g; 62 | //! numerical definition of "dry". 63 | const T dryTol; 64 | //! f-Wave solver for "simple" problems. 65 | solver::FWave fWaveSolver; 66 | //! Augmented Riemann-solver for more complex problems. 67 | solver::AugRie augRieSolver; 68 | 69 | #ifndef NDEBUG 70 | //! how often was the f-Wave solver used. 71 | long counterFWave; 72 | 73 | //! how often was the AugRie solver used. 74 | long counterAugRie; 75 | #endif 76 | 77 | public: 78 | /** 79 | * Constructor of the hybrid solver with optional parameters. 80 | * 81 | * @param i_dryTolerance numerical definition of "dry". 82 | * @param i_gravity gravity constant. 83 | * @param i_newtonTolerance numerical definition of "convergence" (used in the AugRie solver only). 84 | * @param i_maxNumberOfNewtonIterations maximum steps for the Newton-Raphson method (used in the AugRie solver only). 85 | * @param i_zeroTolerance numerical definition of zero. 86 | */ 87 | Hybrid( 88 | T i_dryTolerance = (T)0.01, 89 | T i_gravity = (T)9.81, 90 | T i_newtonTolerance = (T)0.000001, 91 | int i_maxNumberOfNewtonIterations = 10, 92 | T zeroTolerance = (T)0.000000001 93 | ): 94 | g(i_gravity), 95 | dryTol(i_dryTolerance), 96 | fWaveSolver(i_dryTolerance, i_gravity, zeroTolerance), 97 | augRieSolver(i_dryTolerance, i_gravity, i_newtonTolerance, i_maxNumberOfNewtonIterations, zeroTolerance) { 98 | #ifndef NDEBUG 99 | // set the counters to zero. 100 | counterFWave = counterAugRie = 0; 101 | 102 | #ifndef SUPPRESS_SOLVER_DEBUG_OUTPUT 103 | // print some information about the used solver. 104 | std::cout 105 | << " *** solver::Hybrid created" << std::endl 106 | << " zeroTolerance=" << zeroTolerance << std::endl 107 | << " gravity=" << i_gravity << std::endl 108 | << " dryTolerance=" << i_dryTolerance << std::endl 109 | << " newtonTolerance=" << i_newtonTolerance << std::endl 110 | << " maxNumberNumberOfNewtonIterations=" << i_maxNumberOfNewtonIterations << std::endl 111 | << " ***\n\n"; 112 | #endif 113 | #endif 114 | }; 115 | 116 | /** 117 | * Compute net updates for the cell on the left/right side of the edge. 118 | * The "correct" solver is used automatically. 119 | * 120 | * @param i_hLeft height on the left side of the edge. 121 | * @param i_hRight height on the right side of the edge. 122 | * @param i_huLeft momentum on the left side of the edge. 123 | * @param i_huRight momentum on the right side of the edge. 124 | * @param i_bLeft bathymetry on the left side of the edge. 125 | * @param i_bRight bathymetry on the right side of the edge. 126 | * 127 | * @param o_hUpdateLeft will be set to: Net-update for the height of the cell on the left side of the edge. 128 | * @param o_hUpdateRight will be set to: Net-update for the height of the cell on the right side of the edge. 129 | * @param o_huUpdateLeft will be set to: Net-update for the momentum of the cell on the left side of the edge. 130 | * @param o_huUpdateRight will be set to: Net-update for the momentum of the cell on the right side of the edge. 131 | * @param o_maxWaveSpeed will be set to: Maximum (linearized) wave speed -> Should be used in the CFL-condition. 132 | */ 133 | void computeNetUpdates( 134 | const T& i_hLeft, 135 | const T& i_hRight, 136 | const T& i_huLeft, 137 | const T& i_huRight, 138 | const T& i_bLeft, 139 | const T& i_bRight, 140 | 141 | T& o_hUpdateLeft, 142 | T& o_hUpdateRight, 143 | T& o_huUpdateLeft, 144 | T& o_huUpdateRight, 145 | T& o_maxWaveSpeed 146 | ) { 147 | if (useAugmentedRiemannSolver(i_hLeft, i_hRight, i_huLeft, i_huRight, i_bLeft, i_bRight, o_hUpdateLeft, o_hUpdateRight, o_huUpdateLeft, o_huUpdateRight, o_maxWaveSpeed) == true) { 148 | 149 | augRieSolver.computeNetUpdates( 150 | i_hLeft, 151 | i_hRight, 152 | i_huLeft, 153 | i_huRight, 154 | i_bLeft, 155 | i_bRight, 156 | 157 | o_hUpdateLeft, 158 | o_hUpdateRight, 159 | o_huUpdateLeft, 160 | o_huUpdateRight, 161 | o_maxWaveSpeed 162 | ); 163 | 164 | #ifndef NDEBUG 165 | counterAugRie++; 166 | #endif 167 | 168 | } 169 | #ifndef NDEBUG 170 | else { 171 | counterFWave++; 172 | } 173 | #endif 174 | } 175 | 176 | /** 177 | * Should the Augmented Riemann Solver be used? 178 | * Side effect: If its sufficient to use the f-Wave solver the net-updates 179 | * will be computed already (hybrid f-Wave version). 180 | * 181 | * @param i_hLeft height on the left side of the edge. 182 | * @param i_hRight height on the right side of the edge. 183 | * @param i_huLeft momentum on the left side of the edge. 184 | * @param i_huRight momentum on the right side of the edge. 185 | * @param i_bLeft bathymetry on the left side of the edge. 186 | * @param i_bRight bathymetry on the right side of the edge. 187 | * 188 | * @param o_hUpdateLeft will be set to: Net-update for the height of the cell on the left side of the edge. 189 | * @param o_hUpdateRight will be set to: Net-update for the height of the cell on the right side of the edge. 190 | * @param o_huUpdateLeft will be set to: Net-update for the momentum of the cell on the left side of the edge. 191 | * @param o_huUpdateRight will be set to: Net-update for the momentum of the cell on the right side of the edge. 192 | * @param o_maxWaveSpeed will be set to: Maximum (linearized) wave speed -> Should be used in the CFL-condition. 193 | * 194 | * @return A boolean whether the Augmented Riemann Solver should be used or not. 195 | */ 196 | bool useAugmentedRiemannSolver( 197 | const T& i_hLeft, 198 | const T& i_hRight, 199 | const T& i_huLeft, 200 | const T& i_huRight, 201 | const T& i_bLeft, 202 | const T& i_bRight, 203 | 204 | T& o_hUpdateLeft, 205 | T& o_hUpdateRight, 206 | T& o_huUpdateLeft, 207 | T& o_huUpdateRight, 208 | T& o_maxWaveSpeed 209 | ) { 210 | // use the augmented solver by default 211 | bool useAugRieSolver = true; 212 | 213 | if (i_hLeft > dryTol && i_hRight > dryTol) { // both cells wet? 214 | 215 | // compute the velocities 216 | T uLeft = i_huLeft / i_hLeft; 217 | T uRight = i_huRight / i_hRight; 218 | 219 | // definition of a "simple" Riemann-problem (GeoClaw) 220 | // TODO: Literature? 221 | if( std::fabs(i_hLeft - i_hRight) < (T)0.001*std::min(i_hLeft, i_hRight) && //"small" jump in height 222 | std::max(uLeft*uLeft, uRight*uRight)/std::max(g*i_hLeft, g*i_hRight) < (T)0.01 ) { //"small" jump in velocity 223 | useAugRieSolver = false; 224 | 225 | // compute simplified wave speeds (Geoclaw) 226 | // TODO: Literature? 227 | T waveSpeeds[2]; 228 | waveSpeeds[0] = (uLeft + uRight) * (T).5 - std::sqrt(g * (i_hLeft + i_hRight) * (T).5); 229 | waveSpeeds[1] = (uLeft + uRight) * (T).5 + std::sqrt(g * (i_hLeft + i_hRight) * (T).5); 230 | 231 | // compute the f-waves 232 | fWaveSolver.computeNetUpdatesHybrid( 233 | i_hLeft, 234 | i_hRight, 235 | i_huLeft, 236 | i_huRight, 237 | i_bLeft, 238 | i_bRight, 239 | uLeft, 240 | uRight, 241 | waveSpeeds, 242 | 243 | o_hUpdateLeft, 244 | o_hUpdateRight, 245 | o_huUpdateLeft, 246 | o_huUpdateRight, 247 | o_maxWaveSpeed 248 | ); 249 | } 250 | } 251 | // DryDry case: Don't use any solver and set everything to zero 252 | else if (i_hLeft < dryTol && i_hRight < dryTol) { 253 | o_hUpdateLeft = o_hUpdateRight = o_huUpdateLeft = o_huUpdateRight = o_maxWaveSpeed = 0; 254 | useAugRieSolver = false; 255 | } 256 | 257 | return useAugRieSolver; 258 | } 259 | 260 | #ifndef NDEBUG 261 | /** 262 | * Prints the current statistics of the hybrid solver. 263 | */ 264 | void printStats() { 265 | std::cout 266 | << " *** solver::Hybrid printing statistics" << std::endl 267 | << " times the f-Wave solver was used: " << counterFWave << std::endl 268 | << " times the AugRie solver was used: " << counterAugRie << std::endl 269 | << " ***\n\n"; 270 | } 271 | 272 | /** 273 | * Get the current statistics of the hybrid solver. 274 | * 275 | * @param o_counterFWave will be set to: times the f-Wave solver was used. 276 | * @param o_counterAugRie will be set to: times the Augmented Riemann solver was used. 277 | */ 278 | void getStats(long& o_counterFWave, long& o_counterAugRie) { 279 | o_counterFWave = counterFWave; 280 | o_counterAugRie = counterAugRie; 281 | } 282 | #endif 283 | }; 284 | 285 | #endif /* HYBRID_HPP_ */ 286 | -------------------------------------------------------------------------------- /Source/FWaveCUDASolver.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * FWaveCuda.h 3 | * 4 | **** 5 | **** This is a pure C implementation of the standard C++ f-Wave solver (FWave.hpp). 6 | **** 7 | * 8 | * Created on: Jan 12, 2012 9 | * Last Update: Jan 12, 2012 10 | * 11 | **** 12 | * 13 | * Author: Alexander Breuer 14 | * Homepage: http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer 15 | * E-Mail: breuera AT in.tum.de 16 | * 17 | **** 18 | * 19 | * (Main) Literature: 20 | * 21 | * @article{bale2002wave, 22 | * title={A wave propagation method for conservation laws and balance laws with spatially varying flux 23 | *functions}, author={Bale, D.S. and LeVeque, R.J. and Mitran, S. and Rossmanith, J.A.}, journal={SIAM Journal on 24 | *Scientific Computing}, volume={24}, number={3}, pages={955--978}, year={2002}, publisher={Citeseer}} 25 | * 26 | * @book{leveque2002finite, 27 | * Author = {LeVeque, R. J.}, 28 | * Date-Added = {2011-09-13 14:09:31 +0000}, 29 | * Date-Modified = {2011-10-31 09:46:40 +0000}, 30 | * Publisher = {Cambridge University Press}, 31 | * Title = {Finite Volume Methods for Hyperbolic Problems}, 32 | * Volume = {31}, 33 | * Year = {2002}} 34 | * 35 | * @webpage{levequeclawpack, 36 | * Author = {LeVeque, R. J.}, 37 | * Lastchecked = {January, 05, 2011}, 38 | * Title = {Clawpack Sofware}, 39 | * Url = {https://github.com/clawpack/clawpack-4.x/blob/master/geoclaw/2d/lib}} 40 | * 41 | **** 42 | * 43 | * Acknowledgments: 44 | * Special thanks go to R.J. LeVeque and D.L. George for publishing their code 45 | * and the corresponding documentation (-> Literature). 46 | */ 47 | 48 | #include 49 | #include 50 | 51 | typedef float T; 52 | 53 | //! numerical definition of zero. 54 | const T zeroTol = (T)0.0000001; 55 | 56 | //! numerical definition of a dry cell 57 | const T dryTol = (T)1.; 58 | 59 | /* 60 | * Visual C++ compiler doesn't allow the definitions above. 61 | * Therefore the pre-compiler should be used. 62 | */ 63 | //#define zeroTol (T)0.0000001 64 | //#define dryTol (T)100. 65 | 66 | __device__ void fWaveComputeNetUpdates( 67 | const T i_gravity, 68 | T i_hLeft, 69 | T i_hRight, 70 | T i_huLeft, 71 | T i_huRight, 72 | T i_bLeft, 73 | T i_bRight, 74 | 75 | T o_netUpdates[5] 76 | ); 77 | 78 | __device__ inline void fWaveComputeWaveSpeeds( 79 | const T i_gravity, 80 | const T i_hLeft, 81 | const T i_hRight, 82 | const T i_huLeft, 83 | const T i_huRight, 84 | const T i_uLeft, 85 | const T i_uRight, 86 | const T i_bLeft, 87 | const T i_bRight, 88 | 89 | T o_waveSpeeds[2] 90 | ); 91 | 92 | __device__ inline void fWaveComputeWaveDecomposition( 93 | const T i_gravity, 94 | const T i_hLeft, 95 | const T i_hRight, 96 | const T i_huLeft, 97 | const T i_huRight, 98 | const T i_uLeft, 99 | const T i_uRight, 100 | const T i_bLeft, 101 | const T i_bRight, 102 | const T i_waveSpeeds[2], 103 | 104 | T o_fWaves[2][2] 105 | ); 106 | 107 | /** 108 | * Compute net updates for the cell on the left/right side of the edge 109 | * 110 | * The order of o_netUpdates is given by: 111 | * 0: hUpdateLeft - Net-update for the height of the cell on the left side of the edge. 112 | * 1: hUpdateRight - Net-update for the height of the cell on the right side of the edge. 113 | * 2: huUpdateLeft - Net-update for the momentum of the cell on the left side of the edge 114 | * 3: huUpdateRight - Net-update for the momentum of the cell on the right side of the edge. 115 | * 4: maxWaveSpeed - Maximum (linearized) wave speed -> Should be used in the CFL-condition. 116 | * 117 | * TODO: A wet/wet state is assumend / no boundaries are implemented within the solver to 118 | * allow an execution with with a few jumps only. 119 | * 120 | * @param i_gravity gravity constant. 121 | * @param i_hLeft height on the left side of the edge. 122 | * @param i_hRight height on the right side of the edge. 123 | * @param i_huLeft momentum on the left side of the edge. 124 | * @param i_huRight momentum on the right side of the edge. 125 | * @param i_bLeft bathymetry on the left side of the edge. 126 | * @param i_bRight bathymetry on the right side of the edge. 127 | * 128 | * @param o_netUpdates will be set to the net updates. 129 | */ 130 | __device__ void fWaveComputeNetUpdates( 131 | const T i_gravity, 132 | T i_hLeft, 133 | T i_hRight, 134 | T i_huLeft, 135 | T i_huRight, 136 | T i_bLeft, 137 | T i_bRight, 138 | 139 | T o_netUpdates[5] 140 | ) { 141 | // reset net updates 142 | o_netUpdates[0] = (T)0.; // hUpdateLeft 143 | o_netUpdates[1] = (T)0.; // hUpdateRight 144 | o_netUpdates[2] = (T)0.; // huUpdateLeft 145 | o_netUpdates[3] = (T)0.; // huUpdateRight 146 | 147 | // reset the maximum wave speed 148 | o_netUpdates[4] = (T)0.; // maxWaveSpeed 149 | 150 | // determine the wet dry state and corr. values, if necessary. 151 | if (!(i_hLeft > dryTol && i_hRight > dryTol)) { 152 | if (i_hLeft < dryTol && i_hRight < dryTol) 153 | return; 154 | else if (i_hLeft < dryTol) { 155 | i_hLeft = i_hRight; 156 | i_huLeft = -i_huRight; 157 | i_bLeft = i_bRight; 158 | } else { //( i_hRight < dryTol ) 159 | i_hRight = i_hLeft; 160 | i_huRight = -i_huLeft; 161 | i_bRight = i_bLeft; 162 | } 163 | } 164 | 165 | //! velocity on the left side of the edge 166 | T uLeft = i_huLeft / i_hLeft; 167 | //! velocity on the right side of the edge 168 | T uRight = i_huRight / i_hRight; 169 | 170 | //! wave speeds of the f-waves 171 | T waveSpeeds[2]; 172 | 173 | // compute the wave speeds 174 | fWaveComputeWaveSpeeds( 175 | i_gravity, 176 | i_hLeft, 177 | i_hRight, 178 | i_huLeft, 179 | i_huRight, 180 | uLeft, 181 | uRight, 182 | i_bLeft, 183 | i_bRight, 184 | 185 | waveSpeeds 186 | ); 187 | 188 | //! where to store the two f-waves 189 | T fWaves[2][2]; 190 | 191 | // compute the decomposition into f-waves 192 | fWaveComputeWaveDecomposition( 193 | i_gravity, 194 | i_hLeft, 195 | i_hRight, 196 | i_huLeft, 197 | i_huRight, 198 | uLeft, 199 | uRight, 200 | i_bLeft, 201 | i_bRight, 202 | 203 | waveSpeeds, 204 | fWaves 205 | ); 206 | 207 | // compute the net-updates 208 | // 1st wave family 209 | if (waveSpeeds[0] < -zeroTol) { // left going 210 | o_netUpdates[0] += fWaves[0][0]; // hUpdateLeft 211 | o_netUpdates[2] += fWaves[0][1]; // huUpdateLeft 212 | } else if (waveSpeeds[0] > zeroTol) { // right going 213 | o_netUpdates[1] += fWaves[0][0]; // hUpdateRight 214 | o_netUpdates[3] += fWaves[0][1]; // huUpdateRight 215 | } else { // split waves 216 | o_netUpdates[0] += (T).5 * fWaves[0][0]; // hUpdateLeft 217 | o_netUpdates[2] += (T).5 * fWaves[0][1]; // huUpdateLeft 218 | o_netUpdates[1] += (T).5 * fWaves[0][0]; // hUpdateRight 219 | o_netUpdates[3] += (T).5 * fWaves[0][1]; // huUpdateRight 220 | } 221 | 222 | // 2nd wave family 223 | if (waveSpeeds[1] < -zeroTol) { // left going 224 | o_netUpdates[0] += fWaves[1][0]; // hUpdateLeft 225 | o_netUpdates[2] += fWaves[1][1]; // huUpdateLeft 226 | } else if (waveSpeeds[1] > zeroTol) { // right going 227 | o_netUpdates[1] += fWaves[1][0]; // hUpdateRight 228 | o_netUpdates[3] += fWaves[1][1]; // huUpdateRight 229 | } else { // split waves 230 | o_netUpdates[0] += (T).5 * fWaves[1][0]; // hUpdateLeft 231 | o_netUpdates[2] += (T).5 * fWaves[1][1]; // huUpdateLeft 232 | o_netUpdates[1] += (T).5 * fWaves[1][0]; // hUpdateRight 233 | o_netUpdates[3] += (T).5 * fWaves[1][1]; // huUpdateRight 234 | } 235 | 236 | // compute maximum wave speed (-> CFL-condition) 237 | o_netUpdates[4] = fmax(fabs(waveSpeeds[0]), fabs(waveSpeeds[1])); 238 | } 239 | 240 | /** 241 | * Compute the edge local eigenvalues. 242 | * 243 | * @param i_gravity gravity constant. 244 | * @param i_hLeft height on the left side of the edge. 245 | * @param i_hRight height on the right side of the edge. 246 | * @param i_huLeft momentum on the left side of the edge. 247 | * @param i_huRight momentum on the right side of the edge. 248 | * @param i_uLeft velocity on the left side of the edge. 249 | * @param i_uRight velocity on the right side of the edge. 250 | * @param i_bLeft bathymetry on the left side of the edge. 251 | * @param i_bRight bathymetry on the right side of the edge. 252 | * 253 | * @param o_waveSpeeds will be set to: speeds of the linearized waves (eigenvalues). 254 | */ 255 | __device__ inline void fWaveComputeWaveSpeeds( 256 | const T i_gravity, 257 | const T i_hLeft, 258 | const T i_hRight, 259 | const T i_huLeft, 260 | const T i_huRight, 261 | const T i_uLeft, 262 | const T i_uRight, 263 | const T i_bLeft, 264 | const T i_bRight, 265 | 266 | T o_waveSpeeds[2] 267 | ) { 268 | // compute eigenvalues of the jacobian matrices in states Q_{i-1} and Q_{i} 269 | T characteristicSpeeds[2]; 270 | characteristicSpeeds[0] = i_uLeft - sqrt(i_gravity * i_hLeft); 271 | characteristicSpeeds[1] = i_uRight + sqrt(i_gravity * i_hRight); 272 | 273 | // compute "Roe speeds" 274 | T hRoe = (T).5 * (i_hRight + i_hLeft); 275 | T uRoe = i_uLeft * sqrt(i_hLeft) + i_uRight * sqrt(i_hRight); 276 | uRoe /= sqrt(i_hLeft) + sqrt(i_hRight); 277 | 278 | T roeSpeeds[2]; 279 | roeSpeeds[0] = uRoe - sqrt(i_gravity * hRoe); 280 | roeSpeeds[1] = uRoe + sqrt(i_gravity * hRoe); 281 | 282 | // computer eindfeldt speeds 283 | T einfeldtSpeeds[2]; 284 | einfeldtSpeeds[0] = fmin(characteristicSpeeds[0], roeSpeeds[0]); 285 | einfeldtSpeeds[1] = fmax(characteristicSpeeds[1], roeSpeeds[1]); 286 | 287 | // set wave speeds 288 | o_waveSpeeds[0] = einfeldtSpeeds[0]; 289 | o_waveSpeeds[1] = einfeldtSpeeds[1]; 290 | } 291 | 292 | /** 293 | * Compute the decomposition into f-Waves. 294 | * 295 | * @param i_gravity gravity constant. 296 | * @param i_hLeft height on the left side of the edge. 297 | * @param i_hRight height on the right side of the edge. 298 | * @param i_huLeft momentum on the left side of the edge. 299 | * @param i_huRight momentum on the right side of the edge. 300 | * @param i_uLeft velocity on the left side of the edge. 301 | * @param i_uRight velocity on the right side of the edge. 302 | * @param i_bLeft bathymetry on the left side of the edge. 303 | * @param i_bRight bathymetry on the right side of the edge. 304 | * @param i_waveSpeeds speeds of the linearized waves (eigenvalues). 305 | * @param o_fWaves will be set to: Decomposition into f-Waves. 306 | */ 307 | __device__ inline void fWaveComputeWaveDecomposition( 308 | const T i_gravity, 309 | const T i_hLeft, 310 | const T i_hRight, 311 | const T i_huLeft, 312 | const T i_huRight, 313 | const T i_uLeft, 314 | const T i_uRight, 315 | const T i_bLeft, 316 | const T i_bRight, 317 | const T i_waveSpeeds[2], 318 | 319 | T o_fWaves[2][2] 320 | ) { 321 | T lambdaDif = i_waveSpeeds[1] - i_waveSpeeds[0]; 322 | 323 | // compute the inverse matrix R^{-1} 324 | T Rinv[2][2]; 325 | 326 | T oneDivLambdaDif = (T)1. / lambdaDif; 327 | Rinv[0][0] = oneDivLambdaDif * i_waveSpeeds[1]; 328 | Rinv[0][1] = -oneDivLambdaDif; 329 | 330 | Rinv[1][0] = oneDivLambdaDif * -i_waveSpeeds[0]; 331 | Rinv[1][1] = oneDivLambdaDif; 332 | 333 | // right hand side 334 | T fDif[2]; 335 | 336 | // calculate modified (bathymetry!) flux difference 337 | // f(Q_i) - f(Q_{i-1}) 338 | fDif[0] = i_huRight - i_huLeft; 339 | fDif[1] = i_huRight * i_uRight + (T).5 * i_gravity * i_hRight * i_hRight 340 | - (i_huLeft * i_uLeft + (T).5 * i_gravity * i_hLeft * i_hLeft); 341 | 342 | // \delta x \Psi[2] 343 | T psi = -i_gravity * (T).5 * (i_hRight + i_hLeft) * (i_bRight - i_bLeft); 344 | fDif[1] -= psi; 345 | 346 | // solve linear equations 347 | T beta[2]; 348 | beta[0] = Rinv[0][0] * fDif[0] + Rinv[0][1] * fDif[1]; 349 | beta[1] = Rinv[1][0] * fDif[0] + Rinv[1][1] * fDif[1]; 350 | 351 | // return f-waves 352 | o_fWaves[0][0] = beta[0]; 353 | o_fWaves[0][1] = beta[0] * i_waveSpeeds[0]; 354 | 355 | o_fWaves[1][0] = beta[1]; 356 | o_fWaves[1][1] = beta[1] * i_waveSpeeds[1]; 357 | 358 | /* 359 | * in the case of a "zero strength" wave set the wave speeds to zero 360 | * => non present waves don't affect the CFL-condition. 361 | * TODO: Seems not to affect the time step size 362 | */ 363 | // if( fmax(fabs(beta[0]), fabs(beta[1])) < zeroTol ) { 364 | // io_waveSpeeds[0] = (T) 0.; 365 | // io_waveSpeeds[1] = (T) 0.; 366 | // } 367 | } 368 | 369 | // undefine the constants (see above) 370 | #undef zeroTol 371 | #undef dryTol 372 | -------------------------------------------------------------------------------- /Source/FWaveSolver.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * FWaveSolver.hpp 3 | * 4 | **** 5 | **** F-Wave Riemann Solver for the Shallow Water Equation 6 | **** 7 | * 8 | * Created on: Aug 25, 2011 9 | * Last Update: Feb 18, 2012 10 | * 11 | **** 12 | * 13 | * Author: Alexander Breuer 14 | * Homepage: http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer 15 | * E-Mail: breuera AT in.tum.de 16 | * 17 | **** 18 | * 19 | * (Main) Literature: 20 | * 21 | * @article{bale2002wave, 22 | * title={A wave propagation method for conservation laws and balance laws with spatially varying flux 23 | *functions}, author={Bale, D.S. and LeVeque, R.J. and Mitran, S. and Rossmanith, J.A.}, journal={SIAM Journal on 24 | *Scientific Computing}, volume={24}, number={3}, pages={955--978}, year={2002}, publisher={Citeseer}} 25 | * 26 | * @book{leveque2002finite, 27 | * Author = {LeVeque, R. J.}, 28 | * Date-Added = {2011-09-13 14:09:31 +0000}, 29 | * Date-Modified = {2011-10-31 09:46:40 +0000}, 30 | * Publisher = {Cambridge University Press}, 31 | * Title = {Finite Volume Methods for Hyperbolic Problems}, 32 | * Volume = {31}, 33 | * Year = {2002}} 34 | * 35 | * @webpage{levequeclawpack, 36 | * Author = {LeVeque, R. J.}, 37 | * Lastchecked = {January, 05, 2011}, 38 | * Title = {Clawpack Sofware}, 39 | * Url = {https://github.com/clawpack/clawpack-4.x/blob/master/geoclaw/2d/lib}} 40 | * 41 | **** 42 | * 43 | * Acknowledgments: 44 | * Special thanks go to R.J. LeVeque and D.L. George for publishing their code 45 | * and the corresponding documentation (-> Literature). 46 | */ 47 | 48 | #pragma once 49 | 50 | #include 51 | #include 52 | #include 53 | #include 54 | 55 | #include "WavePropagationSolver.hpp" 56 | 57 | namespace Solvers { 58 | 59 | /** 60 | * FWave Riemann Solver for the Shallow Water Equations. 61 | * 62 | * T should be double or float. 63 | */ 64 | template 65 | class FWaveSolver: public WavePropagationSolver { 66 | private: 67 | // Use nondependent names (template base class) 68 | using WavePropagationSolver::dryTol_; 69 | using WavePropagationSolver::gravity_; 70 | using WavePropagationSolver::zeroTol_; 71 | 72 | using WavePropagationSolver::hLeft_; 73 | using WavePropagationSolver::hRight_; 74 | using WavePropagationSolver::huLeft_; 75 | using WavePropagationSolver::huRight_; 76 | using WavePropagationSolver::bLeft_; 77 | using WavePropagationSolver::bRight_; 78 | using WavePropagationSolver::uLeft_; 79 | using WavePropagationSolver::uRight_; 80 | 81 | using WavePropagationSolver::wetDryState_; 82 | 83 | /** 84 | * Compute the edge local eigenvalues. 85 | * 86 | * @param o_waveSpeeds will be set to: speeds of the linearized waves (eigenvalues). 87 | */ 88 | void computeWaveSpeeds(T o_waveSpeeds[2]) const { 89 | // Compute eigenvalues of the Jacobian matrices in states Q_{i-1} and Q_{i} 90 | T characteristicSpeeds[2]{}; 91 | characteristicSpeeds[0] = uLeft_ - std::sqrt(gravity_ * hLeft_); 92 | characteristicSpeeds[1] = uRight_ + std::sqrt(gravity_ * hRight_); 93 | 94 | // Compute "Roe speeds" 95 | T hRoe = T(0.5) * (hRight_ + hLeft_); 96 | T uRoe = uLeft_ * std::sqrt(hLeft_) + uRight_ * std::sqrt(hRight_); 97 | uRoe /= std::sqrt(hLeft_) + std::sqrt(hRight_); 98 | 99 | T roeSpeeds[2]{}; 100 | roeSpeeds[0] = uRoe - std::sqrt(gravity_ * hRoe); 101 | roeSpeeds[1] = uRoe + std::sqrt(gravity_ * hRoe); 102 | 103 | // Compute eindfeldt speeds 104 | T einfeldtSpeeds[2]{}; 105 | einfeldtSpeeds[0] = std::min(characteristicSpeeds[0], roeSpeeds[0]); 106 | einfeldtSpeeds[1] = std::max(characteristicSpeeds[1], roeSpeeds[1]); 107 | 108 | // Set wave speeds 109 | o_waveSpeeds[0] = einfeldtSpeeds[0]; 110 | o_waveSpeeds[1] = einfeldtSpeeds[1]; 111 | } 112 | 113 | /** 114 | * Compute the decomposition into f-Waves. 115 | * 116 | * @param waveSpeeds speeds of the linearized waves (eigenvalues). 117 | * @param o_fWaves will be set to: Decomposition into f-Waves. 118 | */ 119 | void computeWaveDecomposition(const T waveSpeeds[2], T o_fWaves[2][2]) const { 120 | // Eigenvalues*********************************************************************************************** 121 | // Computed somewhere before. 122 | // An option would be to use the char. Speeds: 123 | // 124 | // lambda^1 = u_{i-1} - sqrt(g * h_{i-1}) 125 | // lambda^2 = u_i + sqrt(g * h_i) 126 | // Matrix of right eigenvectors****************************************************************************** 127 | // 1 1 128 | // R = 129 | // u_{i-1} - sqrt(g * h_{i-1}) u_i + sqrt(g * h_i) 130 | // ********************************************************************************************************** 131 | // u_i + sqrt(g * h_i) -1 132 | // R^{-1} = 1 / (u_i - sqrt(g * h_i) - u_{i-1} + sqrt(g * h_{i-1}) * 133 | // -( u_{i-1} - sqrt(g * h_{i-1}) ) 1 134 | // ********************************************************************************************************** 135 | // hu 136 | // f(q) = 137 | // hu^2 + 1/2 g * h^2 138 | // ********************************************************************************************************** 139 | // 0 140 | // \delta x \Psi = 141 | // -g * 1/2 * (h_i + h_{i-1}) * (b_i - b_{i+1}) 142 | // ********************************************************************************************************** 143 | // beta = R^{-1} * (f(Q_i) - f(Q_{i-1}) - \delta x \Psi) 144 | // ********************************************************************************************************** 145 | 146 | // assert: wave speed of the 1st wave family should be less than the speed of the 2nd wave family. 147 | assert(waveSpeeds[0] < waveSpeeds[1]); 148 | 149 | T lambdaDif = waveSpeeds[1] - waveSpeeds[0]; 150 | 151 | // assert: no division by zero 152 | assert(std::abs(lambdaDif) > zeroTol_); 153 | 154 | // Compute the inverse matrix R^{-1} 155 | T Rinv[2][2]{}; 156 | 157 | T oneDivLambdaDif = T(1.0) / lambdaDif; 158 | Rinv[0][0] = oneDivLambdaDif * waveSpeeds[1]; 159 | Rinv[0][1] = -oneDivLambdaDif; 160 | 161 | Rinv[1][0] = oneDivLambdaDif * -waveSpeeds[0]; 162 | Rinv[1][1] = oneDivLambdaDif; 163 | 164 | // Right hand side 165 | T fDif[2]{}; 166 | 167 | // Calculate modified (bathymetry!) flux difference 168 | // f(Q_i) - f(Q_{i-1}) 169 | fDif[0] = huRight_ - huLeft_; 170 | fDif[1] = huRight_ * uRight_ + T(0.5) * gravity_ * hRight_ * hRight_ 171 | - (huLeft_ * uLeft_ + T(0.5) * gravity_ * hLeft_ * hLeft_); 172 | 173 | // \delta x \Psi[2] 174 | T psi = -gravity_ * T(0.5) * (hRight_ + hLeft_) * (bRight_ - bLeft_); 175 | fDif[1] -= psi; 176 | 177 | // Solve linear equations 178 | T beta[2]{}; 179 | beta[0] = Rinv[0][0] * fDif[0] + Rinv[0][1] * fDif[1]; 180 | beta[1] = Rinv[1][0] * fDif[0] + Rinv[1][1] * fDif[1]; 181 | 182 | // Return f-waves 183 | o_fWaves[0][0] = beta[0]; 184 | o_fWaves[0][1] = beta[0] * waveSpeeds[0]; 185 | 186 | o_fWaves[1][0] = beta[1]; 187 | o_fWaves[1][1] = beta[1] * waveSpeeds[1]; 188 | } 189 | 190 | /** 191 | * Compute net updates for the cell on the left/right side of the edge. 192 | * Its assumed that the member variables are set already. 193 | * 194 | * @param waveSpeeds speeds of the linearized waves (eigenvalues). 195 | * 196 | * @param o_hUpdateLeft will be set to: Net-update for the height of the cell on the left side of the edge. 197 | * @param o_hUpdateRight will be set to: Net-update for the height of the cell on the right side of the edge. 198 | * @param o_huUpdateLeft will be set to: Net-update for the momentum of the cell on the left side of the edge. 199 | * @param o_huUpdateRight will be set to: Net-update for the momentum of the cell on the right side of the edge. 200 | * @param o_maxWaveSpeed will be set to: Maximum (linearized) wave speed -> Should be used in the CFL-condition. 201 | */ 202 | void computeNetUpdatesWithWaveSpeeds( 203 | const T waveSpeeds[2], 204 | T& o_hUpdateLeft, 205 | T& o_hUpdateRight, 206 | T& o_huUpdateLeft, 207 | T& o_huUpdateRight, 208 | T& o_maxWaveSpeed 209 | ) { 210 | // Reset net updates 211 | o_hUpdateLeft = o_hUpdateRight = o_huUpdateLeft = o_huUpdateRight = T(0.0); 212 | 213 | //! Where to store the two f-waves 214 | T fWaves[2][2]; 215 | 216 | // Compute the decomposition into f-waves 217 | computeWaveDecomposition(waveSpeeds, fWaves); 218 | 219 | // Compute the net-updates 220 | // 1st wave family 221 | if (waveSpeeds[0] < -zeroTol_) { // Left going 222 | o_hUpdateLeft += fWaves[0][0]; 223 | o_huUpdateLeft += fWaves[0][1]; 224 | } else if (waveSpeeds[0] > zeroTol_) { // Right going 225 | o_hUpdateRight += fWaves[0][0]; 226 | o_huUpdateRight += fWaves[0][1]; 227 | } else { // Split waves 228 | o_hUpdateLeft += T(0.5) * fWaves[0][0]; 229 | o_huUpdateLeft += T(0.5) * fWaves[0][1]; 230 | o_hUpdateRight += T(0.5) * fWaves[0][0]; 231 | o_huUpdateRight += T(0.5) * fWaves[0][1]; 232 | } 233 | 234 | // 2nd wave family 235 | if (waveSpeeds[1] < -zeroTol_) { // Left going 236 | o_hUpdateLeft += fWaves[1][0]; 237 | o_huUpdateLeft += fWaves[1][1]; 238 | } else if (waveSpeeds[1] > zeroTol_) { // Right going 239 | o_hUpdateRight += fWaves[1][0]; 240 | o_huUpdateRight += fWaves[1][1]; 241 | } else { // Split waves 242 | o_hUpdateLeft += T(0.5) * fWaves[1][0]; 243 | o_huUpdateLeft += T(0.5) * fWaves[1][1]; 244 | o_hUpdateRight += T(0.5) * fWaves[1][0]; 245 | o_huUpdateRight += T(0.5) * fWaves[1][1]; 246 | } 247 | 248 | // Compute maximum wave speed (-> CFL-condition) 249 | o_maxWaveSpeed = std::max(std::fabs(waveSpeeds[0]), std::fabs(waveSpeeds[1])); 250 | } 251 | 252 | protected: 253 | /** 254 | * Determine the wet/dry state and set member variables accordingly. 255 | */ 256 | void determineWetDryState() override { 257 | // Determine the wet/dry state 258 | if (hLeft_ < dryTol_ && hRight_ < dryTol_) { // Both cells are dry 259 | wetDryState_ = WavePropagationSolver::WetDryState::DryDry; 260 | } else if (hLeft_ < dryTol_) { // Left cell dry, right cell wet 261 | uRight_ = huRight_ / hRight_; 262 | 263 | // Set wall boundary conditions. 264 | // This is not correct in the case of inundation problems. 265 | hLeft_ = hRight_; 266 | bLeft_ = bRight_; 267 | huLeft_ = -huRight_; 268 | uLeft_ = -uRight_; 269 | wetDryState_ = WavePropagationSolver::WetDryState::DryWetWall; 270 | } else if (hRight_ < dryTol_) { // Left cell wet, right cell dry 271 | uLeft_ = huLeft_ / hLeft_; 272 | 273 | // Set wall boundary conditions. 274 | // This is not correct in the case of inundation problems. 275 | hRight_ = hLeft_; 276 | bRight_ = bLeft_; 277 | huRight_ = -huLeft_; 278 | uRight_ = -uLeft_; 279 | wetDryState_ = WavePropagationSolver::WetDryState::WetDryWall; 280 | } else { // Both cells wet 281 | uLeft_ = huLeft_ / hLeft_; 282 | uRight_ = huRight_ / hRight_; 283 | 284 | wetDryState_ = WavePropagationSolver::WetDryState::WetWet; 285 | } 286 | } 287 | 288 | public: 289 | /** 290 | * Constructor of the f-Wave solver with optional parameters. 291 | * 292 | * @param dryTolerance numerical definition of "dry". 293 | * @param gravity gravity constant. 294 | * @param zeroTolerance numerical definition of zero. 295 | */ 296 | FWaveSolver( 297 | T dryTolerance = static_cast(0.01), 298 | T gravity = static_cast(9.81), 299 | T zeroTolerance = static_cast(0.000000001) 300 | ): 301 | WavePropagationSolver(dryTolerance, gravity, zeroTolerance) {} 302 | 303 | ~FWaveSolver() override = default; 304 | 305 | /** 306 | * Compute net updates for the cell on the left/right side of the edge. 307 | * This is the default method of a standalone f-Wave solver. 308 | * 309 | * Please note: 310 | * In the case of a Dry/Wet- or Wet/Dry-boundary, wall boundary conditions will be set. 311 | * The f-Wave solver is not positivity preserving. 312 | * -> You as the programmer have to take care about "negative water heights"! 313 | * 314 | * @param hLeft height on the left side of the edge. 315 | * @param hRight height on the right side of the edge. 316 | * @param huLeft momentum on the left side of the edge. 317 | * @param huRight momentum on the right side of the edge. 318 | * @param bLeft bathymetry on the left side of the edge. 319 | * @param bRight bathymetry on the right side of the edge. 320 | * 321 | * @param o_hUpdateLeft will be set to: Net-update for the height of the cell on the left side of the edge. 322 | * @param o_hUpdateRight will be set to: Net-update for the height of the cell on the right side of the edge. 323 | * @param o_huUpdateLeft will be set to: Net-update for the momentum of the cell on the left side of the edge. 324 | * @param o_huUpdateRight will be set to: Net-update for the momentum of the cell on the right side of the edge. 325 | * @param o_maxWaveSpeed will be set to: Maximum (linearized) wave speed -> Should be used in the CFL-condition. 326 | */ 327 | void computeNetUpdates( 328 | const T& hLeft, 329 | const T& hRight, 330 | const T& huLeft, 331 | const T& huRight, 332 | const T& bLeft, 333 | const T& bRight, 334 | T& o_hUpdateLeft, 335 | T& o_hUpdateRight, 336 | T& o_huUpdateLeft, 337 | T& o_huUpdateRight, 338 | T& o_maxWaveSpeed 339 | ) override { 340 | // Set speeds to zero (will be determined later) 341 | uLeft_ = uRight_ = 0; 342 | 343 | // Reset the maximum wave speed 344 | o_maxWaveSpeed = 0; 345 | 346 | //! Wave speeds of the f-waves 347 | T waveSpeeds[2]; 348 | 349 | // Store parameters to member variables 350 | WavePropagationSolver::storeParameters(hLeft, hRight, huLeft, huRight, bLeft, bRight); 351 | 352 | // Determine the wet/dry state and compute local variables correspondingly 353 | determineWetDryState(); 354 | 355 | // Zero updates and return in the case of dry cells 356 | if (wetDryState_ == WavePropagationSolver::WetDryState::DryDry) { 357 | o_hUpdateLeft = o_hUpdateRight = o_huUpdateLeft = o_huUpdateRight = T(0.0); 358 | return; 359 | } 360 | 361 | // Compute the wave speeds 362 | computeWaveSpeeds(waveSpeeds); 363 | 364 | // Use the wave speeds to compute the net-updates 365 | computeNetUpdatesWithWaveSpeeds( 366 | waveSpeeds, o_hUpdateLeft, o_hUpdateRight, o_huUpdateLeft, o_huUpdateRight, o_maxWaveSpeed 367 | ); 368 | 369 | // Zero ghost updates (wall boundary) 370 | if (wetDryState_ == WavePropagationSolver::WetDryState::WetDryWall) { 371 | o_hUpdateRight = 0; 372 | o_huUpdateRight = 0; 373 | } else if (wetDryState_ == WavePropagationSolver::WetDryState::DryWetWall) { 374 | o_hUpdateLeft = 0; 375 | o_huUpdateLeft = 0; 376 | } 377 | } 378 | 379 | /** 380 | * Compute net updates for the cell on the left/right side of the edge. 381 | * This is an expert method, because a lot of (numerical-)knowledge about the problem is assumed/has to be provided. 382 | * It is the f-Wave entry point for the hybrid solver, which combines the "simple" F-Wave approach with the more 383 | * complex Augmented Riemann Solver. 384 | * 385 | * wetDryState is assumed to be WetWet. 386 | * 387 | * @param hLeft height on the left side of the edge. 388 | * @param hRight height on the right side of the edge. 389 | * @param huLeft momentum on the left side of the edge. 390 | * @param huRight momentum on the right side of the edge. 391 | * @param bLeft bathymetry on the left side of the edge. 392 | * @param bRight bathymetry on the right side of the edge. 393 | * @param uLeft velocity on the left side of the edge. 394 | * @param uRight velocity on the right side of the edge. 395 | * @param waveSpeeds speeds of the linearized waves (eigenvalues). 396 | * A hybrid solver will typically provide its own values. 397 | * 398 | * @param o_hUpdateLeft will be set to: Net-update for the height of the cell on the left side of the edge. 399 | * @param o_hUpdateRight will be set to: Net-update for the height of the cell on the right side of the edge. 400 | * @param o_huUpdateLeft will be set to: Net-update for the momentum of the cell on the left side of the edge. 401 | * @param o_huUpdateRight will be set to: Net-update for the momentum of the cell on the right side of the edge. 402 | * @param o_maxWaveSpeed will be set to: Maximum (linearized) wave speed -> Should be used in the CFL-condition. 403 | */ 404 | void computeNetUpdatesHybrid( 405 | const T& hLeft, 406 | const T& hRight, 407 | const T& huLeft, 408 | const T& huRight, 409 | const T& bLeft, 410 | const T& bRight, 411 | const T& uLeft, 412 | const T& uRight, 413 | const T waveSpeeds[2], 414 | T& o_hUpdateLeft, 415 | T& o_hUpdateRight, 416 | T& o_huUpdateLeft, 417 | T& o_huUpdateRight, 418 | T& o_maxWaveSpeed 419 | ) { 420 | // Store parameters to member variables 421 | storeParameters(hLeft, hRight, huLeft, huRight, bLeft, bRight, uLeft, uRight); 422 | 423 | computeNetUpdatesWithWaveSpeeds( 424 | waveSpeeds, o_hUpdateLeft, o_hUpdateRight, o_huUpdateLeft, o_huUpdateRight, o_maxWaveSpeed 425 | ); 426 | } 427 | }; 428 | 429 | } // namespace Solvers 430 | -------------------------------------------------------------------------------- /Source/HLLEFunSolver.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * HLLEFun.hpp 3 | * @file 4 | * This file is part of Pond. 5 | * 6 | **** 7 | **** HLLE Solver for the Shallow Water Equations 8 | **** vectorizable functional implementation (based on AugRieFun) 9 | **** 10 | **** 11 | * 12 | * Author: Nicolai Schaffroth 13 | * 14 | * AugRiefun: Alexander Breuer 15 | * Homepage: http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer 16 | * E-Mail: breuera AT in.tum.de 17 | * 18 | * Some optimizations: Martin Schreiber 19 | * Homepage: http://www5.in.tum.de/wiki/index.php/Martin_Schreiber 20 | * E-Mail: schreibm AT in.tum.de 21 | * 22 | * CUDA: Wolfgang Hölzl 23 | * E-Mail: hoelzlw AT in.tum.de 24 | * 25 | * Further optimizations: Michael Bader 26 | * Homepage: http://www5.in.tum.de/wiki/index.php/Michael_Bader 27 | * E-Mail: bader AT in.tum.de 28 | *** 29 | * 30 | * @section LICENSE 31 | * 32 | * Pond is free software: you can redistribute it and/or modify 33 | * it under the terms of the GNU General Public License as published by 34 | * the Free Software Foundation, either version 3 of the License, or 35 | * (at your option) any later version. 36 | * 37 | * Pond is distributed in the hope that it will be useful, 38 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 39 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 40 | * GNU General Public License for more details. 41 | * 42 | * You should have received a copy of the GNU General Public License 43 | * along with Pond. If not, see . 44 | * 45 | **** 46 | */ 47 | 48 | #ifndef HLLE_FUN_HPP 49 | #define HLLE_FUN_HPP 50 | 51 | #include 52 | #include 53 | #include 54 | //#include 55 | //#include 56 | 57 | // constants to classify wet-dry-state of a pairs of cells: 58 | const int DryDry = 0; 59 | const int WetWet = 1; 60 | const int WetDryInundation = 2; 61 | const int WetDryWall = 3; 62 | const int WetDryWallInundation = 4; 63 | const int DryWetInundation = 5; 64 | const int DryWetWall = 6; 65 | const int DryWetWallInundation = 7; 66 | 67 | // constants to classify Riemann state of a pairs of cells: 68 | const int DrySingleRarefaction = 0; 69 | const int SingleRarefactionDry = 1; 70 | const int ShockShock = 2; 71 | const int ShockRarefaction = 3; 72 | const int RarefactionShock = 4; 73 | const int RarefactionRarefaction = 5; 74 | 75 | namespace solver { 76 | 77 | /** 78 | * 79 | */ 80 | template 81 | class HLLEFun { 82 | private: 83 | const T dryTol; 84 | const T g; // gravity constant 85 | const T half_g; // 0.5 * gravity constant 86 | const T sqrt_g; // square root of the gravity constant 87 | const T zeroTol; 88 | 89 | public: 90 | /** 91 | * AugRieFun Constructor, takes three problem parameters 92 | * @param dryTol "dry tolerance": if the water height falls below dryTol, wall boundary conditions are applied 93 | * (default value is 0.01) 94 | * @param gravity takes the value of the gravity constant (default value is 9.81 m/s^2) 95 | * @param zeroTol computed f-waves with an absolute value < zeroTol are treated as static waves (default value is 96 | * 10^{-7}) 97 | */ 98 | HLLEFun(T i_dryTol = (T)0.01, T i_gravity = (T)9.81, T i_zeroTol = (T)0.0000001): 99 | dryTol(i_dryTol), 100 | g(i_gravity), 101 | half_g((T).5 * i_gravity), 102 | sqrt_g(std::sqrt(i_gravity)), 103 | zeroTol(i_zeroTol) {} 104 | 105 | // Define MIN and MAX as Macros, std::min and std::max seem to crash icpc 106 | // For some reason, the Intel C++ compiler crashes during when Vectorization is enabled. 107 | #define MIN(x, y) (((x) <= (y)) ? (x) : (y)) 108 | #define MAX(x, y) (((x) >= (y)) ? (x) : (y)) 109 | 110 | /** 111 | * Compute net updates for the left/right cell of the edge. 112 | * 113 | * maxWaveSpeed will be set to the maximum (linearized) wave speed => CFL 114 | */ 115 | #ifdef VECTORIZE 116 | #pragma omp declare simd 117 | #endif 118 | void computeNetUpdates( 119 | const T i_hLeft, 120 | const T i_hRight, 121 | const T i_huLeft, 122 | const T i_huRight, 123 | const T i_bLeft, 124 | const T i_bRight, 125 | 126 | T& o_hUpdateLeft, 127 | T& o_hUpdateRight, 128 | T& o_huUpdateLeft, 129 | T& o_huUpdateRight, 130 | T& o_maxWaveSpeed 131 | ) const { 132 | T hLeft = i_hLeft; 133 | T hRight = i_hRight; 134 | T uLeft = (T)0; 135 | T uRight = (T)0; 136 | T huLeft = i_huLeft; 137 | T huRight = i_huRight; 138 | T bLeft = i_bLeft; 139 | T bRight = i_bRight; 140 | 141 | // declare variables which are used over and over again 142 | T sqrt_g_hLeft; 143 | T sqrt_g_hRight; 144 | 145 | T sqrt_hLeft; 146 | T sqrt_hRight; 147 | 148 | // reset net updates and the maximum wave speed 149 | o_hUpdateLeft = o_hUpdateRight = o_huUpdateLeft = o_huUpdateRight = T(0); 150 | o_maxWaveSpeed = (T)0; 151 | 152 | // HLLE middle height (Unused?) 153 | // T hMiddle = (T)0; 154 | 155 | /*************************************************************************************** 156 | * Determine Wet Dry State Begin 157 | * (determine the wet/dry state and compute local variables correspondingly) 158 | **************************************************************************************/ 159 | int wetDryState; 160 | // compute speeds or set them to zero (dry cells) 161 | if (hLeft >= dryTol) { 162 | uLeft = huLeft / hLeft; 163 | } else { 164 | bLeft += hLeft; 165 | hLeft = huLeft = uLeft = (T)0; 166 | } 167 | 168 | if (hRight >= dryTol) { 169 | uRight = huRight / hRight; 170 | } else { 171 | bRight += hRight; 172 | hRight = huRight = uRight = (T)0; 173 | } 174 | 175 | // MB: determine wet/dry-state - try to start with most frequent case 176 | if (hLeft >= dryTol) { 177 | if (hRight >= dryTol) { 178 | // simple wet/wet case - expected as most frequently executed branch 179 | wetDryState = WetWet; 180 | } else { // hLeft >= dryTol and hRight < dryTol 181 | // we have a shoreline: left cell wet, right cell dry 182 | //=>check for simple inundation problems 183 | if (hLeft + bLeft > bRight) { 184 | // => dry cell lies lower than the wet cell 185 | wetDryState = WetDryInundation; 186 | } else { // hLeft >= dryTol and hRight < dryTol and hLeft + bLeft <= bRight 187 | // =>dry cell (right) lies higher than the wet cell (left) 188 | // Removed middle state computation -> assuming momentum is never high enough to overcome boundary on its 189 | // own 190 | hRight = hLeft; 191 | uRight = -uLeft; 192 | huRight = -huLeft; 193 | bRight = bLeft = (T)0; 194 | wetDryState = WetDryWall; 195 | } 196 | } 197 | } else { // hLeft < dryTol 198 | if (hRight >= dryTol) { 199 | // we have a shoreline: left cell dry, right cell wet 200 | //=>check for simple inundation problems 201 | if (hRight + bRight > bLeft) { 202 | // => dry cell lies lower than the wet cell 203 | wetDryState = DryWetInundation; 204 | } else { // hLeft < dryTol and hRight >= dryTol and hRight + bRight <= bLeft 205 | // =>dry cell (left) lies higher than the wet cell (right) 206 | // Removed middle state computation -> assuming momentum is never high enough to overcome boundary on its 207 | // own 208 | hLeft = hRight; 209 | uLeft = -uRight; 210 | huLeft = -huRight; 211 | bLeft = bRight = (T)0; 212 | wetDryState = DryWetWall; 213 | } 214 | } else { // hLeft < dryTol and hRight < dryTol 215 | wetDryState = DryDry; 216 | // nothing to do for dry/dry case, all netUpdates and maxWaveSpeed are 0 217 | #ifdef VECTORIZE // Vectorization fails with branching return statement. Let computation resume with dummy values 218 | // instead. 219 | hLeft = hRight = dryTol; 220 | uLeft = uRight = (T)0; 221 | huLeft = huRight = (T)0; 222 | bLeft = bRight = (T)0; 223 | #else 224 | return; 225 | #endif 226 | } 227 | }; 228 | 229 | /*************************************************************************************** 230 | * Determine Wet Dry State End 231 | **************************************************************************************/ 232 | // MB: not executed for DryDry => returns right after case is identified 233 | // assert(wetDryState != DryDry); 234 | 235 | // precompute some terms which are fixed during 236 | // the computation after some specific point 237 | sqrt_hLeft = std::sqrt(hLeft); 238 | sqrt_hRight = std::sqrt(hRight); 239 | 240 | sqrt_g_hLeft = sqrt_g * sqrt_hLeft; 241 | sqrt_g_hRight = sqrt_g * sqrt_hRight; 242 | 243 | // compute the augmented decomposition 244 | // (thats the place where the computational work is done..) 245 | /*************************************************************************************** 246 | * Compute Wave Decomposition Begin 247 | **************************************************************************************/ 248 | // compute eigenvalues of the jacobian matrices in states Q_{i-1} and Q_{i} (char. speeds) 249 | const T characteristicSpeeds[2] = {uLeft - sqrt_g_hLeft, uRight + sqrt_g_hRight}; 250 | 251 | // compute "Roe speeds" 252 | const T hRoe = (T)0.5 * (hRight + hLeft); 253 | const T uRoe = (uLeft * sqrt_hLeft + uRight * sqrt_hRight) / (sqrt_hLeft + sqrt_hRight); 254 | 255 | // optimization for dumb compilers 256 | const T sqrt_g_hRoe = sqrt_g * std::sqrt(hRoe); 257 | const T roeSpeeds[2] = {uRoe - sqrt_g_hRoe, uRoe + sqrt_g_hRoe}; 258 | 259 | // middle state computation removed, using basic Einfeldt speeds 260 | 261 | T extEinfeldtSpeeds[2] = {(T)0, (T)0}; 262 | if (wetDryState == WetWet || wetDryState == WetDryWall || wetDryState == DryWetWall) { 263 | extEinfeldtSpeeds[0] = MIN(characteristicSpeeds[0], roeSpeeds[0]); 264 | 265 | extEinfeldtSpeeds[1] = MAX(characteristicSpeeds[1], roeSpeeds[1]); 266 | } else if (hLeft < dryTol) { // MB: !!! cases DryWetInundation, DryWetWallInundation 267 | // ignore undefined speeds 268 | extEinfeldtSpeeds[0] = roeSpeeds[0]; 269 | extEinfeldtSpeeds[1] = MAX(characteristicSpeeds[1], roeSpeeds[1]); 270 | 271 | } else if (hRight < dryTol) { // MB: !!! cases WetDryInundation, WetDryWallInundation 272 | // ignore undefined speeds 273 | extEinfeldtSpeeds[0] = MIN(characteristicSpeeds[0], roeSpeeds[0]); 274 | extEinfeldtSpeeds[1] = roeSpeeds[1]; 275 | 276 | } else { 277 | // This case corresponds to the early return statement above. Should only be executed with vectorization enabled. 278 | #ifdef VECTORIZE 279 | extEinfeldtSpeeds[0] = (T)0; 280 | extEinfeldtSpeeds[1] = (T)1; 281 | #else 282 | assert(false); 283 | #endif 284 | } 285 | 286 | // HLL middle state 287 | // \cite[theorem 3.1]{george2006finite}, \cite[ch. 4.1]{george2008augmented} 288 | const T hLLMiddleHeight = MAX( 289 | (huLeft - huRight + extEinfeldtSpeeds[1] * hRight - extEinfeldtSpeeds[0] * hLeft 290 | ) / (extEinfeldtSpeeds[1] - extEinfeldtSpeeds[0]), 291 | (T)0 292 | ); 293 | 294 | // define eigenvalues 295 | const T eigenValues[3] = { 296 | extEinfeldtSpeeds[0], (T)0.5 * (extEinfeldtSpeeds[0] + extEinfeldtSpeeds[1]), extEinfeldtSpeeds[1]}; 297 | 298 | // define eigenvectors 299 | // MB: no longer used as system matrix 300 | // -> but still used to compute f-waves 301 | const T eigenVectors[3][3] = { 302 | {(T)1, (T)0, (T)1}, 303 | {eigenValues[0], (T)0, eigenValues[2]}, 304 | {eigenValues[0] * eigenValues[0], (T)1, eigenValues[2] * eigenValues[2]}}; 305 | 306 | // compute the jump in state 307 | T rightHandSide[3] = { 308 | hRight - hLeft, 309 | huRight - huLeft, 310 | (huRight * uRight + half_g * hRight * hRight) - (huLeft * uLeft + half_g * hLeft * hLeft)}; 311 | 312 | // compute steady state wave 313 | // \cite[ch. 4.2.1 \& app. A]{george2008augmented}, \cite[ch. 6.2 \& ch. 4.4]{george2006finite} 314 | T steadyStateWave[2] = {-(bRight - bLeft), -half_g * (hLeft + hRight) * (bRight - bLeft)}; 315 | 316 | // preserve depth-positivity 317 | // \cite[ch. 6.5.2]{george2006finite}, \cite[ch. 4.2.3]{george2008augmented} 318 | if (eigenValues[0] < -zeroTol && eigenValues[2] > zeroTol) { 319 | // subsonic 320 | steadyStateWave[0] = MAX( 321 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[0] 322 | ); 323 | steadyStateWave[0] = MIN( 324 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[2] 325 | ); 326 | } else if (eigenValues[0] > zeroTol) { 327 | // supersonic right TODO: motivation? 328 | steadyStateWave[0] = MAX(steadyStateWave[0], -hLeft); 329 | steadyStateWave[0] = MIN( 330 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[0] 331 | ); 332 | } else if (eigenValues[2] < -zeroTol) { 333 | // supersonic left TODO: motivation? 334 | steadyStateWave[0] = MAX( 335 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[2] 336 | ); 337 | steadyStateWave[0] = MIN(steadyStateWave[0], hRight); 338 | } 339 | // Limit the effect of the source term 340 | // \cite[ch. 6.4.2]{george2006finite} 341 | steadyStateWave[1] = MIN(steadyStateWave[1], g * MAX(-hLeft * (bRight - bLeft), -hRight * (bRight - bLeft))); 342 | steadyStateWave[1] = MAX(steadyStateWave[1], g * MIN(-hLeft * (bRight - bLeft), -hRight * (bRight - bLeft))); 343 | 344 | rightHandSide[0] -= steadyStateWave[0]; 345 | // rightHandSide[1]: no source term 346 | rightHandSide[2] -= steadyStateWave[1]; 347 | 348 | // everything is ready, solve the equations! 349 | /*************************************************************************************** 350 | * Solve linear equation begin 351 | **************************************************************************************/ 352 | 353 | // direct solution of specific 3x3 system: 354 | // ( 1 0 1 ) ( beta[0] ) = ( rightHandSide[0] ) 355 | // ( eigenValues[0] 0 eigenValues[2] ) ( beta[1] ) ( rightHandSide[1] ) 356 | // ( eigenValues[0]^2 1 eigenValues[2]^2 ) ( beta[2] ) ( rightHandSide[2] ) 357 | 358 | // step 1: solve the following 2x2 system (1st and 3rd column): 359 | // ( 1 1 ) ( beta[0] ) = ( rightHandSide[0] ) 360 | // ( eigenValues[0] eigenValues[2] ) ( beta[2] ) ( rightHandSide[1] ) 361 | 362 | // compute the inverse of the wave speed difference: 363 | T inverseDiff = (T)1 / (eigenValues[2] - eigenValues[0]); // 2 FLOPs (1 div) 364 | // compute f-waves: 365 | T beta[3]; 366 | beta[0] = (eigenValues[2] * rightHandSide[0] - rightHandSide[1]) * inverseDiff; // 3 FLOPs 367 | beta[2] = (-eigenValues[0] * rightHandSide[0] + rightHandSide[1]) * inverseDiff; // 3 FLOPs 368 | 369 | // step 2: solve 3rd row for beta[1]: 370 | beta[1] = rightHandSide[2] - eigenValues[0] * eigenValues[0] * beta[0] - eigenValues[2] * eigenValues[2] * beta[2]; 371 | 372 | #ifdef false 373 | // compute inverse of 3x3 matrix 374 | // MB: !!!AVOID COMPUTATION of inverse => see above for better solution for simple matrix 375 | // MB: TODO -> different choice of matrix in AugRie.hpp -> requires a separate solution procedure 376 | const T m[3][3] = { 377 | {(eigenVectors[1][1] * eigenVectors[2][2] - eigenVectors[1][2] * eigenVectors[2][1]), 378 | -(eigenVectors[0][1] * eigenVectors[2][2] - eigenVectors[0][2] * eigenVectors[2][1]), 379 | (eigenVectors[0][1] * eigenVectors[1][2] - eigenVectors[0][2] * eigenVectors[1][1])}, 380 | {-(eigenVectors[1][0] * eigenVectors[2][2] - eigenVectors[1][2] * eigenVectors[2][0]), 381 | (eigenVectors[0][0] * eigenVectors[2][2] - eigenVectors[0][2] * eigenVectors[2][0]), 382 | -(eigenVectors[0][0] * eigenVectors[1][2] - eigenVectors[0][2] * eigenVectors[1][0])}, 383 | {(eigenVectors[1][0] * eigenVectors[2][1] - eigenVectors[1][1] * eigenVectors[2][0]), 384 | -(eigenVectors[0][0] * eigenVectors[2][1] - eigenVectors[0][1] * eigenVectors[2][0]), 385 | (eigenVectors[0][0] * eigenVectors[1][1] - eigenVectors[0][1] * eigenVectors[1][0])}}; 386 | const T d = (eigenVectors[0][0] * m[0][0] + eigenVectors[0][1] * m[1][0] + eigenVectors[0][2] * m[2][0]); 387 | 388 | // m stores not really the inverse matrix, but the inverse multiplied by d 389 | const T s = 1 / d; 390 | 391 | // compute m*rightHandSide 392 | const T beta[3] = { 393 | (m[0][0] * rightHandSide[0] + m[0][1] * rightHandSide[1] + m[0][2] * rightHandSide[2]) * s, 394 | (m[1][0] * rightHandSide[0] + m[1][1] * rightHandSide[1] + m[1][2] * rightHandSide[2]) * s, 395 | (m[2][0] * rightHandSide[0] + m[2][1] * rightHandSide[1] + m[2][2] * rightHandSide[2]) * s}; 396 | #endif 397 | 398 | /*************************************************************************************** 399 | * Solve linear equation end 400 | **************************************************************************************/ 401 | 402 | // compute f-waves and wave-speeds 403 | T fWaves[3][2]; // array to store the three f-wave vectors (2 components each) 404 | T waveSpeeds[3]; // and vector to their speeds 405 | 406 | if (wetDryState == WetDryWall) { 407 | // zero ghost updates (wall boundary) 408 | // care about the left going wave (0) only 409 | fWaves[0][0] = beta[0] * eigenVectors[1][0]; 410 | fWaves[0][1] = beta[0] * eigenVectors[2][0]; 411 | 412 | // set the rest to zero 413 | fWaves[1][0] = fWaves[1][1] = (T)0; 414 | fWaves[2][0] = fWaves[2][1] = (T)0; 415 | 416 | waveSpeeds[0] = eigenValues[0]; 417 | waveSpeeds[1] = waveSpeeds[2] = (T)0; 418 | 419 | assert(eigenValues[0] < zeroTol); 420 | } else if (wetDryState == DryWetWall) { 421 | // zero ghost updates (wall boundary) 422 | // care about the right going wave (2) only 423 | fWaves[2][0] = beta[2] * eigenVectors[1][2]; 424 | fWaves[2][1] = beta[2] * eigenVectors[2][2]; 425 | 426 | // set the rest to zero 427 | fWaves[0][0] = fWaves[0][1] = (T)0; 428 | fWaves[1][0] = fWaves[1][1] = (T)0; 429 | 430 | waveSpeeds[2] = eigenValues[2]; 431 | waveSpeeds[0] = waveSpeeds[1] = (T)0; 432 | 433 | assert(eigenValues[2] > -zeroTol); 434 | } else { 435 | // compute f-waves (default) 436 | // loop manually unrolled for vectorization testing 437 | /* 438 | for (int waveNumber = 0; waveNumber < 3; waveNumber++) { 439 | fWaves[waveNumber][0] = beta[waveNumber] * eigenVectors[1][waveNumber]; //select 2nd and 440 | fWaves[waveNumber][1] = beta[waveNumber] * eigenVectors[2][waveNumber]; //3rd component of the augmented 441 | decomposition 442 | } 443 | */ 444 | 445 | fWaves[0][0] = beta[0] * eigenVectors[1][0]; 446 | fWaves[0][1] = beta[0] * eigenVectors[2][0]; 447 | 448 | fWaves[1][0] = beta[1] * eigenVectors[1][1]; 449 | fWaves[1][1] = beta[1] * eigenVectors[2][1]; 450 | 451 | fWaves[2][0] = beta[2] * eigenVectors[1][2]; 452 | fWaves[2][1] = beta[2] * eigenVectors[2][2]; 453 | 454 | waveSpeeds[0] = eigenValues[0]; 455 | waveSpeeds[1] = eigenValues[1]; 456 | waveSpeeds[2] = eigenValues[2]; 457 | } 458 | /*************************************************************************************** 459 | * Compute Wave Decomposition End 460 | **************************************************************************************/ 461 | 462 | #ifdef VECTORIZE 463 | // DryDry state with dummy data only reaches this point with vectorization enabled. 464 | // Return values are not updated in that case, since nothing happens in those cells. 465 | if (wetDryState != DryDry) { 466 | #endif 467 | // compute the updates from the three propagating waves 468 | // A^-\delta Q = \sum{s[i]<0} \beta[i] * r[i] = A^-\delta Q = \sum{s[i]<0} Z^i 469 | // A^+\delta Q = \sum{s[i]>0} \beta[i] * r[i] = A^-\delta Q = \sum{s[i]<0} Z^i 470 | 471 | // loop manually unrolled for vectorization testing 472 | /* 473 | for (int waveNumber = 0; waveNumber < 3; waveNumber++) { 474 | if (waveSpeeds[waveNumber] < -zeroTol) { 475 | //left going 476 | o_hUpdateLeft += fWaves[waveNumber][0]; 477 | o_huUpdateLeft += fWaves[waveNumber][1]; 478 | } else if (waveSpeeds[waveNumber] > zeroTol) { 479 | //right going 480 | o_hUpdateRight += fWaves[waveNumber][0]; 481 | o_huUpdateRight += fWaves[waveNumber][1]; 482 | } else { 483 | //TODO: this case should not happen mathematically, but it does. Where is the bug? Machine accuracy 484 | only? 485 | // MB: >>> waveSpeeds set to 0 for cases WetDryWall and DryWetWall 486 | o_hUpdateLeft += (T)0.5 * fWaves[waveNumber][0]; 487 | o_huUpdateLeft += (T)0.5 * fWaves[waveNumber][1]; 488 | 489 | o_hUpdateRight += (T)0.5 * fWaves[waveNumber][0]; 490 | o_huUpdateRight += (T)0.5 * fWaves[waveNumber][1]; 491 | } 492 | } 493 | */ 494 | 495 | if (waveSpeeds[0] < -zeroTol) { 496 | // left going 497 | o_hUpdateLeft += fWaves[0][0]; 498 | o_huUpdateLeft += fWaves[0][1]; 499 | } else if (waveSpeeds[0] > zeroTol) { 500 | // right going 501 | o_hUpdateRight += fWaves[0][0]; 502 | o_huUpdateRight += fWaves[0][1]; 503 | } else { 504 | // TODO: this case should not happen mathematically, but it does. Where is the bug? Machine accuracy only? 505 | // MB: >>> waveSpeeds set to 0 for cases WetDryWall and DryWetWall 506 | o_hUpdateLeft += (T)0.5 * fWaves[0][0]; 507 | o_huUpdateLeft += (T)0.5 * fWaves[0][1]; 508 | 509 | o_hUpdateRight += (T)0.5 * fWaves[0][0]; 510 | o_huUpdateRight += (T)0.5 * fWaves[0][1]; 511 | } 512 | if (waveSpeeds[1] < -zeroTol) { 513 | // left going 514 | o_hUpdateLeft += fWaves[1][0]; 515 | o_huUpdateLeft += fWaves[1][1]; 516 | } else if (waveSpeeds[1] > zeroTol) { 517 | // right going 518 | o_hUpdateRight += fWaves[1][0]; 519 | o_huUpdateRight += fWaves[1][1]; 520 | } else { 521 | // TODO: this case should not happen mathematically, but it does. Where is the bug? Machine accuracy only? 522 | // MB: >>> waveSpeeds set to 0 for cases WetDryWall and DryWetWall 523 | o_hUpdateLeft += (T)0.5 * fWaves[1][0]; 524 | o_huUpdateLeft += (T)0.5 * fWaves[1][1]; 525 | 526 | o_hUpdateRight += (T)0.5 * fWaves[1][0]; 527 | o_huUpdateRight += (T)0.5 * fWaves[1][1]; 528 | } 529 | if (waveSpeeds[2] < -zeroTol) { 530 | // left going 531 | o_hUpdateLeft += fWaves[2][0]; 532 | o_huUpdateLeft += fWaves[2][1]; 533 | } else if (waveSpeeds[2] > zeroTol) { 534 | // right going 535 | o_hUpdateRight += fWaves[2][0]; 536 | o_huUpdateRight += fWaves[2][1]; 537 | } else { 538 | // TODO: this case should not happen mathematically, but it does. Where is the bug? Machine accuracy only? 539 | // MB: >>> waveSpeeds set to 0 for cases WetDryWall and DryWetWall 540 | o_hUpdateLeft += (T)0.5 * fWaves[2][0]; 541 | o_huUpdateLeft += (T)0.5 * fWaves[2][1]; 542 | 543 | o_hUpdateRight += (T)0.5 * fWaves[2][0]; 544 | o_huUpdateRight += (T)0.5 * fWaves[2][1]; 545 | } 546 | 547 | // compute maximum wave speed (-> CFL-condition) 548 | waveSpeeds[0] = std::abs(waveSpeeds[0]); 549 | waveSpeeds[1] = std::abs(waveSpeeds[1]); 550 | waveSpeeds[2] = std::abs(waveSpeeds[2]); 551 | 552 | o_maxWaveSpeed = MAX(MAX(waveSpeeds[0], waveSpeeds[1]), waveSpeeds[2]); 553 | #ifdef VECTORIZE 554 | } 555 | #endif 556 | } 557 | 558 | }; // end of class HLLEFun 559 | 560 | } // end of namespace solver 561 | 562 | #endif /* HLLE_FUN_HPP */ 563 | -------------------------------------------------------------------------------- /Source/AugRieCUDASolver.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * AugRie_CUDA.h 3 | * 4 | **** 5 | **** Approximate Augmented Riemann Solver for the Shallow Water Equations 6 | **** vectorized using SIMD-Extensions 7 | **** 8 | * 9 | * Created on: May 28, 2013 10 | * Last Update: Jul 14, 2013 11 | * 12 | **** 13 | * 14 | * Author: Alexander Breuer 15 | * Homepage: http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer 16 | * E-Mail: breuera AT in.tum.de 17 | * 18 | * Some optimizations: Martin Schreiber 19 | * Homepage: http://www5.in.tum.de/wiki/index.php/Martin_Schreiber 20 | * E-Mail: schreibm AT in.tum.de 21 | * 22 | * CUDA: Wolfgang Hölzl 23 | * E-Mail: hoelzlw AT in.tum.de 24 | * 25 | **** 26 | * 27 | * (Main) Literature: 28 | * 29 | * @phdthesis{george2006finite, 30 | * Author = {George, D.L.}, 31 | * Title = {Finite volume methods and adaptive refinement for tsunami propagation and inundation}, 32 | * Year = {2006}} 33 | * 34 | * @article{george2008augmented, 35 | * Author = {George, D.L.}, 36 | * Journal = {Journal of Computational Physics}, 37 | * Number = {6}, 38 | * Pages = {3089--3113}, 39 | * Publisher = {Elsevier}, 40 | * Title = {Augmented Riemann solvers for the shallow water equations over variable topography with steady 41 | *states and inundation}, Volume = {227}, Year = {2008}} 42 | * 43 | * @book{leveque2002finite, 44 | * Author = {LeVeque, R. J.}, 45 | * Date-Added = {2011-09-13 14:09:31 +0000}, 46 | * Date-Modified = {2011-10-31 09:46:40 +0000}, 47 | * Publisher = {Cambridge University Press}, 48 | * Title = {Finite Volume Methods for Hyperbolic Problems}, 49 | * Volume = {31}, 50 | * Year = {2002}} 51 | * 52 | * @webpage{levequeclawpack, 53 | * Author = {LeVeque, R. J.}, 54 | * Lastchecked = {January, 05, 2011}, 55 | * Title = {Clawpack Sofware}, 56 | * Url = {https://github.com/clawpack/clawpack-4.x/blob/master/geoclaw/2d/lib}} 57 | * 58 | **** 59 | * 60 | * Acknowledgments: 61 | * Special thanks go to R.J. LeVeque and D.L. George for publishing their code 62 | * and the corresponding documentation (-> Literature). 63 | */ 64 | 65 | /* 66 | * TODO: store nLow/nHigh variables in array[2] 67 | */ 68 | 69 | #ifndef AUGRIE_CUDA_HPP_ 70 | #define AUGRIE_CUDA_HPP_ 71 | 72 | #define FLOAT32 73 | 74 | #include 75 | #include 76 | #include 77 | #include 78 | #include 79 | 80 | #include "SIMD_TYPES.hpp" 81 | 82 | const integer DryDry = 0; 83 | const integer WetWet = 1; 84 | const integer WetDryInundation = 2; 85 | const integer WetDryWall = 3; 86 | const integer WetDryWallInundation = 4; 87 | const integer DryWetInundation = 5; 88 | const integer DryWetWall = 6; 89 | const integer DryWetWallInundation = 7; 90 | 91 | const integer DrySingleRarefaction = 0; 92 | const integer SingleRarefactionDry = 1; 93 | const integer ShockShock = 2; 94 | const integer ShockRarefaction = 3; 95 | const integer RarefactionShock = 4; 96 | const integer RarefactionRarefaction = 5; 97 | 98 | __device__ inline void computeMiddleState( 99 | const real& i_hLeft, 100 | const real& i_hRight, 101 | const real& i_uLeft, 102 | const real& i_uRight, 103 | const real dryTol, 104 | const real newtonTol, 105 | const real g, 106 | const real sqrt_g, 107 | const unsigned int& i_maxNumberOfNewtonIterations, 108 | real& o_hMiddle, 109 | real o_middleStateSpeeds[2] 110 | ); 111 | 112 | /** 113 | * Compute net updates for the left/right cell of the edge. 114 | * 115 | * maxWaveSpeed will be set to the maximum (linearized) wave speed => CFL 116 | */ 117 | __device__ void augRieComputeNetUpdates( 118 | const real i_hLeft, 119 | const real i_hRight, 120 | const real i_huLeft, 121 | const real i_huRight, 122 | const real i_bLeft, 123 | const real i_bRight, 124 | 125 | const real g, 126 | const real dryTol, 127 | const real newtonTol, 128 | const real zeroTol, 129 | const unsigned int maxNumberOfNewtonIterations, 130 | 131 | real o_netUpdates[5] 132 | ) { 133 | real hLeft = i_hLeft; 134 | real hRight = i_hRight; 135 | real uLeft = static_cast(0); 136 | real uRight = static_cast(0); 137 | real huLeft = i_huLeft; 138 | real huRight = i_huRight; 139 | real bLeft = i_bLeft; 140 | real bRight = i_bRight; 141 | 142 | // declare variables which are used over and over again 143 | const real sqrt_g = sqrtf(g); 144 | real sqrt_g_hLeft; 145 | real sqrt_g_hRight; 146 | 147 | real sqrt_hLeft; 148 | real sqrt_hRight; 149 | 150 | // set speeds to zero (will be determined later) 151 | uLeft = uRight = 0.; 152 | 153 | // reset net updates and the maximum wave speed 154 | o_netUpdates[0] = o_netUpdates[1] = o_netUpdates[2] = o_netUpdates[3] = static_cast(0); 155 | o_netUpdates[4] = static_cast(0); 156 | 157 | real hMiddle = static_cast(0); 158 | real middleStateSpeeds[2] = {static_cast(0)}; 159 | 160 | // determine the wet/dry state and compute local variables correspondingly 161 | 162 | /*************************************************************************************** 163 | * Determine Wet Dry State Begin 164 | **************************************************************************************/ 165 | integer wetDryState; 166 | // compute speeds or set them to zero (dry cells) 167 | if (hLeft > dryTol) { 168 | uLeft = huLeft / hLeft; 169 | } else { 170 | bLeft += hLeft; 171 | hLeft = huLeft = uLeft = 0; 172 | } 173 | 174 | if (hRight > dryTol) { 175 | uRight = huRight / hRight; 176 | } else { 177 | bRight += hRight; 178 | hRight = huRight = uRight = 0; 179 | } 180 | 181 | if (hLeft >= dryTol and hRight >= dryTol) { 182 | // test for simple wet/wet case since this is most probably the 183 | // most frequently executed branch 184 | wetDryState = WetWet; 185 | } else if (hLeft < dryTol and hRight < dryTol) { 186 | // check for the dry/dry-case 187 | wetDryState = DryDry; 188 | } else if (hLeft < dryTol and hRight + bRight > bLeft) { 189 | // we have a shoreline: one cell dry, one cell wet 190 | 191 | // check for simple inundation problems 192 | // (=> dry cell lies lower than the wet cell) 193 | wetDryState = DryWetInundation; 194 | } else if (hRight < dryTol and hLeft + bLeft > bRight) { 195 | wetDryState = WetDryInundation; 196 | } else if (hLeft < dryTol) { 197 | // dry cell lies higher than the wet cell 198 | // lets check if the momentum is able to overcome the difference in height 199 | // => solve homogeneous Riemann-problem to determine the middle state height 200 | // which would arise if there is a wall (wall-boundary-condition) 201 | // \cite[ch. 6.8.2]{george2006finite}) 202 | // \cite[ch. 5.2]{george2008augmented} 203 | computeMiddleState( 204 | hRight, 205 | hRight, 206 | -uRight, 207 | uRight, 208 | dryTol, 209 | newtonTol, 210 | g, 211 | sqrt_g, 212 | maxNumberOfNewtonIterations, 213 | hMiddle, 214 | middleStateSpeeds 215 | ); 216 | 217 | if (hMiddle + bRight > bLeft) { 218 | // momentum is large enough, continue with the original values 219 | // bLeft = o_hMiddle + bRight; 220 | wetDryState = DryWetWallInundation; 221 | } else { 222 | // momentum is not large enough, use wall-boundary-values 223 | hLeft = hRight; 224 | uLeft = -uRight; 225 | huLeft = -huRight; 226 | bLeft = bRight = static_cast(0); 227 | wetDryState = DryWetWall; 228 | } 229 | } else if (hRight < dryTol) { 230 | // lets check if the momentum is able to overcome the difference in height 231 | // => solve homogeneous Riemann-problem to determine the middle state height 232 | // which would arise if there is a wall (wall-boundary-condition) 233 | // \cite[ch. 6.8.2]{george2006finite}) 234 | // \cite[ch. 5.2]{george2008augmented} 235 | computeMiddleState( 236 | hLeft, hLeft, uLeft, -uLeft, dryTol, newtonTol, g, sqrt_g, maxNumberOfNewtonIterations, hMiddle, middleStateSpeeds 237 | ); 238 | 239 | if (hMiddle + bLeft > bRight) { 240 | // momentum is large enough, continue with the original values 241 | // bRight = o_hMiddle + bLeft; 242 | wetDryState = WetDryWallInundation; 243 | } else { 244 | hRight = hLeft; 245 | uRight = -uLeft; 246 | huRight = -huLeft; 247 | bRight = bLeft = static_cast(0); 248 | wetDryState = WetDryWall; 249 | } 250 | } else { 251 | // done with all cases 252 | assert(false); 253 | } 254 | 255 | // limit the effect of the source term if there is a "wall" 256 | //\cite[end of ch. 5.2?]{george2008augmented} 257 | //\cite[rpn2ez_fast_geo.f][levequeclawpack] 258 | if (wetDryState == DryWetWallInundation) { 259 | bLeft = hRight + bRight; 260 | } else if (wetDryState == WetDryWallInundation) { 261 | bRight = hLeft + bLeft; 262 | } 263 | /*************************************************************************************** 264 | * Determine Wet Dry State End 265 | **************************************************************************************/ 266 | 267 | if (wetDryState != DryDry) { 268 | // precompute some terms which are fixed during 269 | // the computation after some specific point 270 | sqrt_hLeft = std::sqrt(hLeft); 271 | sqrt_hRight = std::sqrt(hRight); 272 | 273 | sqrt_g_hLeft = sqrt_g * sqrt_hLeft; 274 | sqrt_g_hRight = sqrt_g * sqrt_hRight; 275 | 276 | // where to store the three waves 277 | real fWaves[3][2]; 278 | // and their speeds 279 | real waveSpeeds[3]; 280 | 281 | // compute the augmented decomposition 282 | // (thats the place where the computational work is done..) 283 | /*************************************************************************************** 284 | * Compute Wave Decomposition Begin 285 | **************************************************************************************/ 286 | // compute eigenvalues of the jacobian matrices in states Q_{i-1} and Q_{i} (char. speeds) 287 | const real characteristicSpeeds[2] = {uLeft - sqrt_g_hLeft, uRight + sqrt_g_hRight}; 288 | 289 | // compute "Roe speeds" 290 | const real hRoe = static_cast(0.5) * (hRight + hLeft); 291 | const real uRoe = (uLeft * sqrt_hLeft + uRight * sqrt_hRight) / (sqrt_hLeft + sqrt_hRight); 292 | 293 | // optimization for dumb compilers 294 | const real sqrt_g_hRoe = std::sqrt(g * hRoe); 295 | const real roeSpeeds[2] = {uRoe - sqrt_g_hRoe, uRoe + sqrt_g_hRoe}; 296 | 297 | // compute the middle state of the homogeneous Riemann-Problem 298 | if (wetDryState != WetDryWall and wetDryState != DryWetWall) { 299 | // case WDW and DWW was computed in determineWetDryState already 300 | computeMiddleState(hLeft, hRight, uLeft, uRight, dryTol, newtonTol, g, sqrt_g, 1, hMiddle, middleStateSpeeds); 301 | } 302 | 303 | // compute extended eindfeldt speeds (einfeldt speeds + middle state speeds) 304 | // \cite[ch. 5.2]{george2008augmented}, \cite[ch. 6.8]{george2006finite} 305 | real extEinfeldtSpeeds[2] = {static_cast(0), static_cast(0)}; 306 | if (wetDryState == WetWet or wetDryState == WetDryWall or wetDryState == DryWetWall) { 307 | extEinfeldtSpeeds[0] = fmin(characteristicSpeeds[0], roeSpeeds[0]); 308 | extEinfeldtSpeeds[0] = fmin(extEinfeldtSpeeds[0], middleStateSpeeds[1]); 309 | 310 | extEinfeldtSpeeds[1] = fmax(characteristicSpeeds[1], roeSpeeds[1]); 311 | extEinfeldtSpeeds[1] = fmax(extEinfeldtSpeeds[1], middleStateSpeeds[0]); 312 | } else if (hLeft < dryTol) { 313 | // ignore undefined speeds 314 | extEinfeldtSpeeds[0] = fmin(roeSpeeds[0], middleStateSpeeds[1]); 315 | extEinfeldtSpeeds[1] = fmax(characteristicSpeeds[1], roeSpeeds[1]); 316 | 317 | assert(middleStateSpeeds[0] < extEinfeldtSpeeds[1]); 318 | } else if (hRight < dryTol) { 319 | // ignore undefined speeds 320 | extEinfeldtSpeeds[0] = fmin(characteristicSpeeds[0], roeSpeeds[0]); 321 | extEinfeldtSpeeds[1] = fmax(roeSpeeds[1], middleStateSpeeds[0]); 322 | 323 | assert(middleStateSpeeds[1] > extEinfeldtSpeeds[0]); 324 | } else { 325 | assert(false); 326 | } 327 | 328 | // HLL middle state 329 | // \cite[theorem 3.1]{george2006finite}, \cite[ch. 4.1]{george2008augmented} 330 | const real hLLMiddleHeight = fmax( 331 | (huLeft - huRight + extEinfeldtSpeeds[1] * hRight - extEinfeldtSpeeds[0] * hLeft 332 | ) / (extEinfeldtSpeeds[1] - extEinfeldtSpeeds[0]), 333 | static_cast(0) 334 | ); 335 | 336 | // define eigenvalues 337 | const real eigenValues[3] = { 338 | extEinfeldtSpeeds[0], 339 | static_cast(0.5) * (extEinfeldtSpeeds[0] + extEinfeldtSpeeds[1]), 340 | extEinfeldtSpeeds[1]}; 341 | // define eigenvectors 342 | const real eigenVectors[3][3] = { 343 | {static_cast(1), static_cast(0), static_cast(1)}, 344 | {eigenValues[0], static_cast(0), eigenValues[2]}, 345 | {eigenValues[0] * eigenValues[0], static_cast(1), eigenValues[2] * eigenValues[2]}}; 346 | 347 | // compute rarefaction corrector wave 348 | // \cite[ch. 6.7.2]{george2006finite}, \cite[ch. 5.1]{george2008augmented} 349 | #pragma message \ 350 | "strongRarefaction set to false. Further investigations needed about senseless initialization of eigenValues[1]" 351 | 352 | // compute the jump in state 353 | real rightHandSide[3] = { 354 | hRight - hLeft, 355 | huRight - huLeft, 356 | huRight * uRight + static_cast(0.5) * g * hRight * hRight 357 | - (huLeft * uLeft + static_cast(0.5) * g * hLeft * hLeft)}; 358 | 359 | // compute steady state wave 360 | // \cite[ch. 4.2.1 \& app. A]{george2008augmented}, \cite[ch. 6.2 \& ch. 4.4]{george2006finite} 361 | const real hBar = (hLeft + hRight) * static_cast(0.5); 362 | 363 | real steadyStateWave[2] = {-(bRight - bLeft), -g * hBar * (bRight - bLeft)}; 364 | 365 | // preserve depth-positivity 366 | // \cite[ch. 6.5.2]{george2006finite}, \cite[ch. 4.2.3]{george2008augmented} 367 | if (eigenValues[0] < -zeroTol and eigenValues[2] > zeroTol) { 368 | // subsonic 369 | steadyStateWave[0] = fmax( 370 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[0] 371 | ); 372 | steadyStateWave[0] = fmin( 373 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[2] 374 | ); 375 | } else if (eigenValues[0] > zeroTol) { 376 | // supersonic right TODO: motivation? 377 | steadyStateWave[0] = fmax(steadyStateWave[0], -hLeft); 378 | steadyStateWave[0] = fmin( 379 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[0] 380 | ); 381 | } else if (eigenValues[2] < -zeroTol) { 382 | // supersonic left TODO: motivation? 383 | steadyStateWave[0] = fmax( 384 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[2] 385 | ); 386 | steadyStateWave[0] = fmin(steadyStateWave[0], hRight); 387 | } 388 | 389 | // Limit the effect of the source term 390 | // \cite[ch. 6.4.2]{george2006finite} 391 | steadyStateWave[1] = fmin(steadyStateWave[1], g * fmax(-hLeft * (bRight - bLeft), -hRight * (bRight - bLeft))); 392 | steadyStateWave[1] = fmax(steadyStateWave[1], g * fmin(-hLeft * (bRight - bLeft), -hRight * (bRight - bLeft))); 393 | 394 | rightHandSide[0] -= steadyStateWave[0]; 395 | // rightHandSide[1]: no source term 396 | rightHandSide[2] -= steadyStateWave[1]; 397 | 398 | // everything is ready, solve the equations! 399 | /*************************************************************************************** 400 | * Solve linear equation begin 401 | **************************************************************************************/ 402 | // compute inverse of 3x3 matrix 403 | const real m[3][3] = { 404 | {(eigenVectors[1][1] * eigenVectors[2][2] - eigenVectors[1][2] * eigenVectors[2][1]), 405 | -(eigenVectors[0][1] * eigenVectors[2][2] - eigenVectors[0][2] * eigenVectors[2][1]), 406 | (eigenVectors[0][1] * eigenVectors[1][2] - eigenVectors[0][2] * eigenVectors[1][1])}, 407 | {-(eigenVectors[1][0] * eigenVectors[2][2] - eigenVectors[1][2] * eigenVectors[2][0]), 408 | (eigenVectors[0][0] * eigenVectors[2][2] - eigenVectors[0][2] * eigenVectors[2][0]), 409 | -(eigenVectors[0][0] * eigenVectors[1][2] - eigenVectors[0][2] * eigenVectors[1][0])}, 410 | {(eigenVectors[1][0] * eigenVectors[2][1] - eigenVectors[1][1] * eigenVectors[2][0]), 411 | -(eigenVectors[0][0] * eigenVectors[2][1] - eigenVectors[0][1] * eigenVectors[2][0]), 412 | (eigenVectors[0][0] * eigenVectors[1][1] - eigenVectors[0][1] * eigenVectors[1][0])}}; 413 | const real d = (eigenVectors[0][0] * m[0][0] + eigenVectors[0][1] * m[1][0] + eigenVectors[0][2] * m[2][0]); 414 | 415 | // m stores not really the inverse matrix, but the inverse multiplied by d 416 | const real s = 1 / d; 417 | 418 | // compute m*rightHandSide 419 | const real beta[3] = { 420 | (m[0][0] * rightHandSide[0] + m[0][1] * rightHandSide[1] + m[0][2] * rightHandSide[2]) * s, 421 | (m[1][0] * rightHandSide[0] + m[1][1] * rightHandSide[1] + m[1][2] * rightHandSide[2]) * s, 422 | (m[2][0] * rightHandSide[0] + m[2][1] * rightHandSide[1] + m[2][2] * rightHandSide[2]) * s}; 423 | /*************************************************************************************** 424 | * Solve linear equation end 425 | **************************************************************************************/ 426 | 427 | // compute f-waves and wave-speeds 428 | if (wetDryState == WetDryWall) { 429 | // zero ghost updates (wall boundary) 430 | // care about the left going wave (0) only 431 | fWaves[0][0] = beta[0] * eigenVectors[1][0]; 432 | fWaves[0][1] = beta[0] * eigenVectors[2][0]; 433 | 434 | // set the rest to zero 435 | fWaves[1][0] = fWaves[1][1] = static_cast(0); 436 | fWaves[2][0] = fWaves[2][1] = static_cast(0); 437 | 438 | waveSpeeds[0] = eigenValues[0]; 439 | waveSpeeds[1] = waveSpeeds[2] = static_cast(0); 440 | 441 | assert(eigenValues[0] < zeroTol); 442 | } else if (wetDryState == DryWetWall) { 443 | // zero ghost updates (wall boundary) 444 | // care about the right going wave (2) only 445 | fWaves[2][0] = beta[2] * eigenVectors[1][2]; 446 | fWaves[2][1] = beta[2] * eigenVectors[2][2]; 447 | 448 | // set the rest to zero 449 | fWaves[0][0] = fWaves[0][1] = static_cast(0); 450 | fWaves[1][0] = fWaves[1][1] = static_cast(0); 451 | 452 | waveSpeeds[2] = eigenValues[2]; 453 | waveSpeeds[0] = waveSpeeds[1] = static_cast(0); 454 | 455 | assert(eigenValues[2] > -zeroTol); 456 | } else { 457 | // compute f-waves (default) 458 | for (int waveNumber = 0; waveNumber < 3; waveNumber++) { 459 | fWaves[waveNumber][0] = beta[waveNumber] * eigenVectors[1][waveNumber]; // select 2nd and 460 | fWaves[waveNumber][1] = beta[waveNumber] * eigenVectors[2][waveNumber]; // 3rd component of the augmented 461 | // decomposition 462 | } 463 | 464 | waveSpeeds[0] = eigenValues[0]; 465 | waveSpeeds[1] = eigenValues[1]; 466 | waveSpeeds[2] = eigenValues[2]; 467 | } 468 | /*************************************************************************************** 469 | * Compute Wave Decomposition End 470 | **************************************************************************************/ 471 | 472 | // compute the updates from the three propagating waves 473 | // A^-\delta Q = \sum{s[i]<0} \beta[i] * r[i] = A^-\delta Q = \sum{s[i]<0} Z^i 474 | // A^+\delta Q = \sum{s[i]>0} \beta[i] * r[i] = A^-\delta Q = \sum{s[i]<0} Z^i 475 | for (int waveNumber = 0; waveNumber < 3; waveNumber++) { 476 | if (waveSpeeds[waveNumber] < -zeroTol) { 477 | // left going 478 | o_netUpdates[0] += fWaves[waveNumber][0]; 479 | o_netUpdates[2] += fWaves[waveNumber][1]; 480 | } else if (waveSpeeds[waveNumber] > zeroTol) { 481 | // right going 482 | o_netUpdates[1] += fWaves[waveNumber][0]; 483 | o_netUpdates[3] += fWaves[waveNumber][1]; 484 | } else { 485 | // TODO: this case should not happen mathematically, but it does. Where is the bug? Machine accuracy only? 486 | o_netUpdates[0] += static_cast(0.5) * fWaves[waveNumber][0]; 487 | o_netUpdates[2] += static_cast(0.5) * fWaves[waveNumber][1]; 488 | 489 | o_netUpdates[1] += static_cast(0.5) * fWaves[waveNumber][0]; 490 | o_netUpdates[3] += static_cast(0.5) * fWaves[waveNumber][1]; 491 | } 492 | } 493 | 494 | // compute maximum wave speed (-> CFL-condition) 495 | waveSpeeds[0] = fabs(waveSpeeds[0]); 496 | waveSpeeds[1] = fabs(waveSpeeds[1]); 497 | waveSpeeds[2] = fabs(waveSpeeds[2]); 498 | 499 | o_netUpdates[4] = fmax(waveSpeeds[0], waveSpeeds[1]); 500 | o_netUpdates[4] = fmax(o_netUpdates[4], waveSpeeds[2]); 501 | } 502 | } 503 | 504 | /** 505 | * Computes the middle state of the homogeneous Riemann-problem. 506 | * -> (\cite[ch. 13]{leveque2002finite}) 507 | * 508 | * @param i_hLeft height on the left side of the edge. 509 | * @param i_hRight height on the right side of the edge. 510 | * @param i_uLeft velocity on the left side of the edge. 511 | * @param i_uRight velocity on the right side of the edge. 512 | * @param i_huLeft momentum on the left side of the edge. 513 | * @param i_huRight momentum on the right side of the edge. 514 | * @param i_maxNumberOfNewtonIterations maximum number of Newton iterations. 515 | */ 516 | __device__ inline void computeMiddleState( 517 | const real& i_hLeft, 518 | const real& i_hRight, 519 | const real& i_uLeft, 520 | const real& i_uRight, 521 | const real dryTol, 522 | const real newtonTol, 523 | const real g, 524 | const real sqrt_g, 525 | const unsigned int& i_maxNumberOfNewtonIterations, 526 | real& o_hMiddle, 527 | real o_middleStateSpeeds[2] 528 | ) { 529 | // set everything to zero 530 | o_hMiddle = static_cast(0); 531 | o_middleStateSpeeds[0] = static_cast(0); 532 | o_middleStateSpeeds[1] = static_cast(0); 533 | 534 | // compute local square roots 535 | //(not necessarily the same ones as in computeNetUpdates!) 536 | real l_sqrt_g_hRight = std::sqrt(g * i_hRight); 537 | real l_sqrt_g_hLeft = std::sqrt(g * i_hLeft); 538 | 539 | // single rarefaction in the case of a wet/dry interface 540 | integer riemannStructure; 541 | if (i_hLeft < dryTol) { 542 | o_middleStateSpeeds[1] = o_middleStateSpeeds[0] = i_uRight - static_cast(2) * l_sqrt_g_hRight; 543 | riemannStructure = DrySingleRarefaction; 544 | return; 545 | } else if (i_hRight < dryTol) { 546 | o_middleStateSpeeds[0] = o_middleStateSpeeds[1] = i_uLeft + static_cast(2) * l_sqrt_g_hLeft; 547 | riemannStructure = SingleRarefactionDry; 548 | return; 549 | } 550 | 551 | // determine the wave structure of the Riemann-problem 552 | /*************************************************************************************** 553 | * Determine riemann structure begin 554 | **************************************************************************************/ 555 | const real hMin = fmin(i_hLeft, i_hRight); 556 | const real hMax = fmax(i_hLeft, i_hRight); 557 | 558 | const real uDif = i_uRight - i_uLeft; 559 | 560 | if (0 <= static_cast(2) * (std::sqrt(g * hMin) - std::sqrt(g * hMax)) + uDif) { 561 | riemannStructure = RarefactionRarefaction; 562 | } else if ((hMax - hMin) * std::sqrt(g * static_cast(0.5) * (1 / hMax + 1 / hMin)) + uDif <= 0) { 563 | riemannStructure = ShockShock; 564 | } else if (i_hLeft < i_hRight) { 565 | riemannStructure = ShockRarefaction; 566 | } else { 567 | riemannStructure = RarefactionShock; 568 | } 569 | /*************************************************************************************** 570 | * Determine riemann structure end 571 | **************************************************************************************/ 572 | 573 | // will be computed later 574 | real sqrt_g_hMiddle = static_cast(0); 575 | 576 | if (riemannStructure == ShockShock) { 577 | o_hMiddle = fmin(i_hLeft, i_hRight); 578 | 579 | real l_sqrtTermH[2] = {0, 0}; 580 | 581 | for (unsigned int i = 0; i < i_maxNumberOfNewtonIterations; i++) { 582 | l_sqrtTermH[0] = std::sqrt(static_cast(0.5) * g * ((o_hMiddle + i_hLeft) / (o_hMiddle * i_hLeft))); 583 | l_sqrtTermH[1] = std::sqrt(static_cast(0.5) * g * ((o_hMiddle + i_hRight) / (o_hMiddle * i_hRight))); 584 | 585 | real phi = i_uRight - i_uLeft + (o_hMiddle - i_hLeft) * l_sqrtTermH[0] + (o_hMiddle - i_hRight) * l_sqrtTermH[1]; 586 | 587 | if (std::fabs(phi) < newtonTol) { 588 | break; 589 | } 590 | 591 | real derivativePhi = l_sqrtTermH[0] + l_sqrtTermH[1] 592 | - static_cast(0.25) * g * (o_hMiddle - i_hLeft) 593 | / (l_sqrtTermH[0] * o_hMiddle * o_hMiddle) 594 | - static_cast(0.25) * g * (o_hMiddle - i_hRight) 595 | / (l_sqrtTermH[1] * o_hMiddle * o_hMiddle); 596 | 597 | o_hMiddle = o_hMiddle - phi / derivativePhi; // Newton step 598 | assert(o_hMiddle >= dryTol); 599 | } 600 | 601 | sqrt_g_hMiddle = std::sqrt(g * o_hMiddle); 602 | } 603 | 604 | if (riemannStructure == RarefactionRarefaction) { 605 | o_hMiddle = fmax( 606 | static_cast(0), i_uLeft - i_uRight + static_cast(2) * (l_sqrt_g_hLeft + l_sqrt_g_hRight) 607 | ); 608 | o_hMiddle = static_cast(1) / (static_cast(16) * g) * o_hMiddle * o_hMiddle; 609 | 610 | sqrt_g_hMiddle = std::sqrt(g * o_hMiddle); 611 | } 612 | 613 | if (riemannStructure == ShockRarefaction or riemannStructure == RarefactionShock) { 614 | real hMin, hMax; 615 | if (riemannStructure == ShockRarefaction) { 616 | hMin = i_hLeft; 617 | hMax = i_hRight; 618 | } else { 619 | hMin = i_hRight; 620 | hMax = i_hLeft; 621 | } 622 | 623 | o_hMiddle = hMin; 624 | 625 | sqrt_g_hMiddle = std::sqrt(g * o_hMiddle); 626 | real sqrt_g_hMax = std::sqrt(g * hMax); 627 | for (unsigned int i = 0; i < i_maxNumberOfNewtonIterations; i++) { 628 | real sqrtTermHMin = std::sqrt(static_cast(0.5) * g * ((o_hMiddle + hMin) / (o_hMiddle * hMin))); 629 | 630 | real phi = i_uRight - i_uLeft + (o_hMiddle - hMin) * sqrtTermHMin 631 | + static_cast(2) * (sqrt_g_hMiddle - sqrt_g_hMax); 632 | 633 | if (std::fabs(phi) < newtonTol) { 634 | break; 635 | } 636 | 637 | real derivativePhi = sqrtTermHMin 638 | - static_cast(0.25) * g * (o_hMiddle - hMin) / (o_hMiddle * o_hMiddle * sqrtTermHMin) 639 | + sqrt_g / sqrt_g_hMiddle; 640 | 641 | o_hMiddle = o_hMiddle - phi / derivativePhi; // Newton step 642 | 643 | sqrt_g_hMiddle = std::sqrt(g * o_hMiddle); 644 | } 645 | } 646 | 647 | o_middleStateSpeeds[0] = i_uLeft + static_cast(2) * l_sqrt_g_hLeft - static_cast(3) * sqrt_g_hMiddle; 648 | o_middleStateSpeeds[1] = i_uRight - static_cast(2) * l_sqrt_g_hRight + static_cast(3) * sqrt_g_hMiddle; 649 | 650 | assert(o_hMiddle >= 0); 651 | } 652 | 653 | #endif /* AUGRIE_CUDA_HPP_ */ 654 | -------------------------------------------------------------------------------- /Source/AugRieFunSolver.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * AugRieFun.hpp 3 | * 4 | **** 5 | **** Approximate Augmented Riemann Solver for the Shallow Water Equations 6 | **** functional implementation (based on AugRieCUDA) 7 | **** 8 | * 9 | * Created on: May 28, 2013 10 | * Last Update: Jan 1, 2014 11 | * 12 | **** 13 | * 14 | * Author: Alexander Breuer 15 | * Homepage: http://www5.in.tum.de/wiki/index.php/Dipl.-Math._Alexander_Breuer 16 | * E-Mail: breuera AT in.tum.de 17 | * 18 | * Some optimizations: Martin Schreiber 19 | * Homepage: http://www5.in.tum.de/wiki/index.php/Martin_Schreiber 20 | * E-Mail: schreibm AT in.tum.de 21 | * 22 | * CUDA: Wolfgang Hölzl 23 | * E-Mail: hoelzlw AT in.tum.de 24 | * 25 | * Further optimizations: Michael Bader 26 | * Homepage: http://www5.in.tum.de/wiki/index.php/Michael_Bader 27 | * E-Mail: bader AT in.tum.de 28 | * 29 | **** 30 | * 31 | * (Main) Literature: 32 | * 33 | * @phdthesis{george2006finite, 34 | * Author = {George, D.L.}, 35 | * Title = {Finite volume methods and adaptive refinement for tsunami propagation and inundation}, 36 | * Year = {2006}} 37 | * 38 | * @article{george2008augmented, 39 | * Author = {George, D.L.}, 40 | * Journal = {Journal of Computational Physics}, 41 | * Number = {6}, 42 | * Pages = {3089--3113}, 43 | * Publisher = {Elsevier}, 44 | * Title = {Augmented Riemann solvers for the shallow water equations over variable topography with steady 45 | *states and inundation}, Volume = {227}, Year = {2008}} 46 | * 47 | * @book{leveque2002finite, 48 | * Author = {LeVeque, R. J.}, 49 | * Date-Added = {2011-09-13 14:09:31 +0000}, 50 | * Date-Modified = {2011-10-31 09:46:40 +0000}, 51 | * Publisher = {Cambridge University Press}, 52 | * Title = {Finite Volume Methods for Hyperbolic Problems}, 53 | * Volume = {31}, 54 | * Year = {2002}} 55 | * 56 | * @webpage{levequeclawpack, 57 | * Author = {LeVeque, R. J.}, 58 | * Lastchecked = {January, 05, 2011}, 59 | * Title = {Clawpack Sofware}, 60 | * Url = {https://github.com/clawpack/clawpack-4.x/blob/master/geoclaw/2d/lib}} 61 | * 62 | **** 63 | * 64 | * Acknowledgments: 65 | * Special thanks go to R.J. LeVeque and D.L. George for publishing their code 66 | * and the corresponding documentation (-> Literature). 67 | */ 68 | 69 | /* 70 | * TODO: store nLow/nHigh variables in array[2] 71 | */ 72 | 73 | #ifndef AUGRIE_FUN_HPP 74 | #define AUGRIE_FUN_HPP 75 | 76 | #include 77 | #include 78 | #include 79 | //#include 80 | //#include 81 | 82 | // constants to classify wet-dry-state of a pairs of cells: 83 | const int DryDry = 0; 84 | const int WetWet = 1; 85 | const int WetDryInundation = 2; 86 | const int WetDryWall = 3; 87 | const int WetDryWallInundation = 4; 88 | const int DryWetInundation = 5; 89 | const int DryWetWall = 6; 90 | const int DryWetWallInundation = 7; 91 | 92 | // constants to classify Riemann state of a pairs of cells: 93 | const int DrySingleRarefaction = 0; 94 | const int SingleRarefactionDry = 1; 95 | const int ShockShock = 2; 96 | const int ShockRarefaction = 3; 97 | const int RarefactionShock = 4; 98 | const int RarefactionRarefaction = 5; 99 | 100 | namespace solver { 101 | 102 | /** 103 | * 104 | */ 105 | template 106 | class AugRieFun { 107 | private: 108 | const real dryTol; 109 | const real g; // gravity constant 110 | const real half_g; // 0.5 * gravity constant 111 | const real sqrt_g; // square root of the gravity constant 112 | const real zeroTol; 113 | const real newtonTol; // tolerance for the Newton iterative solver 114 | const unsigned int maxNumberOfNewtonIterations; // maximum number of performed Newton iterations 115 | 116 | public: 117 | /** 118 | * AugRieFun Constructor, takes three problem parameters 119 | * @param dryTol "dry tolerance": if the water height falls below dryTol, wall boundary conditions are applied 120 | * (default value is 100) 121 | * @param gravity takes the value of the gravity constant (default value is 9.81 m/s^2) 122 | * @param zeroTol computed f-waves with an absolute value < zeroTol are treated as static waves (default value is 123 | * 10^{-7}) 124 | */ 125 | AugRieFun( 126 | real i_dryTol = (real)1.0, 127 | real i_gravity = (real)9.81, 128 | real i_zeroTol = (real)0.0000001, 129 | real i_newtonTol = (real)0.0000001, 130 | real i_maxNewtonIter = 1 131 | ): 132 | dryTol(i_dryTol), 133 | g(i_gravity), 134 | half_g(static_cast(.5) * i_gravity), 135 | sqrt_g(std::sqrt(i_gravity)), 136 | zeroTol(i_zeroTol), 137 | newtonTol(i_newtonTol), 138 | maxNumberOfNewtonIterations(i_maxNewtonIter) {} 139 | 140 | /** 141 | * Compute net updates for the left/right cell of the edge. 142 | * 143 | * maxWaveSpeed will be set to the maximum (linearized) wave speed => CFL 144 | */ 145 | void computeNetUpdates( 146 | const real i_hLeft, 147 | const real i_hRight, 148 | const real i_huLeft, 149 | const real i_huRight, 150 | const real i_bLeft, 151 | const real i_bRight, 152 | 153 | real& o_hUpdateLeft, 154 | real& o_hUpdateRight, 155 | real& o_huUpdateLeft, 156 | real& o_huUpdateRight, 157 | real& o_maxWaveSpeed 158 | ) const { 159 | real hLeft = i_hLeft; 160 | real hRight = i_hRight; 161 | real uLeft = static_cast(0); 162 | real uRight = static_cast(0); 163 | real huLeft = i_huLeft; 164 | real huRight = i_huRight; 165 | real bLeft = i_bLeft; 166 | real bRight = i_bRight; 167 | 168 | // declare variables which are used over and over again 169 | real sqrt_g_hLeft; 170 | real sqrt_g_hRight; 171 | 172 | real sqrt_hLeft; 173 | real sqrt_hRight; 174 | 175 | // reset net updates and the maximum wave speed 176 | o_hUpdateLeft = o_hUpdateRight = o_huUpdateLeft = o_huUpdateRight = static_cast(0); 177 | o_maxWaveSpeed = static_cast(0); 178 | 179 | // variables for computing middle states 180 | real hMiddle = static_cast(0); 181 | real middleStateSpeeds[2] = {static_cast(0)}; 182 | 183 | /*************************************************************************************** 184 | * Determine Wet Dry State Begin 185 | * (determine the wet/dry state and compute local variables correspondingly) 186 | **************************************************************************************/ 187 | int wetDryState; 188 | // compute speeds or set them to zero (dry cells) 189 | if (hLeft >= dryTol) { 190 | uLeft = huLeft / hLeft; 191 | } else { 192 | bLeft += hLeft; 193 | hLeft = huLeft = uLeft = static_cast(0); 194 | } 195 | 196 | if (hRight >= dryTol) { 197 | uRight = huRight / hRight; 198 | } else { 199 | bRight += hRight; 200 | hRight = huRight = uRight = static_cast(0); 201 | } 202 | 203 | // MB: determine wet/dry-state - try to start with most frequent case 204 | if (hLeft >= dryTol) { 205 | if (hRight >= dryTol) { 206 | // simple wet/wet case - expected as most frequently executed branch 207 | wetDryState = WetWet; 208 | } else { // hLeft >= dryTol and hRight < dryTol 209 | // we have a shoreline: left cell wet, right cell dry 210 | //=>check for simple inundation problems 211 | if (hLeft + bLeft > bRight) { 212 | // => dry cell lies lower than the wet cell 213 | wetDryState = WetDryInundation; 214 | } else { // hLeft >= dryTol and hRight < dryTol and hLeft + bLeft <= bRight 215 | // =>dry cell (right) lies higher than the wet cell (left) 216 | // lets check if the momentum is able to overcome the difference in height 217 | // => solve homogeneous Riemann-problem to determine the middle state height 218 | // which would arise if there is a wall (wall-boundary-condition) 219 | // \cite[ch. 6.8.2]{george2006finite}) 220 | // \cite[ch. 5.2]{george2008augmented} 221 | computeMiddleState(hLeft, hLeft, uLeft, -uLeft, maxNumberOfNewtonIterations, hMiddle, middleStateSpeeds); 222 | 223 | if (hMiddle + bLeft > bRight) { 224 | // momentum is large enough, continue with the original values 225 | // bRight = o_hMiddle + bLeft; 226 | wetDryState = WetDryWallInundation; 227 | // limit the effect of the source term if there is a "wall" 228 | //\cite[end of ch. 5.2?]{george2008augmented}, \cite[rpn2ez_fast_geo.f][levequeclawpack] 229 | bRight = hLeft + bLeft; 230 | } else { 231 | hRight = hLeft; 232 | uRight = -uLeft; 233 | huRight = -huLeft; 234 | bRight = bLeft = static_cast(0); 235 | wetDryState = WetDryWall; 236 | } 237 | } 238 | } 239 | } else { // hLeft < dryTol 240 | if (hRight >= dryTol) { 241 | // we have a shoreline: left cell dry, right cell wet 242 | //=>check for simple inundation problems 243 | if (hRight + bRight > bLeft) { 244 | // => dry cell lies lower than the wet cell 245 | wetDryState = DryWetInundation; 246 | } else { // hLeft < dryTol and hRight >= dryTol and hRight + bRight <= bLeft 247 | // =>dry cell (left) lies higher than the wet cell (right) 248 | // lets check if the momentum is able to overcome the difference in height 249 | // => solve homogeneous Riemann-problem to determine the middle state height 250 | // which would arise if there is a wall (wall-boundary-condition) 251 | // \cite[ch. 6.8.2]{george2006finite}) 252 | // \cite[ch. 5.2]{george2008augmented} 253 | computeMiddleState( 254 | hRight, hRight, -uRight, uRight, maxNumberOfNewtonIterations, hMiddle, middleStateSpeeds 255 | ); 256 | 257 | if (hMiddle + bRight > bLeft) { 258 | // momentum is large enough, continue with the original values 259 | // bLeft = o_hMiddle + bRight; 260 | wetDryState = DryWetWallInundation; 261 | // limit the effect of the source term if there is a "wall" 262 | //\cite[end of ch. 5.2?]{george2008augmented}, \cite[rpn2ez_fast_geo.f][levequeclawpack] 263 | bLeft = hRight + bRight; 264 | } else { 265 | // momentum is not large enough, use wall-boundary-values 266 | hLeft = hRight; 267 | uLeft = -uRight; 268 | huLeft = -huRight; 269 | bLeft = bRight = static_cast(0); 270 | wetDryState = DryWetWall; 271 | } 272 | } 273 | } else { // hLeft < dryTol and hRight < dryTol 274 | wetDryState = DryDry; 275 | // nothing to do for dry/dry case, all netUpdates and maxWaveSpeed are 0 276 | return; 277 | } 278 | }; 279 | 280 | /*************************************************************************************** 281 | * Determine Wet Dry State End 282 | **************************************************************************************/ 283 | // MB: not executed for DryDry => returns right after case is identified 284 | assert(wetDryState != DryDry); 285 | 286 | // precompute some terms which are fixed during 287 | // the computation after some specific point 288 | sqrt_hLeft = std::sqrt(hLeft); 289 | sqrt_hRight = std::sqrt(hRight); 290 | 291 | sqrt_g_hLeft = sqrt_g * sqrt_hLeft; 292 | sqrt_g_hRight = sqrt_g * sqrt_hRight; 293 | 294 | // compute the augmented decomposition 295 | // (thats the place where the computational work is done..) 296 | /*************************************************************************************** 297 | * Compute Wave Decomposition Begin 298 | **************************************************************************************/ 299 | // compute eigenvalues of the jacobian matrices in states Q_{i-1} and Q_{i} (char. speeds) 300 | const real characteristicSpeeds[2] = {uLeft - sqrt_g_hLeft, uRight + sqrt_g_hRight}; 301 | 302 | // compute "Roe speeds" 303 | const real hRoe = static_cast(0.5) * (hRight + hLeft); 304 | const real uRoe = (uLeft * sqrt_hLeft + uRight * sqrt_hRight) / (sqrt_hLeft + sqrt_hRight); 305 | 306 | // optimization for dumb compilers 307 | const real sqrt_g_hRoe = sqrt_g * std::sqrt(hRoe); 308 | const real roeSpeeds[2] = {uRoe - sqrt_g_hRoe, uRoe + sqrt_g_hRoe}; 309 | 310 | // compute the middle state of the homogeneous Riemann-Problem 311 | // MB: ???computeMiddleState always called? -> possible to rearrange computation to reduce if-statements??? 312 | // MB: !!!here always only 1 Newton iteration 313 | if (wetDryState != WetDryWall && wetDryState != DryWetWall) { 314 | // case WDW and DWW was computed in determineWetDryState already 315 | computeMiddleState(hLeft, hRight, uLeft, uRight, 1, hMiddle, middleStateSpeeds); 316 | } 317 | 318 | // compute extended eindfeldt speeds (einfeldt speeds + middle state speeds) 319 | // \cite[ch. 5.2]{george2008augmented}, \cite[ch. 6.8]{george2006finite} 320 | real extEinfeldtSpeeds[2] = {static_cast(0), static_cast(0)}; 321 | if (wetDryState == WetWet || wetDryState == WetDryWall || wetDryState == DryWetWall) { 322 | extEinfeldtSpeeds[0] = std::min(characteristicSpeeds[0], roeSpeeds[0]); 323 | extEinfeldtSpeeds[0] = std::min(extEinfeldtSpeeds[0], middleStateSpeeds[1]); 324 | 325 | extEinfeldtSpeeds[1] = std::max(characteristicSpeeds[1], roeSpeeds[1]); 326 | extEinfeldtSpeeds[1] = std::max(extEinfeldtSpeeds[1], middleStateSpeeds[0]); 327 | } else if (hLeft < dryTol) { // MB: !!! cases DryWetInundation, DryWetWallInundation 328 | // ignore undefined speeds 329 | extEinfeldtSpeeds[0] = std::min(roeSpeeds[0], middleStateSpeeds[1]); 330 | extEinfeldtSpeeds[1] = std::max(characteristicSpeeds[1], roeSpeeds[1]); 331 | 332 | assert(middleStateSpeeds[0] < extEinfeldtSpeeds[1]); 333 | } else if (hRight < dryTol) { // MB: !!! cases WetDryInundation, WetDryWallInundation 334 | // ignore undefined speeds 335 | extEinfeldtSpeeds[0] = std::min(characteristicSpeeds[0], roeSpeeds[0]); 336 | extEinfeldtSpeeds[1] = std::max(roeSpeeds[1], middleStateSpeeds[0]); 337 | 338 | assert(middleStateSpeeds[1] > extEinfeldtSpeeds[0]); 339 | } else { 340 | assert(false); 341 | } 342 | 343 | // HLL middle state 344 | // \cite[theorem 3.1]{george2006finite}, \cite[ch. 4.1]{george2008augmented} 345 | const real hLLMiddleHeight = std::max( 346 | (huLeft - huRight + extEinfeldtSpeeds[1] * hRight - extEinfeldtSpeeds[0] * hLeft 347 | ) / (extEinfeldtSpeeds[1] - extEinfeldtSpeeds[0]), 348 | static_cast(0) 349 | ); 350 | 351 | // define eigenvalues 352 | const real eigenValues[3] = { 353 | extEinfeldtSpeeds[0], 354 | static_cast(0.5) * (extEinfeldtSpeeds[0] + extEinfeldtSpeeds[1]), 355 | extEinfeldtSpeeds[1]}; 356 | 357 | // define eigenvectors 358 | // MB: no longer used as system matrix 359 | // -> but still used to compute f-waves 360 | const real eigenVectors[3][3] = { 361 | {static_cast(1), static_cast(0), static_cast(1)}, 362 | {eigenValues[0], static_cast(0), eigenValues[2]}, 363 | {eigenValues[0] * eigenValues[0], static_cast(1), eigenValues[2] * eigenValues[2]}}; 364 | 365 | // compute rarefaction corrector wave 366 | // \cite[ch. 6.7.2]{george2006finite}, \cite[ch. 5.1]{george2008augmented} 367 | #pragma message \ 368 | "strongRarefaction set to false. Further investigations needed about senseless initialization of eigenValues[1]" 369 | 370 | // compute the jump in state 371 | real rightHandSide[3] = { 372 | hRight - hLeft, 373 | huRight - huLeft, 374 | (huRight * uRight + half_g * hRight * hRight) - (huLeft * uLeft + half_g * hLeft * hLeft)}; 375 | 376 | // compute steady state wave 377 | // \cite[ch. 4.2.1 \& app. A]{george2008augmented}, \cite[ch. 6.2 \& ch. 4.4]{george2006finite} 378 | real steadyStateWave[2] = {-(bRight - bLeft), -half_g * (hLeft + hRight) * (bRight - bLeft)}; 379 | 380 | // preserve depth-positivity 381 | // \cite[ch. 6.5.2]{george2006finite}, \cite[ch. 4.2.3]{george2008augmented} 382 | if (eigenValues[0] < -zeroTol && eigenValues[2] > zeroTol) { 383 | // subsonic 384 | steadyStateWave[0] = std::max( 385 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[0] 386 | ); 387 | steadyStateWave[0] = std::min( 388 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[2] 389 | ); 390 | } else if (eigenValues[0] > zeroTol) { 391 | // supersonic right TODO: motivation? 392 | steadyStateWave[0] = std::max(steadyStateWave[0], -hLeft); 393 | steadyStateWave[0] = std::min( 394 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[0] 395 | ); 396 | } else if (eigenValues[2] < -zeroTol) { 397 | // supersonic left TODO: motivation? 398 | steadyStateWave[0] = std::max( 399 | steadyStateWave[0], hLLMiddleHeight * (eigenValues[2] - eigenValues[0]) / eigenValues[2] 400 | ); 401 | steadyStateWave[0] = std::min(steadyStateWave[0], hRight); 402 | } 403 | 404 | // Limit the effect of the source term 405 | // \cite[ch. 6.4.2]{george2006finite} 406 | steadyStateWave[1] = std::min( 407 | steadyStateWave[1], g * std::max(-hLeft * (bRight - bLeft), -hRight * (bRight - bLeft)) 408 | ); 409 | steadyStateWave[1] = std::max( 410 | steadyStateWave[1], g * std::min(-hLeft * (bRight - bLeft), -hRight * (bRight - bLeft)) 411 | ); 412 | 413 | rightHandSide[0] -= steadyStateWave[0]; 414 | // rightHandSide[1]: no source term 415 | rightHandSide[2] -= steadyStateWave[1]; 416 | 417 | // everything is ready, solve the equations! 418 | /*************************************************************************************** 419 | * Solve linear equation begin 420 | **************************************************************************************/ 421 | 422 | // direct solution of specific 3x3 system: 423 | // ( 1 0 1 ) ( beta[0] ) = ( rightHandSide[0] ) 424 | // ( eigenValues[0] 0 eigenValues[2] ) ( beta[1] ) ( rightHandSide[1] ) 425 | // ( eigenValues[0]^2 1 eigenValues[2]^2 ) ( beta[2] ) ( rightHandSide[2] ) 426 | 427 | // step 1: solve the following 2x2 system (1st and 3rd column): 428 | // ( 1 1 ) ( beta[0] ) = ( rightHandSide[0] ) 429 | // ( eigenValues[0] eigenValues[2] ) ( beta[2] ) ( rightHandSide[1] ) 430 | 431 | // compute the inverse of the wave speed difference: 432 | real inverseDiff = static_cast(1.) / (eigenValues[2] - eigenValues[0]); // 2 FLOPs (1 div) 433 | // compute f-waves: 434 | real beta[3]; 435 | beta[0] = (eigenValues[2] * rightHandSide[0] - rightHandSide[1]) * inverseDiff; // 3 FLOPs 436 | beta[2] = (-eigenValues[0] * rightHandSide[0] + rightHandSide[1]) * inverseDiff; // 3 FLOPs 437 | 438 | // step 2: solve 3rd row for beta[1]: 439 | beta[1] = rightHandSide[2] - eigenValues[0] * eigenValues[0] * beta[0] - eigenValues[2] * eigenValues[2] * beta[2]; 440 | 441 | #ifdef false 442 | // compute inverse of 3x3 matrix 443 | // MB: !!!AVOID COMPUTATION of inverse => see above for better solution for simple matrix 444 | // MB: TODO -> different choice of matrix in AugRie.hpp -> requires a separate solution procedure 445 | const real m[3][3] = { 446 | {(eigenVectors[1][1] * eigenVectors[2][2] - eigenVectors[1][2] * eigenVectors[2][1]), 447 | -(eigenVectors[0][1] * eigenVectors[2][2] - eigenVectors[0][2] * eigenVectors[2][1]), 448 | (eigenVectors[0][1] * eigenVectors[1][2] - eigenVectors[0][2] * eigenVectors[1][1])}, 449 | {-(eigenVectors[1][0] * eigenVectors[2][2] - eigenVectors[1][2] * eigenVectors[2][0]), 450 | (eigenVectors[0][0] * eigenVectors[2][2] - eigenVectors[0][2] * eigenVectors[2][0]), 451 | -(eigenVectors[0][0] * eigenVectors[1][2] - eigenVectors[0][2] * eigenVectors[1][0])}, 452 | {(eigenVectors[1][0] * eigenVectors[2][1] - eigenVectors[1][1] * eigenVectors[2][0]), 453 | -(eigenVectors[0][0] * eigenVectors[2][1] - eigenVectors[0][1] * eigenVectors[2][0]), 454 | (eigenVectors[0][0] * eigenVectors[1][1] - eigenVectors[0][1] * eigenVectors[1][0])}}; 455 | const real d = (eigenVectors[0][0] * m[0][0] + eigenVectors[0][1] * m[1][0] + eigenVectors[0][2] * m[2][0]); 456 | 457 | // m stores not really the inverse matrix, but the inverse multiplied by d 458 | const real s = 1 / d; 459 | 460 | // compute m*rightHandSide 461 | const real beta[3] = { 462 | (m[0][0] * rightHandSide[0] + m[0][1] * rightHandSide[1] + m[0][2] * rightHandSide[2]) * s, 463 | (m[1][0] * rightHandSide[0] + m[1][1] * rightHandSide[1] + m[1][2] * rightHandSide[2]) * s, 464 | (m[2][0] * rightHandSide[0] + m[2][1] * rightHandSide[1] + m[2][2] * rightHandSide[2]) * s}; 465 | #endif 466 | 467 | /*************************************************************************************** 468 | * Solve linear equation end 469 | **************************************************************************************/ 470 | 471 | // compute f-waves and wave-speeds 472 | real fWaves[3][2]; // array to store the three f-wave vectors (2 components each) 473 | real waveSpeeds[3]; // and vector to their speeds 474 | 475 | if (wetDryState == WetDryWall) { 476 | // zero ghost updates (wall boundary) 477 | // care about the left going wave (0) only 478 | fWaves[0][0] = beta[0] * eigenVectors[1][0]; 479 | fWaves[0][1] = beta[0] * eigenVectors[2][0]; 480 | 481 | // set the rest to zero 482 | fWaves[1][0] = fWaves[1][1] = static_cast(0); 483 | fWaves[2][0] = fWaves[2][1] = static_cast(0); 484 | 485 | waveSpeeds[0] = eigenValues[0]; 486 | waveSpeeds[1] = waveSpeeds[2] = static_cast(0); 487 | 488 | assert(eigenValues[0] < zeroTol); 489 | } else if (wetDryState == DryWetWall) { 490 | // zero ghost updates (wall boundary) 491 | // care about the right going wave (2) only 492 | fWaves[2][0] = beta[2] * eigenVectors[1][2]; 493 | fWaves[2][1] = beta[2] * eigenVectors[2][2]; 494 | 495 | // set the rest to zero 496 | fWaves[0][0] = fWaves[0][1] = static_cast(0); 497 | fWaves[1][0] = fWaves[1][1] = static_cast(0); 498 | 499 | waveSpeeds[2] = eigenValues[2]; 500 | waveSpeeds[0] = waveSpeeds[1] = static_cast(0); 501 | 502 | assert(eigenValues[2] > -zeroTol); 503 | } else { 504 | // compute f-waves (default) 505 | for (int waveNumber = 0; waveNumber < 3; waveNumber++) { 506 | fWaves[waveNumber][0] = beta[waveNumber] * eigenVectors[1][waveNumber]; // select 2nd and 507 | fWaves[waveNumber][1] = beta[waveNumber] * eigenVectors[2][waveNumber]; // 3rd component of the augmented 508 | // decomposition 509 | } 510 | 511 | waveSpeeds[0] = eigenValues[0]; 512 | waveSpeeds[1] = eigenValues[1]; 513 | waveSpeeds[2] = eigenValues[2]; 514 | } 515 | /*************************************************************************************** 516 | * Compute Wave Decomposition End 517 | **************************************************************************************/ 518 | 519 | // compute the updates from the three propagating waves 520 | // A^-\delta Q = \sum{s[i]<0} \beta[i] * r[i] = A^-\delta Q = \sum{s[i]<0} Z^i 521 | // A^+\delta Q = \sum{s[i]>0} \beta[i] * r[i] = A^-\delta Q = \sum{s[i]<0} Z^i 522 | for (int waveNumber = 0; waveNumber < 3; waveNumber++) { 523 | if (waveSpeeds[waveNumber] < -zeroTol) { 524 | // left going 525 | o_hUpdateLeft += fWaves[waveNumber][0]; 526 | o_huUpdateLeft += fWaves[waveNumber][1]; 527 | } else if (waveSpeeds[waveNumber] > zeroTol) { 528 | // right going 529 | o_hUpdateRight += fWaves[waveNumber][0]; 530 | o_huUpdateRight += fWaves[waveNumber][1]; 531 | } else { 532 | // TODO: this case should not happen mathematically, but it does. Where is the bug? Machine accuracy only? 533 | // MB: >>> waveSpeeds set to 0 for cases WetDryWall and DryWetWall 534 | o_hUpdateLeft += static_cast(0.5) * fWaves[waveNumber][0]; 535 | o_huUpdateLeft += static_cast(0.5) * fWaves[waveNumber][1]; 536 | 537 | o_hUpdateRight += static_cast(0.5) * fWaves[waveNumber][0]; 538 | o_huUpdateRight += static_cast(0.5) * fWaves[waveNumber][1]; 539 | } 540 | } 541 | 542 | // compute maximum wave speed (-> CFL-condition) 543 | waveSpeeds[0] = std::abs(waveSpeeds[0]); 544 | waveSpeeds[1] = std::abs(waveSpeeds[1]); 545 | waveSpeeds[2] = std::abs(waveSpeeds[2]); 546 | 547 | o_maxWaveSpeed = std::max(std::max(waveSpeeds[0], waveSpeeds[1]), waveSpeeds[2]); 548 | } 549 | 550 | /** 551 | * Computes the middle state of the homogeneous Riemann-problem. 552 | * -> (\cite[ch. 13]{leveque2002finite}) 553 | * 554 | * @param i_hLeft height on the left side of the edge. 555 | * @param i_hRight height on the right side of the edge. 556 | * @param i_uLeft velocity on the left side of the edge. 557 | * @param i_uRight velocity on the right side of the edge. 558 | * @param i_maxNumberOfNewtonIterations maximum number of Newton iterations. 559 | */ 560 | inline void computeMiddleState( 561 | const real& i_hLeft, 562 | const real& i_hRight, 563 | const real& i_uLeft, 564 | const real& i_uRight, 565 | const unsigned int& i_maxNumberOfNewtonIterations, 566 | real& o_hMiddle, 567 | real o_middleStateSpeeds[2] 568 | ) const { 569 | //!!!MB: currently called with 570 | // i_maxNumberOfNewtonIterations = maxNumberOfNewtonIterations for wall boundaries 571 | // -> only leads to ShockShock or RarefactionRarefaction -> can be simplified 572 | // i_maxNumberOfNewtonIterations = 1 (computation of middle states) 573 | // -> could be changed towards a simplified implementation 574 | // ==> consider to split method into two or more separate implementations? 575 | 576 | // set everything to zero 577 | o_hMiddle = static_cast(0); 578 | o_middleStateSpeeds[0] = static_cast(0); 579 | o_middleStateSpeeds[1] = static_cast(0); 580 | // will be computed later 581 | real sqrt_g_hMiddle = static_cast(0); 582 | 583 | // compute local square roots 584 | //(not necessarily the same ones as in computeNetUpdates!) 585 | real l_sqrt_g_hRight = std::sqrt(g * i_hRight); 586 | real l_sqrt_g_hLeft = std::sqrt(g * i_hLeft); 587 | 588 | // single rarefaction in the case of a wet/dry interface 589 | if (i_hLeft < dryTol) { 590 | // ===== riemannStructure = DrySingleRarefaction; ===== 591 | o_middleStateSpeeds[1] = o_middleStateSpeeds[0] = i_uRight - static_cast(2) * l_sqrt_g_hRight; 592 | return; 593 | } else if (i_hRight < dryTol) { 594 | // ===== riemannStructure = SingleRarefactionDry; ===== 595 | o_middleStateSpeeds[0] = o_middleStateSpeeds[1] = i_uLeft + static_cast(2) * l_sqrt_g_hLeft; 596 | return; 597 | } 598 | 599 | /*************************************************************************************** 600 | * Determine the wave structure of the Riemann-problem (no dry cases) 601 | **************************************************************************************/ 602 | const real hMin = std::min(i_hLeft, i_hRight); 603 | const real hMax = std::max(i_hLeft, i_hRight); 604 | 605 | const real uDif = i_uRight - i_uLeft; 606 | 607 | if (0 <= static_cast(2) * (std::sqrt(g * hMin) - std::sqrt(g * hMax)) + uDif) { 608 | // ===== riemannStructure = RarefactionRarefaction; ===== 609 | o_hMiddle = std::max( 610 | static_cast(0), i_uLeft - i_uRight + static_cast(2) * (l_sqrt_g_hLeft + l_sqrt_g_hRight) 611 | ); 612 | o_hMiddle = o_hMiddle * o_hMiddle / (static_cast(16) * g); 613 | 614 | sqrt_g_hMiddle = sqrt_g * std::sqrt(o_hMiddle); 615 | // ======================================================= 616 | } else if ((hMax - hMin) * std::sqrt(half_g * (1 / hMax + 1 / hMin)) + uDif <= 0) { 617 | // ===== riemannStructure = ShockShock; ================== 618 | o_hMiddle = std::min(i_hLeft, i_hRight); 619 | 620 | real l_sqrtTermH[2] = {0, 0}; 621 | 622 | for (unsigned int i = 0; i < i_maxNumberOfNewtonIterations; i++) { 623 | l_sqrtTermH[0] = std::sqrt(half_g * ((o_hMiddle + i_hLeft) / (o_hMiddle * i_hLeft))); 624 | l_sqrtTermH[1] = std::sqrt(half_g * ((o_hMiddle + i_hRight) / (o_hMiddle * i_hRight))); 625 | 626 | real phi = i_uRight - i_uLeft + (o_hMiddle - i_hLeft) * l_sqrtTermH[0] 627 | + (o_hMiddle - i_hRight) * l_sqrtTermH[1]; 628 | 629 | if (std::abs(phi) < newtonTol) 630 | break; 631 | 632 | real derivativePhi 633 | = l_sqrtTermH[0] + l_sqrtTermH[1] 634 | - static_cast(0.25) * g 635 | * ((o_hMiddle - i_hLeft) / (l_sqrtTermH[0] * o_hMiddle * o_hMiddle) + (o_hMiddle - i_hRight) / (l_sqrtTermH[1] * o_hMiddle * o_hMiddle)); 636 | o_hMiddle = o_hMiddle - phi / derivativePhi; // Newton step 637 | assert(o_hMiddle >= dryTol); 638 | } 639 | 640 | sqrt_g_hMiddle = sqrt_g * std::sqrt(o_hMiddle); 641 | // ======================================================= 642 | } else { 643 | // ===== riemannStructure = ShockRarefaction; ============ 644 | // ===== riemannStructure = RarefactionShock; ============ 645 | o_hMiddle = hMin; 646 | 647 | sqrt_g_hMiddle = sqrt_g * std::sqrt(o_hMiddle); 648 | real sqrt_g_hMax = sqrt_g * std::sqrt(hMax); 649 | for (unsigned int i = 0; i < i_maxNumberOfNewtonIterations; i++) { 650 | real sqrtTermHMin = half_g * ((o_hMiddle + hMin) / (o_hMiddle * hMin)); 651 | 652 | real phi = i_uRight - i_uLeft + (o_hMiddle - hMin) * sqrtTermHMin 653 | + static_cast(2) * (sqrt_g_hMiddle - sqrt_g_hMax); 654 | 655 | if (std::abs(phi) < newtonTol) 656 | break; 657 | 658 | real derivativePhi = sqrtTermHMin 659 | - static_cast(0.25) * g * (o_hMiddle - hMin) 660 | / (o_hMiddle * o_hMiddle * sqrtTermHMin) 661 | + sqrt_g / sqrt_g_hMiddle; 662 | 663 | o_hMiddle = o_hMiddle - phi / derivativePhi; // Newton step 664 | 665 | sqrt_g_hMiddle = sqrt_g * std::sqrt(o_hMiddle); 666 | } 667 | // ======================================================= 668 | } 669 | /*************************************************************************************** 670 | * Determine the wave structure end 671 | **************************************************************************************/ 672 | 673 | o_middleStateSpeeds[0] = i_uLeft + static_cast(2) * l_sqrt_g_hLeft - static_cast(3) * sqrt_g_hMiddle; 674 | o_middleStateSpeeds[1] = i_uRight - static_cast(2) * l_sqrt_g_hRight + static_cast(3) * sqrt_g_hMiddle; 675 | 676 | assert(o_hMiddle >= 0); 677 | } 678 | 679 | }; // end of class AugRieFun 680 | 681 | } // end of namespace solver 682 | 683 | #endif /* AUGRIE_FUN_HPP */ 684 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------