Skip to content

Commit

Permalink
Features:
Browse files Browse the repository at this point in the history
	- Core PDE Forms: Orders/Dimensions (17, 18)
	- von Neumann 1D Stability Validator #1 (19, 20, 21)
	- von Neumann 1D Stability Validator #2 (22, 23, 24)
	- von Neumann 1D Stability Validator Time Step (25, 26)
	- von Neumann 1D Stability Validator Space Step (27, 28)
	- von Neumann 1D Stability Validator #3 (29, 30, 31)
	- Crank Nicolson Scheme Usage Stable (32, 33, 34)
	- von Neumann 1D Stability Validator Diffusion Coefficient (35, 36, 37)
	- von Neumann nD Stability Validator #1 (40, 41, 42)
	- von Neumann nD Stability Validator Time Step (43, 44)
	- von Neumann nD Stability Validator Space Step (45, 46)
	- von Neumann nD Stability Validator Diffusion Coefficient (47, 48)
	- von Neumann nD Stability Validator #2 (49, 50, 51)
	- von Neumann nD Stability Validator #3 (52, 53, 54)
	- von Neumann nD Stability Validator #4 (55, 56, 57)
	- Second Order 1D PDE Shell (58, 59, 60)
	- Second Order 1D State Concentration Function (61, 62, 63)
	- Second Order 1D State Evolution Function (64, 65, 66)
	- Second Order 1D Constructor (67, 68, 69)
	- Second Order 1D State Time Differential (70, 71, 72)
	- von Neumann Stability Validator Shell (73, 74)
	- von Neumann Stability Validator Time Step (75, 76)
	- von Neumann Stability Validator Diffusion Coefficient (77, 78)
	- von Neumann Stability Validator Constructor (79, 80)
	- von Neumann 1D Stability Validator Extension (81, 82)
	- von Neumann Stability Validator Crank-Nicolson Validation (83, 84, 85)
	- von Neumann 1D Stability Validator Hypotenuse (86)
	- von Neumann 1D Stability Validator Clean Up (87, 88)
	- von Neumann nD Stability Validator #5 (89, 90, 91)
	- von Neumann nD Stability Validator #6 (92, 93, 94)
	- von Neumann nD Stability Validator #7 (95, 96)
	- FDM Numerical Evolution Scheme Shell (99, 100)
	- Numerical Evolution Scheme von Neumann Stability Validator (101, 102)
	- Numerical Evolution Scheme Second Order 1D PDE (107, 108)
	- Numerical Evolution Scheme Constructor (109, 110, 111)
	- Euler Forward Difference State Evolver Scheme (112, 113)
	- Euler Backward Difference State Evolver Scheme (114, 115, 116)
	- Crank Nicolson State Evolver Scheme (117, 118)
	- Diffusion State Space/Time Function (119, 120)


Bug Fixes/Re-organization:

	- Sherman Morrison Triangular Solver Revamp (3)
	- Ryabenkii Tsynkov Triangular Solver Revamp (6, 7, 8)
	- Ryabenkii Tsynkov Solver Tridiagonal Matrix (9)
	- Ryabenkii Tsynkov Solver uRHS Array (10)
	- Ryabenkii Tsynkov Solver vRHS Array (11, 12)
	- Ryabenkii Tsynkov Solver U Solution (13)
	- Ryabenkii Tsynkov Solver V Solution (14)
	- PDE Foundation Rename to Definition (38, 39)
	- Finite Difference PDE Evolver Schemes (97, 98)
	- Second Order 1D Numerical Evolution (103, 104)
	- Second Order 1D PDE (105, 106)


Samples:

	- Non-Periodic Triangular Solver Suite (1, 2)
	- Periodic Sherman Morrison Triangular Solver (4, 5)
	- Periodic Ryabenkii Tsynkov Triangular Solver (15, 16)


IdeaDRIP:
  • Loading branch information
Lakshmik committed Jun 29, 2024
1 parent 071149c commit 00988b9
Show file tree
Hide file tree
Showing 9 changed files with 1,108 additions and 0 deletions.
Binary file not shown.
93 changes: 93 additions & 0 deletions IdeaDRIP/NumericalAnalysis/NA_v0.03
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

