34 questions
2
votes
0
answers
59
views
Having problems computing PDE Residuals
I'm computing PDE residuals for The_Well datasets (e.g. turbulent_radiative_layer_2D and shear_flow) using finite differences, but the residuals are much larger than I expect. The data are generated ...
1
vote
2
answers
125
views
Simple 1 D dispersion equation numerical solution
I am new to coding and trying to solve a simple 1D dispersion equation.
The equation and boundary conditions:
adC/dx = bd^2C/dx^2
x = hj, C = C0; x = - inf, C =0
The analytical solution is
C = C0 * ...
3
votes
1
answer
112
views
Where does SciPy's adaptive step size method for finite differences originate?
Inside the KrylovJacobian class from SciPy, there is this method:
def _update_diff_step(self):
mx = abs(self.x0).max()
mf = abs(self.f0).max()
self.omega = self.rdiff * max(1, mx) / max(1, ...
1
vote
1
answer
103
views
Implementation of Acoustic Wave equation progagation is not scaling at all beyond two threads
In the following OpenMP C code I was expecting that using tempfield could help to write to p1 in one cache line, which in my case is 64 bytes. With two threads I got almost 2x speedup in comparison to ...
0
votes
1
answer
328
views
Fluid Dynamics - Lid driven cavity flow- why is only the first row updated, while I iterate over all grid cells?
I have to simulate a lid driven cavity flow. The idea is as follows:
Initialize boundary conditions
Update stream function (using discretized version, update only if the convergence condition is ...
1
vote
0
answers
95
views
Solving Nonlinear Boundary Value Problem with Constraints
I want to solve the following boundary value problem
where S, k_i, x_f, α_1, and θ are known parameters. We are trying to solve for h(x), p, and θ_d.
My idea was to use finite differences to create a ...
1
vote
0
answers
63
views
RK4 acoustic wave equation
I am trying to modify a code to include a runge kutta time stepping scheme. The original code was not written by me but my motive is to eliminate the pygame library and make it as easy as possible ...
1
vote
1
answer
308
views
2D finite difference scheme of reaction diffusion equation
I want to visualize the solution of the following partial differential equation:
u_t=u_xx+u_yy+f(u)
At different times, such as u(t=1) and u(t=3). I use a finite difference scheme and the following ...
0
votes
1
answer
1k
views
Basic 1D advection equation in python using the finite difference method
Hi I am trying to code a simple advection equation in python using the finite difference upwind method. I have looked online to find a simple example of this but the codes I have found are a little ...
0
votes
1
answer
116
views
Python loop issue: finite volume/difference iteration
I'm having trouble understanding why this for loop is not working. Full code is also below.
I want to calculate the temperature at future time points (j+1) based on the temperatures at the previous ...
0
votes
1
answer
60
views
How to write a solver for the vibration ODE using the current version of Devito?
I'm reading the devito_book/fdm-jupyter-book/notebooks/01_vib/vib_undamped.ipynb and the code in it seems not compatible with devito 4.8.3.
So I tried to rewrite it as:
import numpy as np
from devito ...
0
votes
0
answers
507
views
Generating Turing Patterns Using Finite Difference on Reaction Diffusion Equations
For a school project, I am implementing in Python a finite difference method to numerically solve the following system of reaction diffusion PDE:
I have so far implemented the following:
import numpy ...
0
votes
1
answer
128
views
Optimizing NumPy finite differences via chain rule
Consider the following code:
x = np.array([1, 5, 6, 10]) # an unstructured coordinate
f = x**2 # function value on the points x
grad1 = np.gradient(f, x) # df/dx
...
0
votes
1
answer
371
views
Is there a way to compute gradients on unstructured coordinates with Numpy?
I have a 3D array of data A, with shape (NX, NY, NZ) in the x, y, and z dimensions, respectively.
I want to find the gradient of A in the y dimension. This can be done easily with NumPy:
dAdy = np....
1
vote
0
answers
344
views
Applying Neumann BC on 2D Diffusion Equation on Python using Finite-Difference Method
Given a diffusion equation:
$$\frac{\partial S}{\partial t} = c \Big(\frac{\partial^2 S}{\partial x^2} + \frac{\partial^2 S}{\partial y^2} \Big)$$
with homogeneous Neumann Boundary Condition
$$\frac{\...
1
vote
1
answer
184
views
How to calculate the discrete First Order Derivative of a function f using a Matrix Differential Operator in Matlab?
I want to calculate a discrete approximation of df/dx in Matlab using a vector f representing the function and a Matrix D representing a differential operator. f in this example is a simple sine wave ...
1
vote
0
answers
86
views
Eigen solution for a simple sparse system of equations is wrong. Why?
I can't figure out why this code is not working:
#include <Eigen/Sparse>
#include <vector>
#include <iostream>
#include <Eigen/IterativeLinearSolvers>
// u''(x)= 1
// Boundary ...
0
votes
0
answers
261
views
Nonlinear coupled BVP using relaxation method (finite-difference)
It's my first time posting here and it seems like latex is not working, so I posted some part as an image.
Reference for Relaxation method: Computational Physics by Veseley
I have employed the two ...
1
vote
2
answers
821
views
How can I calculate the second-order derivative of a vector using finite differences if the interval is non-constant?
Say I have vectors x and y and want to calculate the second derivative of y with respect to x using finite differences.
I'd do
x <- rnorm(2000)
y <- x^2
y = y[order(x)]
x = sort(x)
dydx = diff(...
0
votes
0
answers
146
views
Scalability of a Parallel MPI based Poisson Solver using Finite Difference Scheme
I am developing a MPI based parallel numerical solver for a Laplace equation subjected to Dirichlet Boundary condition using Finite Difference method.I have taken a square computational domain with a ...
1
vote
1
answer
612
views
How to use finite difference method for non-uniform grid in python?
I have a function f = dp/de (variation in pressure as a function of variation in energy) and I would like to calculate this derivative with finite differences. I have a list for the p values and a ...
1
vote
0
answers
75
views
Why does changing the boundary conditions cause the finite difference algorithm to diverge?
I wrote a finite difference algorithm to solve the wave equation which is derived here.
When I ran my code, the plotted graphs of the numerical and analytical solution deviated, which is the problem I ...
1
vote
1
answer
557
views
Solving a tridiagonal matrix in python
I have been looking at numerical methods to solve differential equations for chemical reactions. Usually I put the differential equation into a tridiagonal matrix using finite difference method, and ...
0
votes
1
answer
184
views
How to do finite difference integration in python?
I want to solve a differential equation of a given function S. First, I integrate a function using 4th-order runge kutta:
def rk4_step(r, u, h, f, *args):
k1 = h * f(r, u, *args)
k2 = h * f(r +...
2
votes
1
answer
411
views
Finite difference method for solving the Klein-Gordon equation in Matlab
I am trying to numerically solve the Klein-Gordon equation that can be found here. To make sure I solved it correctly, I am comparing it with an analytical solution that can be found on the same link. ...
1
vote
0
answers
190
views
Finite difference scheme in Matlab
I am trying to implement a finite difference scheme for KdV equation in MATLAB, and I have most of the code ready, except for approximation at the first level using initial condition. It was suggested ...
1
vote
2
answers
394
views
1D Finite Difference Wave Equation Cuda
I am new to Cuda. I am trying to solve the wave equation with the initial condition in the form of the Ricky momentum. The performance of the code is 12 GFlops, although my GPU performance is 3900. ...
0
votes
0
answers
89
views
Solving a coupled differential equations system using time splitting
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write ...
0
votes
1
answer
535
views
Why is SymPy's linsolve function not able to solve for the second to the last variable in this problem?
(TLDR: SymPy's linsolve function is unable to solve the system of linear equations, generated from applying the finite difference method to an ODE BVP, when you pass the equations as a pure Python ...
0
votes
0
answers
270
views
Negative values obtained in the solution of the 1D advection-dispersion equation using FD method
I am trying to solve the 1D ADE
This is my code so far:
clc; clear; close all
%Input parameters
Ao = 1; %Initial value
L = 0.08; %Column length [m]
nx = 40; %spatial gridpoints
...
0
votes
1
answer
2k
views
Plotting 3D array of values as coloured points on a grid
I have an (X,Y,Z) numpy array that describes every point inside a box. I would like to do a 3D plot of this data where the colour of the point at [x,y,z] is the value of that point in the array
I have ...
0
votes
0
answers
170
views
index 400 is out of bounds for axis 0 with size 400 - Finite Difference Method in Python
I understand why this error is occurring. I am using finite differences to find solutions with a numpy array of size n = 400 and the term in question produces a term i + 2 which for i in range(1, n - ...
1
vote
0
answers
496
views
Implementing the Lanczos algorithm into C++ for a quantum anharmonic oscillator
Firstly, I would like to mention that I am a complete beginner when it comes to coding, let alone C++, so bear with me, as I need complete guidance. My task is to implement the Lanczos algorithm for ...
0
votes
0
answers
590
views
Backward difference and central difference in R
I know that in R diff(x, lag = L, differences = K) gives you the lag-L K-th order forward difference. But it only allows for positive lags, so only can give you the forward differences, not backward ...