Skip to content

datahandler

Abstract Base Interface for Neural Network Data Handling in PDEs.

This module provides the base interface for handling data transformations and tensor conversions required for neural network-based PDE solvers. It defines the essential structure for managing various data types involved in finite element computations.

The implementation supports
  • Finite element data processing
  • Dirichlet boundary condition handling
  • Test point generation and management
  • Bilinear parameter tensor conversion
  • Sensor data generation and handling
  • Parameter management for inverse problems
Key classes
  • DataHandler: Abstract base class for PDE data handling
Note

All implementations assume double precision (float64) numpy arrays as inputs, with optional conversion to float32 for computational efficiency.

Dependencies
  • abc: For abstract base class functionality
  • tensorflow: For tensor operations
  • numpy: For numerical arrays
Authors
  • Thivin Anandh (https://thivinanandh.github.io/)
Versions
  • 27-Dec-2024 (Version 0.1): Initial Implementation

DataHandler

Abstract base class for PDE solution data handling and tensor conversion.

This class defines the interface for managing and converting various data types required in neural network-based PDE solvers. It handles transformation between numpy arrays and tensorflow tensors, and manages different aspects of the finite element computation data.

Attributes:

Name Type Description
fespace

Finite element space object containing mesh and element info

domain

Domain object containing geometric and boundary information

dtype

TensorFlow data type for tensor conversion (float32/float64)

Example

class MyDataHandler(DataHandler): ... def init(self, fespace, domain): ... super().init(fespace, domain, tf.float32) ... ... def get_dirichlet_input(self): ... # Implementation ... pass ... ... def get_test_points(self): ... # Implementation ... pass

Note

Concrete implementations must override: - get_dirichlet_input() - get_test_points() - get_bilinear_params_dict_as_tensors() - get_sensor_data() - get_inverse_params()

All methods should handle type conversion between numpy arrays and tensorflow tensors consistently.

Source code in scirex/core/sciml/fastvpinns/data/datahandler.py
class DataHandler:
    """Abstract base class for PDE solution data handling and tensor conversion.

    This class defines the interface for managing and converting various data types
    required in neural network-based PDE solvers. It handles transformation between
    numpy arrays and tensorflow tensors, and manages different aspects of the finite
    element computation data.

    Attributes:
        fespace: Finite element space object containing mesh and element info
        domain: Domain object containing geometric and boundary information
        dtype: TensorFlow data type for tensor conversion (float32/float64)

    Example:
        >>> class MyDataHandler(DataHandler):
        ...     def __init__(self, fespace, domain):
        ...         super().__init__(fespace, domain, tf.float32)
        ...
        ...     def get_dirichlet_input(self):
        ...         # Implementation
        ...         pass
        ...
        ...     def get_test_points(self):
        ...         # Implementation
        ...         pass

    Note:
        Concrete implementations must override:
        - get_dirichlet_input()
        - get_test_points()
        - get_bilinear_params_dict_as_tensors()
        - get_sensor_data()
        - get_inverse_params()

        All methods should handle type conversion between numpy arrays
        and tensorflow tensors consistently.
    """

    def __init__(self, fespace, domain, dtype):
        """
        Constructor for the DataHandler class

        Args:
            fespace (FESpace2D): The FESpace2D object.
            domain (Domain2D): The Domain2D object.
            dtype (tf.DType): The tensorflow dtype to be used for all the tensors.

        Returns:
            None
        """

        self.fespace = fespace
        self.domain = domain
        self.dtype = dtype

    @abstractmethod
    def get_dirichlet_input(self) -> tuple:
        """
        This function will return the input for the Dirichlet boundary data

        Args:
            None

        Returns:
            The Dirichlet boundary data as a tuple of tensors
        """

    @abstractmethod
    def get_test_points(self):
        """
        Get the test points for the given domain.

        Args:
            None

        Returns:
            The test points as a tensor
        """

    @abstractmethod
    def get_bilinear_params_dict_as_tensors(self, function) -> dict:
        """
        Accepts a function from example file and converts all the values into tensors of the given dtype

        Args:
            function (function): The function from the example file which returns the bilinear parameters dictionary

        Returns:
            The bilinear parameters dictionary with all the values converted to tensors
        """

    @abstractmethod
    def get_sensor_data(self, exact_sol, num_sensor_points, mesh_type, file_name=None):
        """
        Accepts a function from example file and converts all the values into tensors of the given dtype

        Args:
            exact_sol (function): The exact solution function
            num_sensor_points (int): The number of sensor points
            mesh_type (str): The type of mesh
            file_name (str): The file name to save the sensor data

        Returns:
            The sensor data as a tensor
        """

    @abstractmethod
    def get_inverse_params(self, inverse_params_dict_function):
        """
        Accepts a function from example file and converts all the values into tensors of the given dtype

        Args:
            inverse_params_dict_function (function): The function from the example file which returns the inverse parameters dictionary

        Returns:
            The inverse parameters dictionary with all the values converted to tensors
        """

__init__(fespace, domain, dtype)

Constructor for the DataHandler class

Parameters:

Name Type Description Default
fespace FESpace2D

The FESpace2D object.

required
domain Domain2D

The Domain2D object.

required
dtype DType

The tensorflow dtype to be used for all the tensors.

required

Returns:

Type Description

None

Source code in scirex/core/sciml/fastvpinns/data/datahandler.py
def __init__(self, fespace, domain, dtype):
    """
    Constructor for the DataHandler class

    Args:
        fespace (FESpace2D): The FESpace2D object.
        domain (Domain2D): The Domain2D object.
        dtype (tf.DType): The tensorflow dtype to be used for all the tensors.

    Returns:
        None
    """

    self.fespace = fespace
    self.domain = domain
    self.dtype = dtype

get_bilinear_params_dict_as_tensors(function) abstractmethod

Accepts a function from example file and converts all the values into tensors of the given dtype

Parameters:

Name Type Description Default
function function

The function from the example file which returns the bilinear parameters dictionary

required

Returns:

Type Description
dict

The bilinear parameters dictionary with all the values converted to tensors

Source code in scirex/core/sciml/fastvpinns/data/datahandler.py
@abstractmethod
def get_bilinear_params_dict_as_tensors(self, function) -> dict:
    """
    Accepts a function from example file and converts all the values into tensors of the given dtype

    Args:
        function (function): The function from the example file which returns the bilinear parameters dictionary

    Returns:
        The bilinear parameters dictionary with all the values converted to tensors
    """

get_dirichlet_input() abstractmethod

This function will return the input for the Dirichlet boundary data

Returns:

Type Description
tuple

The Dirichlet boundary data as a tuple of tensors

Source code in scirex/core/sciml/fastvpinns/data/datahandler.py
@abstractmethod
def get_dirichlet_input(self) -> tuple:
    """
    This function will return the input for the Dirichlet boundary data

    Args:
        None

    Returns:
        The Dirichlet boundary data as a tuple of tensors
    """

get_inverse_params(inverse_params_dict_function) abstractmethod

Accepts a function from example file and converts all the values into tensors of the given dtype

Parameters:

Name Type Description Default
inverse_params_dict_function function

The function from the example file which returns the inverse parameters dictionary

required

Returns:

Type Description

The inverse parameters dictionary with all the values converted to tensors

Source code in scirex/core/sciml/fastvpinns/data/datahandler.py
@abstractmethod
def get_inverse_params(self, inverse_params_dict_function):
    """
    Accepts a function from example file and converts all the values into tensors of the given dtype

    Args:
        inverse_params_dict_function (function): The function from the example file which returns the inverse parameters dictionary

    Returns:
        The inverse parameters dictionary with all the values converted to tensors
    """

get_sensor_data(exact_sol, num_sensor_points, mesh_type, file_name=None) abstractmethod

Accepts a function from example file and converts all the values into tensors of the given dtype

Parameters:

Name Type Description Default
exact_sol function

The exact solution function

required
num_sensor_points int

The number of sensor points

required
mesh_type str

The type of mesh

required
file_name str

The file name to save the sensor data

None

Returns:

Type Description

The sensor data as a tensor

Source code in scirex/core/sciml/fastvpinns/data/datahandler.py
@abstractmethod
def get_sensor_data(self, exact_sol, num_sensor_points, mesh_type, file_name=None):
    """
    Accepts a function from example file and converts all the values into tensors of the given dtype

    Args:
        exact_sol (function): The exact solution function
        num_sensor_points (int): The number of sensor points
        mesh_type (str): The type of mesh
        file_name (str): The file name to save the sensor data

    Returns:
        The sensor data as a tensor
    """

get_test_points() abstractmethod

Get the test points for the given domain.

Returns:

Type Description

The test points as a tensor

Source code in scirex/core/sciml/fastvpinns/data/datahandler.py
@abstractmethod
def get_test_points(self):
    """
    Get the test points for the given domain.

    Args:
        None

    Returns:
        The test points as a tensor
    """