--------------------------
#1 - Successive Over-Relaxation
--------------------------
--------------------------
1.1) Successive Over-Relaxation Method for A.x = b; A - n x n square matrix, x - unknown vector, b - RHS vector
1.2) Decompose A into Diagonal, Lower, and upper Triangular Matrices; A = D + L + U
1.3) SOR Scheme uses omega input
1.4) Forward subsitution scheme to iteratively determine the x_i's
1.5) SOR Scheme Linear System Convergence: Inputs A and D, Jacobi Iteration Matrix Spectral Radius, omega
- Construct Jacobi Iteration Matrix: C_Jacobian = I - (Inverse D) A
- Convergence Verification #1: Ensure that Jacobi Iteration Matrix Spectral Radius is < 1
- Convergence Verification #2: Ensure omega between 0 and 2
- Optimal Relaxation Parameter Expression in terms of Jacobi Iteration Matrix Spectral Radius
- Omega Based Convergence Rate Expression
- Gauss-Seidel omega = 1; corresponding Convergence Rate
- Optimal Omega Convergence Rate
1.6) Generic Iterative Solver Method:
- Inputs: Iterator Function(x) and omega
- Unrelaxed Iterated variable: x_n+1 = f(x_n)
- SOR Based Iterated variable: x_n+1 = (1-omega).x_n + omega.f(x_n)
- SOR Based Iterated variable for Unknown Vector x: x_n+1 = (1-omega).x_n + omega.(L_star inverse)(b - U.x_n)
--------------------------

--------------------------
#2 - Successive Over-Relaxation
--------------------------
--------------------------
2.1) SSOR Algorithm - Inputs; A, omega, and gamma
- Decompose into D and L
- Pre-conditioner Matrix: Expression from SSOR
- Finally SSOR Iteration Formula
--------------------------

----------------------------
#3 - Tridiagonal matrix algorithm
----------------------------
----------------------------
3.1) Is Tridiagonal Check
3.2) Core Algorithm:
- C Prime's and D Prime's Calculation
- Back Substitution for the Result
- Modified better Book-keeping algorithm
3.3) Sherman-Morrison Algorithm:
- Choice of gamma
- Construct Tridiagonal B from A and gamma
- u Column from gamma and c_n
- v Column from a_1 and gamma
- Solve for y from By=d
- Solve for q from Bq=u
- Use Sherman Morrison Formula to extract x
3.4) Alternate Boundary Condition Algorithm:
- Solve Au=d for u
- Solve Av={-a_2, 0, ..., -c_n} for v
- Full solution is x_i = u_i + x_1 * v_i
- x_1 if computed using formula
----------------------------

--------------------------
#4 - Crank–Nicolson method
--------------------------
--------------------------
4.1) von Neumann Stability Validator - Inputs; time-step, diffusivity, space step
- 1D => time step * diffusivity / space step ^2 < 0.5
- nD => time step * diffusivity / (space step hypotenuse) ^ 2 < 0.5
4.2) Set up:
- Input: Spatial variable x
- Input: Time variable t
- Inputs: State variable u, du/dx, d2u/dx2 - all at time t
- Second Order, 1D => du/dt = F (u, x, t, du/dx, d2u/dx2)
4.3) Finite Difference Evolution Scheme:
- Time Step delta_t, space step delta_x
- Forward Difference: F calculated at x
- Backward Difference: F calculated at x + delta_x
- Crank Nicolson: Average of Forward/Backward
4.4) 1D Diffusion:
- Inputs: 1D von Neumann Stability Validator, Number of time/space steps
- Time Index n, Space Index i
- Explicit Tridiagonal form for the discretization - State concentration at n+1 given state concentration at n
- Non-linear diffusion coefficient:
- Linearization across x_i and x_i+1
- Quasi-explicit forms accommodation
4.5) 2D Diffusion:
- Inputs: 2D von Neumann Stability Validator, Number of time/space steps
- Time Index n, Space Index i, j
- Explicit Tridiagonal form for the discretization - State concentration at n+1 given state concentration at n
- Explicit Solution using the Alternative Difference Implicit Scheme
4.6) Extension to Iterative Solver Schemes above:
- Input: State Space "velocity" dF/du
- Input: State "Step Size" delta_u
- Fixed Point Iterative Location Scheme
- Relaxation Scheme based Robustness => Input: Relaxation Parameter
--------------------------
67 changes: 67 additions & 0 deletions ReleaseNotes/01_22_2024.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

Features:

