Skip to content

Commit

Permalink
Features:
Browse files Browse the repository at this point in the history
	- Add State Response Snapshot #1 (1, 2)
	- Add State Response Snapshot #2 (3, 4)
	- CN Discretized Evolver 1D Solve #1 (13, 14)
	- CN Discretized Evolver 1D Solve #2 (15, 16)
	- R^1 State Response Snapshot - Shell (19, 20, 21)
	- R^1 State Response Snapshot - Array (22, 23, 24)
	- R^1 State Response Snapshot - Constructor (25, 26, 27)
	- R^1 Evolution Snapshot State Response (28, 29, 30)
	- R^1 State Response Snapshot Diagnostics #1 (34, 35, 36)
	- R^1 State Response Snapshot Diagnostics Time-shift Jacobian (37, 38, 39)
	- R^1 State Response Snapshot Diagnostics von-Neumann Stability Metric Array (40, 41)
	- R^1 State Response Snapshot Diagnostics Weighted Node Value Constraint Array (42, 43, 44)
	- R^1 State Response Snapshot Diagnostics - Constructor #1 (45, 46)
	- R^1 State Response Snapshot Diagnostics - Constructor #2 (47, 48)
	- R^1 State Response Snapshot Diagnostics #2 (49, 50, 51)
	- CN Discretized Evolver 1D Diagnostics On #1 (52, 53)
	- CN Discretized Evolver 1D Diagnostics On #2 (55, 56, 57)
	- CN Discretized Evolver 1D Diagnostics On #3 (58, 59, 60)
	- CN Discretized Evolver 1D Diagnostics On #4 (94, 95, 96)


Bug Fixes/Re-organization:

Samples:

	- Diffusion 1D Discretized Evolver #1 (5, 6, 7)
	- Diffusion 1D Discretized Evolver #2 (8, 9, 10)
	- Diffusion 1D Discretized Evolver #3 (11, 12)
	- Diffusion 1D Discretized Evolver #4 (17, 18)
	- Diffusion 1D Discretized Evolver #5 (31, 32, 33)
	- Diffusion 1D Discretized Evolver #6 (54)
	- Diffusion 1D Discretized Evolver #7 (61, 62, 63)
	- Diffusion 1D Discretized Evolver #8 (64, 65, 66)
	- Diffusion 1D Discretized Evolver #9 (67, 68, 69)
	- Diffusion 1D Discretized Evolver #10 (70, 71, 72)
	- Diffusion 1D Discretized Evolver #11 (73, 74, 75)
	- Diffusion 1D Discretized Evolver #12 (76, 77, 78)
	- Diffusion 1D Discretized Evolver #13 (79, 80, 81)
	- Diffusion 1D Discretized Evolver #14 (82, 83, 84)
	- Diffusion 1D Discretized Evolver #15 (85, 86, 87)
	- Diffusion 1D Discretized Evolver #16 (88, 89, 90)
	- Diffusion 1D Discretized Evolver #17 (91, 92, 93)
	- Diffusion 1D Discretized Evolver #18 (97, 98, 99)
	- Diffusion 1D Discretized Evolver #19 (100, 101, 102)
	- Diffusion 1D Discretized Evolver #20 (103, 104, 105)
	- Diffusion 1D Discretized Evolver #21 (106, 107, 108)
	- Diffusion 1D Discretized Evolver #22 (109, 110, 111)
	- Diffusion 1D Discretized Evolver #23 (112, 113, 114)
	- Diffusion 1D Discretized Evolver #24 (115, 116, 117)
	- Diffusion 1D Discretized Evolver #25 (118, 119, 120)


IdeaDRIP:
  • Loading branch information
Lakshmik committed Jul 1, 2024
1 parent e2f6936 commit 48d901a
Show file tree
Hide file tree
Showing 6 changed files with 801 additions and 56 deletions.
56 changes: 56 additions & 0 deletions ReleaseNotes/01_25_2024.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

Features:

