Record Class Solution<E extends Equation>

java.lang.Object
java.lang.Record
io.github.andreipunko.math.pde.solver.Solution<E>
Type Parameters:
E - the type of equation that was solved
Record Components:
equation - the partial differential equation that was solved
area - the space-time domain where the solution was found
matrix - grid values of the solution (same layout as above); must not be null

public record Solution<E extends Equation>(E extends Equation equation, Area area, Matrix2D matrix) extends Record
Numerical PDE solution on a space-time domain: equation(), area(), and grid values matrix() (Matrix2D — rows are time layers, columns are spatial nodes).
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Solution(E equation, Area area, Matrix2D matrix)
    Validates record components before the instance is created.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the area record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the equation record component.
    gUt(double t)
    Retrieves a spatial slice of the solution at a specified time moment.
    gUt(int it)
    Retrieves a spatial slice of the solution at a specified time layer index.
    gUx(double x)
    Retrieves a temporal slice of the solution at a specified spatial coordinate.
    gUx(int ix)
    Retrieves a temporal slice of the solution at a specified spatial column index.
    final int
    Returns a hash code value for this object.
    Returns the value of the matrix record component.
    void
    sUt(String fileName, double t)
    Saves solution data U(x) for a single time moment to a file.
    void
    sUt(String fileName, double[] t)
    Saves solution data U(x,t) for specified time moments to a file.
    void
    sUx(String fileName, double x)
    Saves solution data U(t) for a single spatial coordinate to a file.
    void
    sUx(String fileName, double[] x)
    Saves solution data U(x,t) for specified spatial coordinates to a file.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Solution

      public Solution(E equation, Area area, Matrix2D matrix)
      Validates record components before the instance is created.
      Throws:
      IllegalArgumentException - if equation, area or matrix is null
  • Method Details

    • sUt

      public void sUt(String fileName, double[] t) throws IOException
      Saves solution data U(x,t) for specified time moments to a file. Creates a set of spatial slices of the solution at different time points. The file starts with #-comment lines describing columns, then numeric rows in US locale (FileUtil.formatDouble(double)). Each data line contains spatial coordinates followed by solution values at different time moments. All spatial columns of matrix() are written (same extent as gUt(int) for a fixed time layer).

      Each t is mapped to a time-layer index via Area.ti(double) (see Interval.i(double)): values are read from the nearest grid time level at or to the left of t, with no interpolation.

      Parameters:
      fileName - name of the file to save the data
      t - array of time moments to save
      Throws:
      IllegalArgumentException - if t is null, fileName is null, or any time is outside the solution domain
      IOException - if an I/O error occurs writing the file
    • sUt

      public void sUt(String fileName, double t) throws IOException
      Saves solution data U(x) for a single time moment to a file. Creates a spatial slice of the solution at the specified time. Time is resolved on the grid like sUt(String, double[]) (via Area.ti(double)).
      Parameters:
      fileName - name of the file to save the data
      t - time moment to save
      Throws:
      IllegalArgumentException - if fileName is null or the time moment is outside the solution domain
      IOException - if an I/O error occurs writing the file
    • sUx

      public void sUx(String fileName, double[] x) throws IOException
      Saves solution data U(x,t) for specified spatial coordinates to a file. Creates a set of temporal slices of the solution at different spatial points. The file starts with #-comment lines describing columns, then numeric rows in US locale (FileUtil.formatDouble(double)). Each data line contains time coordinates followed by solution values at different spatial points. All time rows of matrix() are written (same extent as gUx(int) for a fixed spatial column).

      Each x is mapped to a spatial column index via Area.xi(double) (see Interval.i(double)): values are read from the nearest grid point at or to the left of x, with no interpolation.

      Parameters:
      fileName - name of the file to save the data
      x - array of spatial coordinates to save
      Throws:
      IllegalArgumentException - if x is null, fileName is null, or any coordinate is outside the solution domain
      IOException - if an I/O error occurs writing the file
    • sUx

      public void sUx(String fileName, double x) throws IOException
      Saves solution data U(t) for a single spatial coordinate to a file. Creates a temporal slice of the solution at the specified spatial point. Position is resolved on the grid like sUx(String, double[]) (via Area.xi(double)).
      Parameters:
      fileName - name of the file to save the data
      x - spatial coordinate to save
      Throws:
      IllegalArgumentException - if fileName is null or the spatial coordinate is outside the solution domain
      IOException - if an I/O error occurs writing the file
    • gUt

      public MatrixXY gUt(double t)
      Retrieves a spatial slice of the solution at a specified time moment. Returns a matrix containing spatial coordinates and corresponding solution values. Uses Area.ti(double) to pick the time layer (nearest grid time at or to the left of t), no interpolation.
      Parameters:
      t - time moment to get the slice for
      Returns:
      MatrixXY containing the spatial slice of the solution
      Throws:
      IllegalArgumentException - if the time moment is outside the solution domain
    • gUt

      public MatrixXY gUt(int it)
      Retrieves a spatial slice of the solution at a specified time layer index. Returns a matrix containing spatial coordinates and corresponding solution values.
      Parameters:
      it - row index in matrix() (time layer; 0 <= it < matrix.getM())
      Returns:
      MatrixXY containing the spatial slice of the solution
      Throws:
      IllegalArgumentException - if the time layer index is out of bounds
    • gUx

      public MatrixXY gUx(double x)
      Retrieves a temporal slice of the solution at a specified spatial coordinate. Returns a matrix containing time coordinates and corresponding solution values. Uses Area.xi(double) to pick the spatial column (nearest grid point at or to the left of x), no interpolation.
      Parameters:
      x - spatial coordinate to get the slice for
      Returns:
      MatrixXY containing the temporal slice of the solution
      Throws:
      IllegalArgumentException - if the spatial coordinate is outside the solution domain
    • gUx

      public MatrixXY gUx(int ix)
      Retrieves a temporal slice of the solution at a specified spatial column index. Returns a matrix containing time coordinates and corresponding solution values.
      Parameters:
      ix - column index in matrix() (spatial node; 0 <= ix < matrix.getN())
      Returns:
      MatrixXY containing the temporal slice of the solution
      Throws:
      IllegalArgumentException - if the spatial column index is out of bounds
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • equation

      public E equation()
      Returns the value of the equation record component.
      Returns:
      the value of the equation record component
    • area

      public Area area()
      Returns the value of the area record component.
      Returns:
      the value of the area record component
    • matrix

      public Matrix2D matrix()
      Returns the value of the matrix record component.
      Returns:
      the value of the matrix record component