A library for numerical solution of partial differential equations (PDE) using finite difference method and Thomas algorithm
L(x,t,U)*∂U/∂t = ∂U( K(x,t,U)*∂U/∂x )/∂x + V(x,t,U)*∂U/∂x + F(x,t,U)
where U = U(x,t) is the unknown function (temperature, concentration, etc)
M(x,t,U)*∂²U/∂t² = ∂U( K(x,t,U)*∂U/∂x )/∂x + V(x,t,U)*∂U/∂x + F(x,t,U)
where U = U(x,t) is the unknown function (displacement of string, etc)
- Dirichlet (function value at the boundary)
- Neumann (derivative value at the boundary)
- Robin (linear combination of function value and its derivative)
- Finite difference method for derivative approximation
- Thomas algorithm for solving tridiagonal systems of linear equations
- JDK 21
- Gradle (embedded in the project)
./gradlew clean build./gradlew clean javadocCheck ./build/doc/javadoc folder
Online documentation is available here
- Describes diffusion, heat conduction, and other dissipative processes
- Characterized by the presence of only first-order time derivative
- Solution is defined on the space-time domain
[x1,x2]×[0,t2]
- Describes wave processes and oscillations
- Characterized by the presence of second-order time derivative
- Solution is defined on the space-time domain
[x1,x2]×[0,t2]
DirichletBorderCondition class
- Specifies function value at the boundary:
U(x1,t) = g1(t)orU(x2,t) = g2(t)
- Specifies derivative value at the boundary:
∂U/∂x(x1,t) = g1(t)or∂U/∂x(x2,t) = g2(t)
- Specifies linear combination of function value and its derivative:
∂U/∂x(x1,t) = h*(U(x1,t) - Theta(t))or∂U/∂x(x2,t) = h*(U(x2,t) - Theta(t))
- Approximates derivatives using finite differences
- Transforms PDE into a system of linear equations
- Uses the Thomas algorithm to solve the resulting system
- Efficient algorithm for solving tridiagonal systems of linear equations
- Time complexity O(n), where n is the system size
- Diffusion problem with Dirichlet boundary conditions
- Diffusion problem with Neumann boundary conditions
- Heat transfer problem with mixed Dirichlet+Robin boundary conditions
<dependency>
<groupId>io.github.andrei-punko</groupId>
<artifactId>pde-solvers</artifactId>
<version>1.0.3</version>
</dependency>implementation 'io.github.andrei-punko:pde-solvers:1.0.3'import io.github.andreipunko.math.pde.border.DirichletBorderCondition;
import io.github.andreipunko.math.pde.equation.ParabolicEquation;
import io.github.andreipunko.util.FileUtil;
class ParabolicEquationSolution {
private final double C_MAX = 100.0; // Max concentration
private final double L = 0.001; // Thickness of plate, m
private final double TIME = 1; // Investigated time, sec
private final double D = 1e-9; // Diffusion coefficient
private final double h = L / 100.0; // Space step
private final double tau = TIME / 100.0; // Time step
public void solve() {
var diffusionEquation = buildParabolicEquation();
var solution = new ParabolicEquationSolver()
.solve(diffusionEquation, h, tau);
var numericU = solution.gUt(TIME);
FileUtil.save(numericU, "./build/parabolic1-eqn-solution.txt", true);
}
/**
* Parabolic equation definition
*/
private ParabolicEquation buildParabolicEquation() {
var leftBorderCondition = new DirichletBorderCondition();
var rightBorderCondition = new DirichletBorderCondition();
return new ParabolicEquation(0, L, TIME, leftBorderCondition, rightBorderCondition) {
@Override
public double gK(double x, double t, double U) {
return D;
}
@Override
public double gU0(double x) {
return getC0(x);
}
};
}
/**
* Initial concentration profile
*/
private double getC0(double x) {
x /= L;
if (0.4 <= x && x <= 0.5) {
return C_MAX * (10 * x - 4);
}
if (0.5 <= x && x <= 0.6) {
return C_MAX * (-10 * x + 6);
}
return 0;
}
}Check README
See instruction
See instruction