- Core PDE Forms: Orders/Dimensions (17, 18)
- von Neumann 1D Stability Validator #1 (19, 20, 21)
- von Neumann 1D Stability Validator #2 (22, 23, 24)
- von Neumann 1D Stability Validator Time Step (25, 26)
- von Neumann 1D Stability Validator Space Step (27, 28)
- von Neumann 1D Stability Validator #3 (29, 30, 31)
- Crank Nicolson Scheme Usage Stable (32, 33, 34)
- von Neumann 1D Stability Validator Diffusion Coefficient (35, 36, 37)
- von Neumann nD Stability Validator #1 (40, 41, 42)
- von Neumann nD Stability Validator Time Step (43, 44)
- von Neumann nD Stability Validator Space Step (45, 46)
- von Neumann nD Stability Validator Diffusion Coefficient (47, 48)
- von Neumann nD Stability Validator #2 (49, 50, 51)
- von Neumann nD Stability Validator #3 (52, 53, 54)
- von Neumann nD Stability Validator #4 (55, 56, 57)
- Second Order 1D PDE Shell (58, 59, 60)
- Second Order 1D State Concentration Function (61, 62, 63)
- Second Order 1D State Evolution Function (64, 65, 66)
- Second Order 1D Constructor (67, 68, 69)
- Second Order 1D State Time Differential (70, 71, 72)
- von Neumann Stability Validator Shell (73, 74)
- von Neumann Stability Validator Time Step (75, 76)
- von Neumann Stability Validator Diffusion Coefficient (77, 78)
- von Neumann Stability Validator Constructor (79, 80)
- von Neumann 1D Stability Validator Extension (81, 82)
- von Neumann Stability Validator Crank-Nicolson Validation (83, 84, 85)
- von Neumann 1D Stability Validator Hypotenuse (86)
- von Neumann 1D Stability Validator Clean Up (87, 88)
- von Neumann nD Stability Validator #5 (89, 90, 91)
- von Neumann nD Stability Validator #6 (92, 93, 94)
- von Neumann nD Stability Validator #7 (95, 96)
- FDM Numerical Evolution Scheme Shell (99, 100)
- Numerical Evolution Scheme von Neumann Stability Validator (101, 102)
- Numerical Evolution Scheme Second Order 1D PDE (107, 108)
- Numerical Evolution Scheme Constructor (109, 110, 111)
- Euler Forward Difference State Evolver Scheme (112, 113)
- Euler Backward Difference State Evolver Scheme (114, 115, 116)
- Crank Nicolson State Evolver Scheme (117, 118)
- Diffusion State Space/Time Function (119, 120)


Bug Fixes/Re-organization:

- Sherman Morrison Triangular Solver Revamp (3)
- Ryabenkii Tsynkov Triangular Solver Revamp (6, 7, 8)
- Ryabenkii Tsynkov Solver Tridiagonal Matrix (9)
- Ryabenkii Tsynkov Solver uRHS Array (10)
- Ryabenkii Tsynkov Solver vRHS Array (11, 12)
- Ryabenkii Tsynkov Solver U Solution (13)
- Ryabenkii Tsynkov Solver V Solution (14)
- PDE Foundation Rename to Definition (38, 39)
- Finite Difference PDE Evolver Schemes (97, 98)
- Second Order 1D Numerical Evolution (103, 104)
- Second Order 1D PDE (105, 106)


Samples:

- Non-Periodic Triangular Solver Suite (1, 2)
- Periodic Sherman Morrison Triangular Solver (4, 5)
- Periodic Ryabenkii Tsynkov Triangular Solver (15, 16)


IdeaDRIP:
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@

package org.drip.fdm.definition;

/*
* -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*/

/*!
* Copyright (C) 2025 Lakshmi Krishnamurthy
*
* This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
* asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
* analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
* equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
* numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
* graph builder/navigator, and computational support.
*
* https://lakshmidrip.github.io/DROP/
*
* DROP is composed of three modules:
*
* - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
* - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
* - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
*
* DROP Product Core implements libraries for the following:
* - Fixed Income Analytics
* - Loan Analytics
* - Transaction Cost Analytics
*
* DROP Portfolio Core implements libraries for the following:
* - Asset Allocation Analytics
* - Asset Liability Management Analytics
* - Capital Estimation Analytics
* - Exposure Analytics
* - Margin Analytics
* - XVA Analytics
*
* DROP Computational Core implements libraries for the following:
* - Algorithm Support
* - Computation Support
* - Function Analysis
* - Graph Algorithm
* - Model Validation
* - Numerical Analysis
* - Numerical Optimizer
* - Spline Builder
* - Statistical Learning
*
* Documentation for DROP is Spread Over:
*
* - Main => https://lakshmidrip.github.io/DROP/
* - Wiki => https://github.com/lakshmiDRIP/DROP/wiki
* - GitHub => https://github.com/lakshmiDRIP/DROP
* - Repo Layout Taxonomy => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
* - Javadoc => https://lakshmidrip.github.io/DROP/Javadoc/index.html
* - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
* - Release Versions => https://lakshmidrip.github.io/DROP/version.html
* - Community Credits => https://lakshmidrip.github.io/DROP/credits.html
* - Issues Catalog => https://github.com/lakshmiDRIP/DROP/issues
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* <i>SecondOrder1DNumericalEvolution</i> implements key Second Order Finite Difference Schemes for
* R<sup>1</sup> State Space Evolution. The References are:
*
* <br><br>
* <ul>
* <li>
* Datta, B. N. (2010): <i>Numerical Linear Algebra and Applications 2<sup>nd</sup> Edition</i>
* <b>SIAM</b> Philadelphia, PA
* </li>
* <li>
* Cebeci, T. (2002): <i>Convective Heat Transfer</i> <b>Horizon Publishing</b> Hammond, IN
* </li>
* <li>
* Crank, J., and P. Nicolson (1947): A Practical Method for Numerical Evaluation of Solutions of
* Partial Differential Equations of the Heat Conduction Type <i>Proceedings of the Cambridge
* Philosophical Society</i> <b>43 (1)</b> 50-67
* </li>
* <li>
* Thomas, J. W. (1995): <i>Numerical Partial Differential Equations: Finite Difference Methods</i>
* <b>Springer-Verlag</b> Berlin, Germany
* </li>
* <li>
* Wikipedia (2023): Alternating-direction implicit method
* https://en.wikipedia.org/wiki/Alternating-direction_implicit_method
* </li>
* <li>
* Wikipedia (2024): Crank–Nicolson method
* https://en.wikipedia.org/wiki/Crank%E2%80%93Nicolson_method
* </li>
* </ul>
*
* <br><br>
* <ul>
* <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ComputationalCore.md">Computational Core Module</a></li>
* <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/NumericalAnalysisLibrary.md">Numerical Analysis Library</a></li>
* <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/pde/README.md">Numerical Solution Schemes for PDEs</a></li>
* <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/fdm/definition/README.md">Finite Difference PDE Evolver Schemes</a></li>
* </ul>
* <br><br>
*
* @author Lakshmi Krishnamurthy
*/

