Base Problem#
Module for the BaseProblem class.
- class BaseProblem[source]#
Bases:
ProblemInterfaceBase class for all problems, implementing common functionality.
A problem is defined by core components, including input and output variables, a set of conditions to be satisfied, and optionally the domains on which these conditions are defined.
All problems must inherit from this class and implement abstract methods defined in
ProblemInterface.This class is not meant to be instantiated directly.
Initialization of the
BaseProblemclass.- discretise_domain(n=None, mode='random', domains=None, sample_rules=None)[source]#
Discretise the problem’s domains by sampling a specified number of points according to the selected sampling mode.
- Parameters:
n (int) – The number of points to sample. This is ignored if
sample_rulesis provided. Default isNone.mode (str) – The sampling method. Available modes include:
"random"for random sampling,"latin"or"lh"for latin hypercube sampling,"chebyshev"for Chebyshev sampling, and"grid"for grid sampling. Default is"random".domains (str | list[str]) – The domains from which to sample. If
None, all domains are considered for sampling. Default isNone.sample_rules (dict) – The dictionary specifying custom sampling rules for each input variable. When provided, it overrides the global
nandmodearguments. Each key in the dictionary must match one of the variables defined ininput_variables(), and each value must be a dictionary containing two keys:nfor the number of points to sample for that variable, andmodefor the sampling method to use. IfNone, the globalnandmodeparameters are used for all variables. Default isNone.
- Raises:
ValueError – If
sample_rulesis provided but it is not a dictionary.ValueError – If
sample_rulesis provided but its keys do not match the input variables of the problem.ValueError – If
sample_rulesis provided but any of its rules is not a dictionary containing bothnandmodekeys, withnbeing a positive integer andmodebeing a string.AssertionError – If
nis not a positive integer.ValueError – If
modeis not a stringValueError – If
domainsis provided by it is neither a string nor a list of strings.
Warning
"random"is the only supportedmodeacross all geometries:CartesianDomain,EllipsoidDomain, andSimplexDomain. Sampling modes such as"latin","chebyshev", and"grid"are only implemented forCartesianDomain. When custom discretisation is specified viasample_rules, the domain to be discretised must be an instance ofCartesianDomain.- Example:
>>> problem.discretise_domain(n=10, mode="random") >>> problem.discretise_domain(n=10, mode="lh", domains=["boundary"]) >>> problem.discretise_domain( ... sample_rules={ ... 'x': {'n': 10, 'mode': 'grid'}, ... 'y': {'n': 100, 'mode': 'grid'} ... }, ... )
- add_points(new_points_dict)[source]#
Append additional points to an already discretised domain.
- Parameters:
new_points_dict (dict) – The dictionary mapping each domain to the corresponding set of new points to be added. Each key in the dictionary must match one of the domains defined in
domains, and each value must be aLabelTensorcontaining the new points to be added to that domain. The labels of the points to be added must correspond to those of the domain to which they are being added.- Raises:
ValueError – If
new_points_dictis not a dictionary.ValueError – If any of the values in
new_points_dictis not aLabelTensor.ValueError – If any of the keys in
new_points_dictdoes not match any of the domains defined indomains.ValueError – If any of the domains in
new_points_dicthas not been discretised yet.
- Example:
>>> additional_points = { ... "boundary": LabelTensor(torch.rand(5, 2), labels=["x", "y"]) ... } >>> problem.add_points(additional_points)
- move_discretisation_into_conditions()[source]#
Move the sampled points from the discretised domains into their corresponding conditions. This ensures that the conditions are evaluated on the correct set of points after discretisation.
- property input_variables#
The input variables of the problem.
- property discretised_domains#
The dictionary containing the discretised domains of the problem. Each key corresponds to a domain defined in
domains, and each value is aLabelTensorcontaining the sampled points for that domain.- Returns:
The discretised domains.
- Return type: