1-D advection

class _1DGrid
#include <_1DGrid.H>

Create a 1D grid for advection create a grid for the fluid in the domain from [xmin,xmax] including ghost points. Allow number of ghost points/cells, ng, on each end. The resolution of the domain is determined by nx, the numebr of points or cells.

Public Functions

inline _1DGrid(int _nx, int _ng = 2, double _xmin = 0.0, double _xmax = 1.0)

Constructing our _1DGrid

std::vector<double> scratch_array()

Returns a scratched array, 0 array with size nx+2*ng

void fill_BCs_diff()

invoke the boundary condition to update ghost cell

void set_init(std::vector<double> init_vec)

set initial condition

std::vector<double> get_state()

Returns the current state

Private Members

double xmin

physical xmin of the domain excluding ghost point

double xmax

physical xmax of the domain excluding ghost point

int ng

number of ghost points on each end

int nx

domain points excluding ghost points

int ilo

lower bound point of the domain excluding ghost point

int ihi

high bound point of the domain excluding ghost point

double dx

separation between each point

std::vector<double> state

current state, carry the state for each physical coordinate

std::vector<double> state_init

initial state

std::vector<double> temp_state

some temporary state to hold value

std::vector<double> x

physical x-coordinate inccluding ghost points

Friends

friend class advection_solver
class advection_solver
#include <solver.H>

1-D advection solver. Contains both linear and nonlinear advection solver.

Public Functions

inline advection_solver(_1DGrid _grid, double _u, double _C, std::function<std::vector<double>(const std::vector<double>&)> _init_cond, double _num_periods = 1.0, const std::string &_method = "upwinding", const std::string &_slope_method = "centered", const bool _runtime_dat = false)

Constructing the advection solver

void solve()

It solves the advection equation with given advection method and slope if chose a nonlinear method.

void print_state()

It prints the current state(solution)

double find_error()

Return the relative error between initial and final state It can be called only when num_of_periods is a whole number, i.e. making a full cycle of advection. It is used to test the validity of advection method, which should return back to the original state.

void write_file(std::string fname)

A procedure to write state data to file

Private Functions

void ftcs()

Linear advection method: ftcs method. Smaller C works better

void upwinding()

Linear upwinding method, requires C<=1 for stability. If C=1 we have an exact solution

void predictor_corrector()

Nonlinear advection method: predictor_corrector. if choose slope to be piecewise_const, then its the same as upwinding method.

void method_of_lines()

Nonlinear advection method: method of lines method, uses RK4 integration.

double rhs(int ind)

Returns the RHS of equation da/dt

double riemann_selector(int ind)

Returns the result of Riemann Problem depending on which advection directio, i.e. depending on the sign of u.

double slope(int ind)

Returns the slope depending on the slope method of choice.

Private Members

_1DGrid grid

1DGrid class using _1DGrid.H

double u

velocity of advection. Positive travels to the right. Negative travels to the left

double C

Courant–Friedrichs–Lewy number, which is a a measure of what fraction of a zone we cross per timestep

double num_periods

Number of periods for advection

double t

current time for advection

std::function< std::vector< double >std::vector< double > &) > init_cond

A function that takes the physical domain, e.g. x, as argument that returns the initial state for advection.

std::string method

Advection method of choice. For linear advection, choose between ftcs or upwinding For nonlinear advection, choose between predictor_corrector or method_of_lines

std::string slope_method

Slope method of choice for nonlinear advection methods. Choose between piecewise_const, centered, minmod, MC

bool runtime_dat

Set this to true to allow runtime advection states, which then can be used for doing runtime visualization.

double dt

current time step

double dt_init

initial timestep

double tmax

end time of advection

file _1DGrid.cpp
#include “_1DGrid.H
#include <>
file _1DGrid.H
#include <>
#include <>
#include <>
#include <>
file init_cond.H
#include <>
#include <>

Functions

std::vector<double> tophat(const std::vector<double> &domain)

Tophat initial condition Takes the physical domain as parameter and returns the state.

std::vector<double> sine(const std::vector<double> &domain)

Sine initial condition Takes the physical domain as parameter and returns the state.

std::vector<double> gaussian(const std::vector<double> &domain)

Gaussian initial condition Takes the physical domain as parameter and returns the state.

file runtime_test.cpp
#include “solver.H
#include “_1DGrid.H
#include “init_cond.H

Functions

int main()
file solver.cpp
#include “solver.H
#include <>
#include <>
#include <>
#include <>
#include <>

Functions

double minmod(double a, double b)
file solver.H
#include “_1DGrid.H
#include <>
#include <>
#include <>
file unit_test.cpp
#include “solver.H
#include “_1DGrid.H
#include “init_cond.H
#include <>

Functions

int main()
dir /home/runner/work/Mini_Projects/Mini_Projects/one_d_advection