public class SecondOrder1DNumericalEvolution
{
private SecondOrder1DPDE _secondOrder1DPDE = null;
private VonNeumann1DStabilityValidator _vonNeumann1DStabilityValidator = null;

/**
* <i>SecondOrder1DNumericalEvolution</i> Constructor
*
* @param secondOrder1DPDE Second Order R<sup>1</sup> State Space Evolution PDE
* @param vonNeuman1DStabilityValidator Space/Time von Neumann R<sup>1</sup> Stability Validator
*
* @throws Exception Thrown if the Inputs are Invalid
*/

public SecondOrder1DNumericalEvolution (
final SecondOrder1DPDE secondOrder1DPDE,
final VonNeumann1DStabilityValidator vonNeumann1DStabilityValidator)
throws Exception
{
if (null == (_secondOrder1DPDE= secondOrder1DPDE) ||
(null == (_vonNeumann1DStabilityValidator = vonNeumann1DStabilityValidator)))
{
throw new Exception ("SecondOrder1DNumericalEvolution Constructor => Invalid Inputs");
}
}

/**
* Retrieve the Second Order R<sup>1</sup> State Space Evolution PDE
*
* @return Second Order R<sup>1</sup> State Space Evolution PDE
*/

public SecondOrder1DPDE secondOrder1DPDE()
{
return _secondOrder1DPDE;
}

/**
* Retrieve the Space/Time von Neumann R<sup>1</sup> Stability Validator
*
* @return Space/Time von Neumann R<sup>1</sup> Stability Validator
*/

public VonNeumannStabilityValidator vonNeumann1DStabilityValidator()
{
return _vonNeumann1DStabilityValidator;
}

/**
* Compute the State Increment using the Euler Forward Difference State Evolver Scheme
*
* @param time Time
* @param space Space
*
* @return State Increment using the Euler Forward Difference State Evolver Scheme
*
* @throws Exception Thrown if the Inputs are Invalid
*/

public double eulerForwardDifferenceScheme (
final double time,
final double space)
throws Exception
{
return _secondOrder1DPDE.timeDifferential (time, space);
}

/**
* Compute the State Increment using the Euler Backward Difference State Evolver Scheme
*
* @param time Time
* @param space Space
*
* @return State Increment using the Euler Backward Difference State Evolver Scheme
*
* @throws Exception Thrown if the Inputs are Invalid
*/

public double eulerBackwardDifferenceScheme (
final double time,
final double space)
throws Exception
{
return _secondOrder1DPDE.timeDifferential (
time,
space + _vonNeumann1DStabilityValidator.r1SpaceStep()
);
}

/**
* Compute the State Increment using the Crank-Nicolson State Evolver Scheme
*
* @param time Time
* @param space Space
*
* @return State Increment using the Crank-Nicolson State Evolver Scheme
*
* @throws Exception Thrown if the Inputs are Invalid
*/

public double crankNicolsonDifferenceScheme (
final double time,
final double space)
throws Exception
{
return 0.5 * (
_secondOrder1DPDE.timeDifferential (time, space) + _secondOrder1DPDE.timeDifferential (
time,
space + _vonNeumann1DStabilityValidator.r1SpaceStep()
)
);
}
}
Loading

0 comments on commit 00988b9

Please sign in to comment.