Skip to content

Commit

Permalink
Add test for ParabolicEquation (need to add analytic solution)
Browse files Browse the repository at this point in the history
Remove Main class
  • Loading branch information
andrei-punko committed Oct 14, 2024
1 parent 5278898 commit 79d5663
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
15 changes: 0 additions & 15 deletions src/main/java/by/andd3dfx/Main.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/java/by/andd3dfx/math/pde/Equation.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected void prepare(double h, double tau) {
* @param t time
*/
public void sUt(String fileName, double t) {
sUt(fileName, new double[]{0, t});
sUt(fileName, new double[]{t});
}

/**
Expand Down Expand Up @@ -202,7 +202,7 @@ public void sUt(String fileName, double t[]) {
* @param x space coordinate
*/
public void sUx(String fileName, double x) {
sUx(fileName, new double[]{0, x});
sUx(fileName, new double[]{x});
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/by/andd3dfx/math/pde/ParabolicEquation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Parabolic equation:
* M(x,t,U)*dU_dt = K(x,t,U)*d2U_dt2 + V(x,t,U)*dU_dt + F(x,t,U) where U = U(x,t)
* M(x,t,U)*dU_dt = dU(K(x,t,U)*dU_dt)_dt + V(x,t,U)*dU_dt + F(x,t,U) where U = U(x,t)
*/
public class ParabolicEquation extends Equation {

Expand Down
45 changes: 45 additions & 0 deletions src/test/java/by/andd3dfx/math/pde/ParabolicEquationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package by.andd3dfx.math.pde;

import by.andd3dfx.math.Interval;
import by.andd3dfx.util.FileUtil;
import org.junit.jupiter.api.Test;

class ParabolicEquationTest {

private final double C_LEFT = 1.0;
private final double THICKNESS = 1e-3; // 1mm
private final double TIME = 1; // 1sec
private final double DIFFUSION_COEFFICIENT = 1e-4;

@Test
void solve() {
var h = THICKNESS / 1000.0;
var tau = TIME / 1000.0;

var diffusionEquation = new ParabolicEquation(0, THICKNESS, TIME) {
@Override
protected double gK(double x, double t, double U) {
return DIFFUSION_COEFFICIENT;
}

@Override
protected double gLU(double t) {
return C_LEFT;
}
};

diffusionEquation.solve(h, tau);

diffusionEquation.sUt("./build/res-numeric.txt", TIME);
FileUtil.saveFunc(
new Interval(0, THICKNESS, h),
(x) -> analyticSolution(x, TIME),
"./build/res-analytic.txt"
);
}

private double analyticSolution(double x, double t) {
// TODO add analytic solution
return 0;
}
}

0 comments on commit 79d5663

Please sign in to comment.