Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make crate::pde::{kse,she} private #82

Merged
merged 6 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/swe.rs → examples/she.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn main() {
let interval = 100;
let step = 1000;

let eom = pde::SWE::new(n, l, 1.0, 6.0);
let eom = pde::SHE::new(n, l, 1.0, 6.0);
let mut pair = pde::Pair::new(n);
let n_coef = eom.model_size();
let teo = semi_implicit::DiagRK4::new(eom, dt);
Expand Down
21 changes: 15 additions & 6 deletions src/pde/kse.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
//! Kuramoto-Sivashinsky equation (KSE)
//!
//! KSE is a representative example of spatio-temporal chaos, or phase-turbulence.
//! See also the book ["Chemical Oscillations, Waves, and Turbulence"](http://www.springer.com/us/book/9783642696916), or related articles.

use fftw::types::c64;
use ndarray::*;
use std::f64::consts::PI;

use super::Pair;
use crate::traits::*;

/// One-dimensional Kuramoto-Sivashinsky equation with spectral-method
#[cfg_attr(doc, katexit::katexit)]
/// One-dimensional Kuramoto-Sivashinsky equation with spectral method.
///
/// $$
/// \frac{\partial u}{\partial t} + u\frac{\partial u}{\partial x} +
/// \frac{\partial^2 u}{\partial x^2} + \frac{\partial^4 u}{\partial x^4} = 0
/// $$
///
/// where $u = u(x, t)$ is real value field defined on $x \in [0, L]$
/// with cyclic boundary condition $u(x, t) = u(x + L, t)$.
///
/// Links
/// -----
/// - ["Chemical Oscillations, Waves, and Turbulence", Y. Kuramoto, Springer](http://www.springer.com/us/book/9783642696916)
///
pub struct KSE {
n: usize,
nf: usize,
Expand Down
8 changes: 4 additions & 4 deletions src/pde/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Example nonlinear PDEs
//! Example nonlinear PDEs with spectral (Fourier-Galerkin) method

pub mod kse;
pub mod she;
mod kse;
mod she;

pub use self::kse::KSE;
pub use self::she::SWE;
pub use self::she::SHE;

use fftw::array::*;
use fftw::plan::*;
Expand Down
37 changes: 26 additions & 11 deletions src/pde/she.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@ use std::f64::consts::PI;
use super::Pair;
use crate::traits::*;

/// One-dimensional Swift-Hohenberg equation with spectral-method
#[cfg_attr(doc, katexit::katexit)]
/// One-dimensional Swift-Hohenberg equation with spectral method
///
/// $$
/// \frac{\partial u}{\partial t} =
/// ru - \left(\partial_x^2 + q_c^2 \right)^2 u + u^2 - u^3
/// $$
///
/// where $u = u(x, t)$ is real value field defined on $x \in [0, L]$
/// with cyclic boundary condition $u(x, t) = u(x + L, t)$.
/// The nonlinear term $u^2 - u^3$ has several variation,
/// and sometimes called generalized Swift-Hohenberg equation for this case.
///
/// Links
/// -----
/// - ["Localized states in the generalized Swift-Hohenberg equation", J. Burke and E. Knobloch, PRE 73, 056211 (2006)](https://journals.aps.org/pre/abstract/10.1103/PhysRevE.73.056211)
///
#[derive(Clone)]
pub struct SWE {
n: usize,
pub struct SHE {
nf: usize,

/// System size (length of entire periodic domain)
length: f64,
/// Parameter for linear stablity
r: f64,
/// Length scale of instablity
Expand All @@ -22,23 +35,25 @@ pub struct SWE {
u: Pair,
}

impl ModelSpec for SWE {
impl ModelSpec for SHE {
type Scalar = c64;
type Dim = Ix1;
fn model_size(&self) -> usize {
self.nf
}
}

impl SWE {
impl SHE {
/// - `n`: Number of Fourier coefficients to be computed
/// - `length`: System size $L$
/// - `r`: Stability parameter $r$
/// - `lc`: Length scale of instablity, i.e. $q_c = 2\pi / l_c$
pub fn new(n: usize, length: f64, r: f64, lc: f64) -> Self {
let nf = n / 2 + 1;
let k0 = 2.0 * PI / length;
let qc = 2.0 * PI / lc;
SWE {
n,
SHE {
nf,
length,
r,
qc,
k: Array::from_iter((0..nf).map(|i| c64::new(0.0, k0 * i as f64))),
Expand All @@ -47,7 +62,7 @@ impl SWE {
}
}

impl SemiImplicit for SWE {
impl SemiImplicit for SHE {
fn nlin<'a, S>(
&mut self,
uf: &'a mut ArrayBase<S, Self::Dim>,
Expand Down
Binary file removed swe.png
Binary file not shown.