# Tag Info

5

The short answer is that you need $$\phi_{-1} = \phi_0$$ $$\phi_N = \phi_{N-1}$$ to impose $\nabla\phi=0$. A quick check by making the following change if idx == -1: idx = 0 elif idx == N: idx = N-1 in the code, you have posted shows that the average $\phi$ remains constant up to 14 decimal places. To see why this is the correct boundary condition ...

2

Here is a brute force solution that would work no matter what is the discontinuity and nonlinearity in $c(x,t)$. Write your PDE as a system of two: $\dot{y}=z\\ \dot{z}=c^2(x,t) y_{xx}$ Now, discretize it on a uniform spatial grid in x: $\vec{x}= [x_0, x_1,..., x_{n-1}] \\ \vec{y}= [y_0, y_1,..., y_{n-1}] \\ \vec{z}= [z_0, z_1,..., z_{n-1}] \\$ Now the ...

2

$c$ depending on time is not the issue. You will use an RK scheme which takes care of this. The issue is $c$ is discontinuous in $x$. I recommend SBP-SAT schemes for this. (1) Derive an energy equation at PDE level. (2) Search literature for SBP-SAT schemes which enforce interface conditions via SAT penalty terms, which are designed to mimic the energy ...

1

I would also like to point at MatlabAutoDiff, which supports sparse Jacobians. Have tried it myself: it is possible to compute large Jacobians (tried with N=1e5) in a small amount of time.

7

Julia has a whole ecosystem for generating sparsity patterns and doing sparse automatic differentiation in a way that mixes with scientific computing and machine learning (or scientific machine learning). Tools like SparseDiffTools.jl, ModelingToolkit.jl, and SparsityDetection.jl will do things like: Automatically find sparsity patterns from code Generate ...

0

$\delta_n \neq \lambda_n - \lambda_{n-1}$. It is actually defined in (2.8) and (I don't know why) $\delta_2 = \lambda_2 - \lambda_1$. You can confirm it by subtracting first three lines of (2.2) from (2.3) which will give you (2.6). Section 2.1 is the convergence analysis of the algorithm, so it is okay if $\delta_1$ is not explicitly defined. Actual ...

0

Yes, I think "better organisation of the codes" as you say is an important reason to use C++ and more generally Object Oriented Programming (OOP). Due to better organization of code, OOP can reuse code more effectively. Reusing code means less code overall means fewer bugs to fix. Another reason, in my opinion, is OOP allows us to express things ...

1

It's just a linear 1D problem, you can easily do implicit time stepping here so that numerical stability would not be a problem. The accuracy should not be an issue either since for such a simple problem you should be able to use any spatial resolution you need. More specifically, let the equation be discretized in space by any scheme, e.g., low-order ...

1

Just too long for a comment I'm a beginner with MPI too, and I'm using that book also. But it seems to me just devoted to the MPI approach. It just give a brief introduction to classes with an example or two, and it does not even talk about templates, which is something that you find in most scientific codes. This is what I'm doing now to learn: I started ...

Top 50 recent answers are included