- Add State Response Snapshot #1 (1, 2)
- Add State Response Snapshot #2 (3, 4)
- CN Discretized Evolver 1D Solve #1 (13, 14)
- CN Discretized Evolver 1D Solve #2 (15, 16)
- R^1 State Response Snapshot - Shell (19, 20, 21)
- R^1 State Response Snapshot - Array (22, 23, 24)
- R^1 State Response Snapshot - Constructor (25, 26, 27)
- R^1 Evolution Snapshot State Response (28, 29, 30)
- R^1 State Response Snapshot Diagnostics #1 (34, 35, 36)
- R^1 State Response Snapshot Diagnostics Time-shift Jacobian (37, 38, 39)
- R^1 State Response Snapshot Diagnostics von-Neumann Stability Metric Array (40, 41)
- R^1 State Response Snapshot Diagnostics Weighted Node Value Constraint Array (42, 43, 44)
- R^1 State Response Snapshot Diagnostics - Constructor #1 (45, 46)
- R^1 State Response Snapshot Diagnostics - Constructor #2 (47, 48)
- R^1 State Response Snapshot Diagnostics #2 (49, 50, 51)
- CN Discretized Evolver 1D Diagnostics On #1 (52, 53)
- CN Discretized Evolver 1D Diagnostics On #2 (55, 56, 57)
- CN Discretized Evolver 1D Diagnostics On #3 (58, 59, 60)
- CN Discretized Evolver 1D Diagnostics On #4 (94, 95, 96)


Bug Fixes/Re-organization:

Samples:

- Diffusion 1D Discretized Evolver #1 (5, 6, 7)
- Diffusion 1D Discretized Evolver #2 (8, 9, 10)
- Diffusion 1D Discretized Evolver #3 (11, 12)
- Diffusion 1D Discretized Evolver #4 (17, 18)
- Diffusion 1D Discretized Evolver #5 (31, 32, 33)
- Diffusion 1D Discretized Evolver #6 (54)
- Diffusion 1D Discretized Evolver #7 (61, 62, 63)
- Diffusion 1D Discretized Evolver #8 (64, 65, 66)
- Diffusion 1D Discretized Evolver #9 (67, 68, 69)
- Diffusion 1D Discretized Evolver #10 (70, 71, 72)
- Diffusion 1D Discretized Evolver #11 (73, 74, 75)
- Diffusion 1D Discretized Evolver #12 (76, 77, 78)
- Diffusion 1D Discretized Evolver #13 (79, 80, 81)
- Diffusion 1D Discretized Evolver #14 (82, 83, 84)
- Diffusion 1D Discretized Evolver #15 (85, 86, 87)
- Diffusion 1D Discretized Evolver #16 (88, 89, 90)
- Diffusion 1D Discretized Evolver #17 (91, 92, 93)
- Diffusion 1D Discretized Evolver #18 (97, 98, 99)
- Diffusion 1D Discretized Evolver #19 (100, 101, 102)
- Diffusion 1D Discretized Evolver #20 (103, 104, 105)
- Diffusion 1D Discretized Evolver #21 (106, 107, 108)
- Diffusion 1D Discretized Evolver #22 (109, 110, 111)
- Diffusion 1D Discretized Evolver #23 (112, 113, 114)
- Diffusion 1D Discretized Evolver #24 (115, 116, 117)
- Diffusion 1D Discretized Evolver #25 (118, 119, 120)


IdeaDRIP:
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

package org.drip.fdm.cranknicolson;

import java.util.HashMap;
import java.util.Map;

import org.drip.fdm.definition.EvolutionGrid1D;
import org.drip.fdm.definition.R1EvolutionSnapshot;
import org.drip.function.definition.RdToR1;
import org.drip.numerical.common.NumberUtil;
import org.drip.numerical.linearalgebra.StrictlyTridiagonalSolver;
Expand Down Expand Up @@ -127,6 +125,7 @@

public class CNDiscretizedEvolver1D
{
private boolean _diagnosticsOn = false;
private RdToR1 _diffusionFunction = null;
private EvolutionGrid1D _evolutionGrid1D = null;

Expand Down Expand Up @@ -164,19 +163,23 @@ private final double[][] zeroStateResponseTransitionMatrix()
*
* @param evolutionGrid1D R<sup>1</sup> Evolution Increment
* @param diffusionFunction Diffusion Function
* @param diagnosticsOn TRUE - "Diagnostics On" Mode
*
* @throws Exception Thrown if the Inputs are Invalid
*/

public CNDiscretizedEvolver1D (
final EvolutionGrid1D evolutionGrid1D,
final RdToR1 diffusionFunction)
final RdToR1 diffusionFunction,
final boolean diagnosticsOn)
throws Exception
{
if (null == (_evolutionGrid1D = evolutionGrid1D) || null == (_diffusionFunction = diffusionFunction))
{
throw new Exception ("CNDiscretizedEvolver1D Constructor => Invalid Inputs");
}

_diagnosticsOn = diagnosticsOn;
}

