-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
64 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 29 additions & 35 deletions
64
src/UQpy/surrogates/polynomial_chaos/physics_informed/PdePCE.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,59 @@ | ||
import numpy as np | ||
|
||
from UQpy.surrogates.polynomial_chaos.physics_informed.PdeData import PdeData | ||
from typing import Callable | ||
from UQpy.surrogates.polynomial_chaos.PolynomialChaosExpansion import PolynomialChaosExpansion | ||
|
||
class PdePCE: | ||
def __init__(self, pde_data, | ||
pde_functions, | ||
pde_source=None, | ||
boundary_conditions=None, | ||
boundary_condition_function=None, | ||
virtual_points_function=None, | ||
nonlinear=False): | ||
def __init__(self, pde_data: PdeData, | ||
pde_basis: Callable, | ||
pde_source: Callable = None, | ||
boundary_conditions_evaluate: Callable = None, | ||
boundary_conditions_sampling: Callable = None, | ||
virtual_points_sampling: Callable = None, | ||
nonlinear: bool = False): | ||
""" | ||
Class containing information about PDE needed for physics-informed PCE | ||
:param pde_data: an object of the :code:`UQpy` :class:`.PdeData` class | ||
:param pde_functions: pde defined in basis functions | ||
:param pde_basis: pde defined in basis functions | ||
:param pde_source: source term of pde | ||
:param boundary_conditions: evaluation of boundary conditions for estimation of an error | ||
:param boundary_condition_function: function for sampling of boundary conditions | ||
:param virtual_points_function: function for sampling of virtual samples | ||
:param boundary_conditions_evaluate: evaluation of boundary conditions for estimation of an error | ||
:param boundary_conditions_sampling: function for sampling of boundary conditions | ||
:param virtual_points_sampling: function for sampling of virtual samples | ||
:param nonlinear: if True, prescribed pde is non-linear | ||
""" | ||
|
||
self.pde_data = pde_data | ||
self.pde_function = pde_functions | ||
self.pde_basis = pde_basis | ||
self.pde_source = pde_source | ||
self.boundary_condition_function = boundary_condition_function | ||
self.boundary_conditions = boundary_conditions | ||
self.virtual_functions = virtual_points_function | ||
self.boundary_conditions_sampling = boundary_conditions_sampling | ||
self.boundary_conditions_evaluate = boundary_conditions_evaluate | ||
self.virtual_points_sampling = virtual_points_sampling | ||
self.nonlinear = nonlinear | ||
|
||
def evaluate_pde(self, s, | ||
pce, | ||
coefficients=None): | ||
def evaluate_pde(self, standardized_sample: np.ndarray, | ||
pce: PolynomialChaosExpansion, | ||
coefficients: np.ndarray = None): | ||
|
||
pde_basis = self.pde_function(s, pce) | ||
pde_basis = self.pde_basis(standardized_sample, pce) | ||
|
||
if coefficients is not None: | ||
return np.sum(pde_basis * np.array(coefficients).T, axis=1) | ||
else: | ||
return pde_basis | ||
|
||
def evaluate_boundary_conditions(self, | ||
nsim, | ||
pce): | ||
return self.boundary_conditions(nsim, pce) | ||
nsim: np.ndarray, | ||
pce: PolynomialChaosExpansion): | ||
return self.boundary_conditions_evaluate(nsim, pce) | ||
|
||
def evaluate_pde_source(self, s, multindex=None, coefficients=None): | ||
def evaluate_pde_source(self, standardized_sample: np.ndarray, multindex: np.ndarray = None, | ||
coefficients: np.ndarray = None): | ||
if self.pde_source is not None: | ||
if self.nonlinear: | ||
return self.pde_source(s, multindex, coefficients) | ||
return self.pde_source(standardized_sample, multindex, coefficients) | ||
else: | ||
return self.pde_source(s) | ||
return self.pde_source(standardized_sample) | ||
else: | ||
return 0 | ||
|
||
def evaluate_boundary_condition_function(self, s, multindex=None, coefficients=None): | ||
if self.boundary_condition_function is not None: | ||
if coefficients is not None: | ||
bc_pce = self.boundary_condition_function(s, multindex, coefficients) | ||
else: | ||
bc_pce = self.boundary_condition_function(s) | ||
return bc_pce | ||
else: | ||
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters