Coder Social home page Coder Social logo

bcaddy / hydro-sandbox Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 3.97 MB

This is a place for me to practice and experiment with Riemann solvers, MHD, and other miscelanious hydro related things.

License: GNU General Public License v3.0

C++ 52.30% Python 3.58% Makefile 1.03% Shell 0.74% C 15.85% Jupyter Notebook 26.18% Cuda 0.33%

hydro-sandbox's People

Contributors

bcaddy avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

hydro-sandbox's Issues

Make the code more modular and Add Some new features

  • Create a script to build, run, plot, and download a particular solver
  • Split helper.* into multiple files
  • Update 2nd-Order-linear-advection.cpp and burgers.cpp to use the new headers
  • Rename the advection solver to just advection-solver.cpp
  • Reorganize the Makefile to account for changes
    • Make compilation neater like fortran makefiles
  • Make initial conditions and limiter call different local (private) functions
  • Add new functions
    • MC limiter
    • interface computer for advection

Implement a timing class

Overview

  • Write the timer

  • Implement it in euler-main.cpp

Member variables

  • start time
  • time deltas
  • Is timer active?

Member functions

  • Start timer
  • Stop timer
  • Return total time
  • Return time statistics. min, max, avg, n times,
  • Print total time, time statistics, name of timer

Write a MHD Solver

Summary

Using my 3D Euler solver with a Van Leer integrator, implement MHD using the VL+CT algorithm from Stone & Gardiner 2009. Will require a HLLD Riemann solver

References

  • Evans & Hawley 1988 - Original Constrained Transport paper
  • Miyoshi & Kusano 2005 - Original HLLD paper
  • Stone & Gardiner 2009 - VL+CT Algorithm
    • Gardiner & Stone 2005 and 2008 but they're less important
  • 2000 Flash paper by Fryxlell - Application of MHD in FLASH

Implementation

Changes

  • Copy euler1D-VL to `mhd1D' or something similar. Change all the names of things to reflect their MHDness
  • Update the Grid objects
  • Update initial conditions
  • Add new utility functions and update old ones
  • HLLD Riemann solver
    • Have the base and star flux functions store their primitive state as member variables
    • Make sure that each flux function can call the one before it elegantly
  • Update the Riemann tester program so that I can test the HLLD solver
  • Update plotting function
  • Test and debug the HLLD Solver
    • This can't really be done in isolation. The HLLD solver is incomplete (it only covers 5 of 7 waves) and so as a result it can't be used on its own. I tested it enough that it looks correct though

MHDSimulation Class: Implementing a VL+CT integrator (S&G 2009)

  • Figure out what new member variables are needed
    • cell centered magnetic fields
    • edge averaged electric fields - this will require the most differences between 1D an 3D
  • Figure out what new member functions are needed
    • compute cell centered magnetic fields
    • CT electric fields
      • make sure the primitive grid is stored such that I virtual cells on all sides. I need to be able to treat this as a 1x1xN simulation. Do this by creating a 3x3xN grid when I'm computing the electric fields. All the values at a given N should be identical.
  • Update old member functions and variables
    • _piecewiseLinearReconstruction
    • _piecewiseConstantReconstruction
    • computeTimeStep
    • interfaceStates - might not require much modification since it's just chooses which reconstruction to use
    • solveRiemann
      • make sure I'm passing magnetic fields correctly
    • conservativeUpdate
    • constructor

Bug Fixes

  • Resolve bugs that linter has noted
  • Make sure each file compiles
  • Get the makefile setup
  • Get the whole project to compile
  • Get it to run
  • Fix obvious bugs
    • Initial conditions aren't right. Especially check Bz and pressure
    • Sudden pressure drop in first time step?
    • Magnetic field not updating
    • Issue with (i think) R** state in HLLD solver)
      • looks like an issue with the calculations of the velocity
  • Test each component
    • MHD utilities
      • magsonicSpeed
      • total pressure
      • alfven speed
      • velocity
      • momentum
      • pressure
      • energy
    • HLLD Solver
      • wave speeds
      • standard fluxes
      • vAndBStar
      • Star Fluxes'
      • double star fluxes
    • MHD Simulation1D Class
      • conservativeUpdate
      • centered magnetic field
      • ctElectricFields
      • ctSlope
      • interface states
      • PLM
      • PCM
      • time step
      • grid.boundaries
      • solveRiemann
      • initial conditions
  • Integration testing

Create a 1D Euler Solver using a Van Leer integrator

Tasks

  • Move the old euler solver to eulerSolver1D-CTU

  • Copy the contents of that directory to a new directory titled eulerSolver1D-VL

  • Update shell scripts and doxygen documentation to account for the changes

    • different doxygen things for each directory??
  • Modify contents of eulerSolver1D-VL to use Van Leer algorithm

Van Leer Algorithm

  1. Compute first order interface states

  2. Solve Riemann problem

  3. Perform a conservative update to compute the temporary half time step values for the conserved variables

  4. Compute the interface states with a high order method (PLM) using the half time step conserved variables

  5. Solve the Riemann problem for the half time step interface states

  6. Perform a conservative update on the permanent grid using the fluxes from the second Riemann solve

New Elements I need to add

Interface computations

  • A way to choose on the fly between first and second order interface states. Might need to ditch a current member variable or use it to choose highest order

  • A way to choose if I'm using the primary grid or the half time step grid

Conservative update

  • Choose between updating the real grid or the half time step grid

Member variables

  • a temporary grid for storing half time step values

Grid

  • Create a simple grid struct for storing the grid of primitive variables

Resolving Issues/Bugs

  • The ghost cells in the half time step grid need to be updated as well
  • Van Leer doesn't require characteristic tracing so that needs to be removed

Write an Exact Euler/Riemann Solver

Overview

  • Write documentation using doxygen

  • Create a struct for the grid.

  • Create classes for the simulation

  • Write the main function

  • Write a visualizer

  • My original implementation had issues. Namely that the fluxes were recomputed for each cell and that can lead to numerical instabilities so now I'm fixing and enhancing the code.

Details

Stretch goals in italics

Using Doxygen

  • Make myself a cheatsheet for Doxygen
  • Explore my doxygen VSC plugins

Creating the Classes

Grid Struct

Member variables

  • velocity
  • density
  • pressure
  • numGhostCells
  • numRealCells
  • totNumCells
  • Files (type std::ofstream from std::fstream)

Member functions

Those that will require template functionality are indicated. Functions that might not need to be part of the class are indicated with "?".

  • Calculate momentum
  • Access the ith element of each array
  • Save output, use CSV for now, making three separate CSV files is probably easiest. future versions will use HDF5
  • Set and updated boundary conditions (template: periodic, outflow, reflect, inflow, hydrostatic)

Riemann Solver Class

Member Variables (private unless otherwise indicated)

  • cR and cL for sound speed on left and right side
  • pressureStar
  • velocityStar
  • densityStar
  • Left and right state variables
  • gamma
  • position
  • time

Member Functions (private unless otherwise indicated)

  • Determine pStar
    • guess pStar
  • f_k and f'_k
  • computeVStar
  • speed of shocks
  • speed of rarefaction, both head and tail
  • Compute fluxes
  • compute shock density
  • compute density for the star state next to a rarefaction
  • compute all values within a rarefaction
  • riemannMain (public)

Simulation Class

Member Variables

  • Current grid
  • Next time step grid
  • physLen
  • deltaX
  • timeStep
  • CFLNum
  • limiterKind
  • initialConditionKind
  • current time

Member Functions

  • Set initial conditions (template: Sod, Sedov, advection, slow moving shock)
  • Limiters (template: MC, minmod)
  • Compute time step
    • Zingale eqn. 8.57, Toro Section 6.3.2
  • Reconstruct interface states (template for using piecewise linear or parabolic. Start with the first only)
  • Call Riemann Solver
  • Perform the conservative update
  • Update the primitive values at the end of the loop
  • update current time

The Main Function

This function should:

  • contain all the settings (what limiter to use, initial conditions, etc)
  • call member functions
  • provide console output to the user
  • note the current time and choose when to stop the simulation

Visualizer Code

Look at Evan's sod shock plotter code and make something like that paired with my animation code. The final product should provide an animation with velocity, density, pressure, and internal energy. Maybe stack them so it's clearer where each feature lines up with other features.

  • Did that
  • Modify it to compute internal energy instead of specific internal energy. Compare with Cholla fiducial Sod plot

Enhancements and Refactor

Research Items

  • Templates
  • Namespaces

Todos

  • Refactor to save arrays of interface states and fluxes and then update all the grid elements at once
    • Remove all the stuff for grids that don't get saved
    • Interface states
      • Quick and dirty implementation of piecewise constant reconstruction
      • Add separate functions for PLM and PCM interface reconstruction which are called by Simulation1D::interfaceStates
      • Re-implement MC limiter
  • Move commonly used functions and methods to a header only namespace. This is C++'s version of a "utility class"
    • sound speed
      • Include Nan detection
    • momentum
    • pressure
    • energy
    • velocity
  • Fix up animation program to more elegantly deal with short animations and to always compute an integer stride
  • Clean up documentation. As I go but also do a full pass when I'm done
    • document new initial conditions and limiters
  • Run tests
    • Implement new boundary and initial conditions.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.