/**
Expand All @@ -201,6 +204,17 @@ public RdToR1 diffusionFunction()
return _diffusionFunction;
}

/**
* Retrieve the "Diagnostics On" Mode
*
* @return "Diagnostics On" Mode
*/

public boolean diagnosticsOn()
{
return _diagnosticsOn;
}

/**
* Compute the von Neumann Stability Number
*
Expand Down Expand Up @@ -266,7 +280,7 @@ public boolean stabilityCheck (
* @return Time Map of Factor Predictor/State Response Array
*/

public Map<Double, double[]> evolve (
public R1EvolutionSnapshot evolve (
final double[] startingStateResponseArray)
{
double[] factorPredictorArray = _evolutionGrid1D.factorPredictorArray();
Expand All @@ -277,23 +291,39 @@ public Map<Double, double[]> evolve (
return null;
}

double[] previousStateResponseArray = rhsArray();
double[] vonNeumannStabilityMetricArray = null;
R1EvolutionSnapshot r1EvolutionSnapshot = null;
double[] stateResponseArray = startingStateResponseArray;

if (_diagnosticsOn) {
vonNeumannStabilityMetricArray = new double[factorPredictorArray.length];
}

double[] timeArray = _evolutionGrid1D.timeArray();

for (int n = 0; n < factorPredictorArray.length; ++n) {
previousStateResponseArray[n] = startingStateResponseArray[n];
}
try {
r1EvolutionSnapshot = new R1EvolutionSnapshot (factorPredictorArray);
} catch (Exception e) {
e.printStackTrace();

Map<Double, double[]> timePredictorResponseArrayMap = new HashMap<Double, double[]>();
return null;
}

timePredictorResponseArrayMap.put (timeArray[0], startingStateResponseArray);
if (_diagnosticsOn) {
r1EvolutionSnapshot.addStateResponse (
timeArray[0],
startingStateResponseArray,
zeroStateResponseTransitionMatrix(),
rhsArray(),
vonNeumannStabilityMetricArray
);
} else {
r1EvolutionSnapshot.addStateResponse (timeArray[0], startingStateResponseArray);
}

for (int i = 1; i < timeArray.length; ++i) {
double[] rhsArray = rhsArray();

double[] updatedStateResponseArray = null;

double[][] stateResponseTransitionMatrix = zeroStateResponseTransitionMatrix();

for (int n = 0; n < factorPredictorArray.length; ++n) {
Expand All @@ -317,28 +347,32 @@ public Map<Double, double[]> evolve (
return null;
}

if (_diagnosticsOn) {
vonNeumannStabilityMetricArray[n] = vonNeumannStabilityNumber;
}

if (0 != n && factorPredictorArray.length - 1 != n) {
stateResponseTransitionMatrix[n][n - 1] = -1. * vonNeumannStabilityNumber;
stateResponseTransitionMatrix[n][n] = 1. + 2. * vonNeumannStabilityNumber;
stateResponseTransitionMatrix[n][n + 1] = -1. * vonNeumannStabilityNumber;
rhsArray[n] = vonNeumannStabilityNumber * previousStateResponseArray[n - 1] +
(1. - 2. * vonNeumannStabilityNumber) * previousStateResponseArray[n] +
vonNeumannStabilityNumber * previousStateResponseArray[n + 1];
rhsArray[n] = vonNeumannStabilityNumber * stateResponseArray[n - 1] +
(1. - 2. * vonNeumannStabilityNumber) * stateResponseArray[n] +
vonNeumannStabilityNumber * stateResponseArray[n + 1];
} else if (factorPredictorArray.length - 1 == n) {
stateResponseTransitionMatrix[n][n - 1] = -1. * vonNeumannStabilityNumber;
stateResponseTransitionMatrix[n][n] = 1. + 2. * vonNeumannStabilityNumber;
rhsArray[n] = vonNeumannStabilityNumber * previousStateResponseArray[n - 1] +
(1. - 2. * vonNeumannStabilityNumber) * previousStateResponseArray[n];
rhsArray[n] = vonNeumannStabilityNumber * stateResponseArray[n - 1] +
(1. - 2. * vonNeumannStabilityNumber) * stateResponseArray[n];
} else {
stateResponseTransitionMatrix[n][n] = 1. + 2. * vonNeumannStabilityNumber;
stateResponseTransitionMatrix[n][n + 1] = -1. * vonNeumannStabilityNumber;
rhsArray[n] = (1. - 2. * vonNeumannStabilityNumber) * previousStateResponseArray[n] +
vonNeumannStabilityNumber * previousStateResponseArray[n + 1];
rhsArray[n] = (1. - 2. * vonNeumannStabilityNumber) * stateResponseArray[n] +
vonNeumannStabilityNumber * stateResponseArray[n + 1];
}
}

try {
updatedStateResponseArray = new StrictlyTridiagonalSolver (
stateResponseArray = new StrictlyTridiagonalSolver (
stateResponseTransitionMatrix,
rhsArray
).forwardSweepBackSubstitution();
Expand All @@ -348,13 +382,19 @@ public Map<Double, double[]> evolve (
return null;
}

for (int n = 0; n < factorPredictorArray.length; ++n) {
previousStateResponseArray[n] = updatedStateResponseArray[n];
if (_diagnosticsOn) {
r1EvolutionSnapshot.addStateResponse (
timeArray[i],
stateResponseArray,
stateResponseTransitionMatrix,
rhsArray,
vonNeumannStabilityMetricArray
);
} else {
r1EvolutionSnapshot.addStateResponse (timeArray[i], stateResponseArray);
}

timePredictorResponseArrayMap.put (timeArray[i], updatedStateResponseArray);
}

return timePredictorResponseArrayMap;
return r1EvolutionSnapshot;
}
}
84 changes: 80 additions & 4 deletions src/main/java/org/drip/fdm/definition/R1EvolutionSnapshot.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
public class R1EvolutionSnapshot
{
private double[] _factorPredictorArray = null;
private Map<Double, double[]> _timeStateResponseArrayMap = null;
private Map<Double, R1StateResponseSnapshot> _timeStateResponseMap = null;

/**
* <i>R1EvolutionSnapshot</i> Constructor
Expand All @@ -146,7 +146,7 @@ public R1EvolutionSnapshot (
throw new Exception ("R1EvolutionSnapshot Constructor => Invalid Inputs");
}

_timeStateResponseArrayMap = new TreeMap<Double, double[]>();
_timeStateResponseMap = new TreeMap<Double, R1StateResponseSnapshot>();
}

/**
Expand All @@ -166,8 +166,84 @@ public double[] factorPredictorArray()
* @return Time Map of Realized State Response Array
*/

public Map<Double, double[]> timeStateResponseArrayMap()
public Map<Double, R1StateResponseSnapshot> timeStateResponseMap()
{
return _timeStateResponseArrayMap;
return _timeStateResponseMap;
}

/**
* Add the State Response Snapshot Array corresponding to the Time Node
*
* @param time Time Node
* @param stateResponseArray Array of State Responses
*
* @return TRUE - The State Response Snapshot Array corresponding to the Time Node successfully added
*/

public boolean addStateResponse (
final double time,
final double[] stateResponseArray)
{
if (!NumberUtil.IsValid (time) ||
null == stateResponseArray ||
stateResponseArray.length != _factorPredictorArray.length)
{
return false;
}

try {
_timeStateResponseMap.put (time, new R1StateResponseSnapshot (stateResponseArray));
} catch (Exception e) {
e.printStackTrace();

return false;
}

return true;
}

/**
* Add the State Response Snapshot Array corresponding to the Time Node
*
* @param time Time Node
* @param stateResponseArray Array of State Responses
* @param timeShiftJacobian State Response Factor Node Time Shift Jacobian Matrix
* @param weightedNodeValueConstraintArray Weighted Node Value Constraint Array
* @param vonNeumannStabilityMetricArray von-Neumann Stability Metric Array
*
* @return TRUE - The State Response Snapshot Array corresponding to the Time Node successfully added
*/

public boolean addStateResponse (
final double time,
final double[] stateResponseArray,
final double[][] timeShiftJacobian,
final double[] weightedNodeValueConstraintArray,
final double[] vonNeumannStabilityMetricArray)
{
if (!NumberUtil.IsValid (time) ||
null == stateResponseArray ||
stateResponseArray.length != _factorPredictorArray.length)
{
return false;
}

try {
_timeStateResponseMap.put (
time,
new R1StateResponseSnapshotDiagnostics (
stateResponseArray,
timeShiftJacobian,
weightedNodeValueConstraintArray,
vonNeumannStabilityMetricArray
)
);
} catch (Exception e) {
e.printStackTrace();

return false;
}

return true;
}
}
Loading

0 comments on commit 48d901a

Please sign in to comment.