Skip to content

Commit

Permalink
Add javadocs for Equation* classes
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-punko committed Oct 14, 2024
1 parent 7ffea44 commit 8af3bad
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ In Russian - algorithm has name "Progonka" (метод прогонки).

## Usage notes

Should be added later, at this moment - just read provided code
Check classes javadocs
116 changes: 104 additions & 12 deletions src/main/java/by/andd3dfx/math/pde/Equation.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import by.andd3dfx.math.Matrix;
import by.andd3dfx.util.FileUtil;

/**
* Base class. Used to avoid code duplication in child classes
*/
public abstract class Equation {

protected int lbt;
Expand All @@ -14,6 +17,17 @@ public abstract class Equation {
protected Area area;
protected Matrix arr = new Matrix();

/**
* Create equation
*
* @param x1 left space coordinate
* @param x2 right space coordinate
* @param t2 right time coordinate
* @param lbt type of left border condition (1/2/3)
* @param rbt type of right border condition (1/2/3)
* @param lH coefficient for 3rd border condition type of left border
* @param rH coefficient for 3rd border condition type of right border
*/
public Equation(double x1, double x2, double t2, int lbt, int rbt, double lH, double rH) {
assert (lbt >= 1 && lbt <= 3 && rbt >= 1 && rbt <= 3 && lH > 0 && rH > 0);

Expand All @@ -24,34 +38,79 @@ public Equation(double x1, double x2, double t2, int lbt, int rbt, double lH, do
this.rh = rH;
}

/**
* Create equation
*
* @param x1 left space coordinate
* @param x2 right space coordinate
* @param t2 right time coordinate
*/
public Equation(double x1, double x2, double t2) {
this(x1, x2, t2, 1, 1, 1, 1);
}

/**
* Initial condition U0(x)
*
* @param x coordinate
* @return U value in asked coordinate
*/
protected double gU0(double x) {
return 0;
}

/**
* Left border condition U_left(t) (for 1st border type)
*
* @param t time
* @return U value in asked time moment on left border
*/
protected double gLU(double t) {
return 0;
}

/**
* Right border condition U_right(t) (for 1st border type)
*
* @param t time
* @return U value in asked time moment on right border
*/
protected double gRU(double t) {
return 0;
}

/**
* Left border condition dU_dt_left(t) (for 2nd border type)
*
* @param t time
* @return dU_dt value in asked time moment on left border
*/
protected double gLdU_dx(double t) {
return 0;
}

/**
* Right border condition dU_dt_right(t) (for 2nd border type)
*
* @param t time
* @return dU_dt value in asked time moment on right border
*/
protected double gRdU_dx(double t) {
return 0;
}

/**
* Coefficient for 3rd border type of left border
* TODO: provide better description
*/
protected double gLTeta(double t) {
return 0;
}

/**
* Coefficient for 3rd border type of right border
* TODO: provide better description
*/
protected double gRTeta(double t) {
return 0;
}
Expand All @@ -72,6 +131,12 @@ protected double gF(double x, double t, double U) {
return 0;
}

/**
* Solve equation using provided space & time steps
*
* @param h space step
* @param tau time step
*/
public void solve(double h, double tau) {
assert (h > 0 && tau > 0); // установка шагов по пространственной и временной координатам
area.x().reborn(area.x().left(), area.x().right(), h);
Expand All @@ -83,41 +148,65 @@ public void solve(double h, double tau) {
}
}

/**
* Save data U(x) for asked time moment
*
* @param fileName file name
* @param t time
*/
public void sUt(String fileName, double t) {
sUt(fileName, new double[]{0, t}, 1);
sUt(fileName, new double[]{0, t});
}

public void sUt(String fileName, double t[], int size) {
for (var i = 0; i < size; i++) {
/**
* Save data U(x) for asked time moments. So in result we get some set of slices for several time moments
*
* @param fileName file name
* @param t times array
*/
public void sUt(String fileName, double t[]) {
for (var t_i : t) {
var tInterval = area.t();
assert (tInterval.left() <= t[i] && t[i] <= tInterval.right());
assert (tInterval.left() <= t_i && t_i <= tInterval.right());
}

var sb = new StringBuilder();
for (var i = 0; i <= area.x().n(); i++) {
sb.append(area.x().x(i));
for (int j = 0; j < size; j++) {
sb.append(" " + arr.data(area.t().i(t[j]), i));
for (var t_i : t) {
sb.append(" " + arr.data(area.t().i(t_i), i));
}
sb.append("\n");
}
FileUtil.serialize(fileName, sb);
}

/**
* Save data U(t) for asked space coordinate x
*
* @param fileName file name
* @param x space coordinate
*/
public void sUx(String fileName, double x) {
sUx(fileName, new double[]{0, x}, 1);
sUx(fileName, new double[]{0, x});
}

public void sUx(String fileName, double x[], int size) {
for (int i = 0; i < size; i++) {
assert (area.x().left() <= x[i] && x[i] <= area.x().right());
/**
* Save data U(t) for asked space coordinates. So in result we get some set of slices for several space coordinates
*
* @param fileName file name
* @param x coordinates array
*/
public void sUx(String fileName, double x[]) {
for (var x_i : x) {
assert (area.x().left() <= x_i && x_i <= area.x().right());
}

var sb = new StringBuilder();
for (int i = 0; i <= area.t().n(); i++) {
sb.append(area.t().x(i));
for (int j = 0; j < size; j++) {
sb.append(" " + arr.data(i, area.x().i(x[j])));
for (var x_i : x) {
sb.append(" " + arr.data(i, area.x().i(x_i)));
}
sb.append("\n");
}
Expand Down Expand Up @@ -162,6 +251,9 @@ protected Matrix gUx(double x) {
return gUx(area.x().i(x));
}

/**
* Метод прогонки
*/
protected void progonka(int N, double[] A, double[] B, double[] C, double[] F, double m1, double n1, double m2, double n2, double[] Y) {
double[] Alpha = new double[N + 1];
double[] Beta = new double[N + 1];
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/by/andd3dfx/math/pde/HyperbolicEquation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,38 @@

public class HyperbolicEquation extends Equation {

/**
* Create hyperbolic equation
*
* @param x1 left space coordinate
* @param x2 right space coordinate
* @param t2 right time coordinate
* @param lbt type of left border condition (1/2/3)
* @param rbt type of right border condition (1/2/3)
* @param lH coefficient for 3rd border condition type of left border
* @param rH coefficient for 3rd border condition type of right border
*/
public HyperbolicEquation(double x1, double x2, double t2, int lbt, int rbt, double lH, double rH) {
super(x1, x2, t2, lbt, rbt, lH, rH);
}

/**
* Create hyperbolic equation
*
* @param x1 left space coordinate
* @param x2 right space coordinate
* @param t2 right time coordinate
*/
public HyperbolicEquation(double x1, double x2, double t2) {
this(x1, x2, t2, 1, 1, 1, 1);
}

/**
* Solve equation using provided space & time steps
*
* @param h space step
* @param tau time step
*/
@Override
public void solve(double h, double tau) {
super.solve(h, tau);
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/by/andd3dfx/math/pde/ParabolicEquation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,38 @@

public class ParabolicEquation extends Equation {

/**
* Create parabolic equation
*
* @param x1 left space coordinate
* @param x2 right space coordinate
* @param t2 right time coordinate
* @param lbt type of left border condition (1/2/3)
* @param rbt type of right border condition (1/2/3)
* @param lH coefficient for 3rd border condition type of left border
* @param rH coefficient for 3rd border condition type of right border
*/
public ParabolicEquation(double x1, double x2, double t2, int lbt, int rbt, double lH, double rH) {
super(x1, x2, t2, lbt, rbt, lH, rH);
}

/**
* Create parabolic equation
*
* @param x1 left space coordinate
* @param x2 right space coordinate
* @param t2 right time coordinate
*/
public ParabolicEquation(double x1, double x2, double t2) {
super(x1, x2, t2);
}

/**
* Solve equation using provided space & time steps
*
* @param h space step
* @param tau time step
*/
@Override
public void solve(double h, double tau) {
super.solve(h, tau);
Expand Down

0 comments on commit 8af3bad

Please sign in to comment.