Skip to content

Commit

Permalink
Add dedicated classes for each type of border condition
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-punko committed Oct 15, 2024
1 parent 79d5663 commit ead02c0
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 186 deletions.
7 changes: 7 additions & 0 deletions src/main/java/by/andd3dfx/math/pde/BorderCondition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package by.andd3dfx.math.pde;

/**
* Marker interface for border condition
*/
public interface BorderCondition {
}
17 changes: 17 additions & 0 deletions src/main/java/by/andd3dfx/math/pde/BorderConditionType1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package by.andd3dfx.math.pde;

/**
* Params for border condition type 1
*/
public class BorderConditionType1 implements BorderCondition {

/**
* Border condition U(t)
*
* @param t time
* @return U value in asked time moment on this border
*/
public double gU(double t) {
return 0;
}
}
17 changes: 17 additions & 0 deletions src/main/java/by/andd3dfx/math/pde/BorderConditionType2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package by.andd3dfx.math.pde;

/**
* Params for border condition type 2
*/
public class BorderConditionType2 implements BorderCondition {

/**
* Border condition dU_dt(t)
*
* @param t time
* @return dU_dt value in asked time moment on this border
*/
public double gdU_dx(double t) {
return 0;
}
}
24 changes: 24 additions & 0 deletions src/main/java/by/andd3dfx/math/pde/BorderConditionType3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package by.andd3dfx.math.pde;

/**
* Params for border condition type 3
*/
public class BorderConditionType3 implements BorderCondition {

/**
* TODO add description
* @param t time
* @return
*/
public double gTheta(double t) {
return 0;
}

/**
* TODO add description
* @return
*/
public double gH() {
return 0;
}
}
102 changes: 15 additions & 87 deletions src/main/java/by/andd3dfx/math/pde/Equation.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,26 @@
*/
public abstract class Equation {

protected int lbt;
protected int rbt;
protected double lh;
protected double rh;
protected Area area;
protected Matrix arr = new Matrix();
protected final BorderCondition leftBorderCondition;
protected final BorderCondition rightBorderCondition;

/**
* 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);

* @param x1 left space coordinate
* @param x2 right space coordinate
* @param t2 right time coordinate
* @param leftBorderCondition left border condition
* @param rightBorderCondition right border condition
*/
public Equation(double x1, double x2, double t2,
BorderCondition leftBorderCondition,
BorderCondition rightBorderCondition) {
area = new Area(new Interval(x1, x2, 1), new Interval(0, t2, 1));
this.lbt = lbt;
this.rbt = rbt;
this.lh = lH;
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);
this.leftBorderCondition = leftBorderCondition;
this.rightBorderCondition = rightBorderCondition;
}

/**
Expand All @@ -59,62 +42,6 @@ protected double gU0(double x) {
return 0;
}

/**
* Left border condition U(0,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(d,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(0,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(d,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;
}

/**
* Coefficient M(x,t,U) of equation for 2nd-order time derivative
*/
Expand Down Expand Up @@ -268,7 +195,8 @@ protected Matrix gUx(double x) {
/**
* Метод прогонки
*/
protected void progonka(int N, double[] A, double[] B, double[] C, double[] F, double m1, double n1, double m2, double n2, double[] Y) {
protected void progonka(double[] A, double[] B, double[] C, double[] F, double m1, double n1, double m2, double n2, double[] Y) {
int N = A.length;
double[] Alpha = new double[N + 1];
double[] Beta = new double[N + 1];

Expand Down
72 changes: 29 additions & 43 deletions src/main/java/by/andd3dfx/math/pde/HyperbolicEquation.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package by.andd3dfx.math.pde;

/**
* Parabolic equation:
* Hyperbolic equation:
* M(x,t,U)*d2U_dt2 + L(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)
*/
public class HyperbolicEquation extends Equation {
Expand All @@ -12,24 +12,13 @@ public class HyperbolicEquation extends 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
* @param leftBorderCondition left border condition
* @param rightBorderCondition right border condition
*/
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);
public HyperbolicEquation(double x1, double x2, double t2,
BorderCondition leftBorderCondition,
BorderCondition rightBorderCondition) {
super(x1, x2, t2, leftBorderCondition, rightBorderCondition);
}

/**
Expand All @@ -56,8 +45,10 @@ public void solve(double h, double tau) {
h2_tau = h2 / tau,
_2h2_tau2 = 2 * Math.pow(h / tau, 2);

/* TODO: need to determine what values should be populated into these [1,0] and [1,N] cells
arr.set(1, 0, gLU(tau)); //Задание граничных значений на первом слое
arr.set(1, N, gRU(tau));
*/

// Вычисление значения функции на первом слое для запуска разностной схемы
//
Expand Down Expand Up @@ -100,34 +91,29 @@ public void solve(double h, double tau) {
double Nu[] = new double[3];
double t = area.t().x(nj);

switch (lbt) {
case 1:
Nu[1] = gLU(t);
break;
case 2:
Mu[1] = 1;
Nu[1] = -h * gLdU_dx(t);
break;
case 3:
Mu[1] = 1 / (1 + h * lh);
Nu[1] = h * lh * gLTeta(t) / (1 + h * lh);
break; //Надо бы ускорить (вынесением)
if (leftBorderCondition instanceof BorderConditionType1 condition) {
Nu[1] = condition.gU(t);
} else if (leftBorderCondition instanceof BorderConditionType2 condition) {
Mu[1] = 1;
Nu[1] = -h * condition.gdU_dx(t);
} else if (leftBorderCondition instanceof BorderConditionType3 condition) {
var lh = condition.gH();
Mu[1] = 1 / (1 + h * lh);
Nu[1] = h * lh * condition.gTheta(t) / (1 + h * lh);
}
switch (rbt) {
case 1:
Nu[2] = gRU(t);
break;
case 2:
Mu[2] = 1;
Nu[2] = h * gRdU_dx(t);
break;
case 3:
Mu[2] = 1 / (1 - h * rh);
Nu[2] = -h * rh * gRTeta(t) / (1 - h * rh);
break;

if (rightBorderCondition instanceof BorderConditionType1 condition) {
Nu[2] = condition.gU(t);
} else if (rightBorderCondition instanceof BorderConditionType2 condition) {
Mu[2] = 1;
Nu[2] = h * condition.gdU_dx(t);
} else if (rightBorderCondition instanceof BorderConditionType3 condition) {
var rh = condition.gH();
Mu[2] = 1 / (1 - h * rh);
Nu[2] = -h * rh * condition.gTheta(t) / (1 - h * rh);
}

progonka(N, A, B, C, F, Mu[1], Nu[1], Mu[2], Nu[2], U);
progonka(A, B, C, F, Mu[1], Nu[1], Mu[2], Nu[2], U);
for (int i = 0; i <= N; i++) {
arr.set(nj, i, U[i]);
}
Expand Down
74 changes: 29 additions & 45 deletions src/main/java/by/andd3dfx/math/pde/ParabolicEquation.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,16 @@ 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
* @param x1 left space coordinate
* @param x2 right space coordinate
* @param t2 right time coordinate
* @param leftBorderCondition left border condition
* @param rightBorderCondition right border condition
*/
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);
public ParabolicEquation(double x1, double x2, double t2,
BorderCondition leftBorderCondition,
BorderCondition rightBorderCondition) {
super(x1, x2, t2, leftBorderCondition, rightBorderCondition);
}

/**
Expand Down Expand Up @@ -77,34 +66,29 @@ public void solve(double h, double tau) {
double Nu[] = new double[3];
double t = area.t().x(nj);

switch (lbt) {
case 1:
Nu[1] = gLU(t);
break;
case 2:
Mu[1] = 1;
Nu[1] = -h * gLdU_dx(t);
break;
case 3:
Mu[1] = 1 / (1 + h * lh);
Nu[1] = h * lh * gLTeta(t) / (1 + h * lh);
break;
if (leftBorderCondition instanceof BorderConditionType1 condition) {
Nu[1] = condition.gU(t);
} else if (leftBorderCondition instanceof BorderConditionType2 condition) {
Mu[1] = 1;
Nu[1] = -h * condition.gdU_dx(t);
} else if (leftBorderCondition instanceof BorderConditionType3 condition) {
var lh = condition.gH();
Mu[1] = 1 / (1 + h * lh);
Nu[1] = h * lh * condition.gTheta(t) / (1 + h * lh);
}
switch (rbt) {
case 1:
Nu[2] = gRU(t);
break;
case 2:
Mu[2] = 1;
Nu[2] = h * gRdU_dx(t);
break;
case 3:
Mu[2] = 1 / (1 - h * rh);
Nu[2] = -h * rh * gRTeta(t) / (1 - h * rh);
break;

if (rightBorderCondition instanceof BorderConditionType1 condition) {
Nu[2] = condition.gU(t);
} else if (rightBorderCondition instanceof BorderConditionType2 condition) {
Mu[2] = 1;
Nu[2] = h * condition.gdU_dx(t);
} else if (rightBorderCondition instanceof BorderConditionType3 condition) {
var rh = condition.gH();
Mu[2] = 1 / (1 - h * rh);
Nu[2] = -h * rh * condition.gTheta(t) / (1 - h * rh);
}

progonka(N, A, B, C, F, Mu[1], Nu[1], Mu[2], Nu[2], U);
progonka(A, B, C, F, Mu[1], Nu[1], Mu[2], Nu[2], U);
for (int i = 0; i <= N; i++) {
arr.set(nj, i, U[i]);
}
Expand Down
Loading

0 comments on commit ead02c0

Please sign in to comment.