pihnn.geometries.boundary#

class pihnn.geometries.boundary(curves, np_train, np_test, dd_partition=None)#

Main class for the definition of the domain boundary and boundary conditions (BCs).

Parameters:
  • curves (list) – List of pihnn.geometry.curve which defines the domain boundary.

  • np_train (int) – Number of training points.

  • np_test (int) – Number of test points.

  • dd_partition (callable) – Domain decomposition rule, only for DD-PIHNNs.

An example of domain splitting for partitioning into the 4 quadrants is as follows

def dd_partition (x,y): # Domain decomposition partition
    domains = torch.empty([4,x.shape[0]], dtype=torch.bool)
    domains[0,:] = (x>=-1e-10) & (y>=-1e-10)
    domains[1,:] = (x<=1e-10) & (y>=-1e-10)
    domains[2,:] = (x<=1e-10) & (y<=1e-10)
    domains[3,:] = (x>=-1e-10) & (y<=1e-10)
    return domains

Note

dd_partition must be in exactly the same format as the example: it must return a tensor with an additional dimension at position 0 and each domain must contain also shared interfaces (this is the reason for 1e-10).

extract_points(N)#

Generation of a new batch of points from the boundary.

Parameters:

N (int) – Number of points to generate

Returns:

  • points (torch.tensor) - Coordinates of the extracted points.

  • normals (torch.tensor) - Coordinates of the boundary outward vectors at the points locations.

  • bc_idxs (torch.tensor) - Type of BC at the corresponding points.

  • bc_values (torch.tensor) - Assigned BC value at the corresponding points.

extract_points_dd()#

Training and test points generated from extract_points() are copied internally in an additional format that is necessary for the training of DD-PIHNNs.

In particular, if \(N\) is the number of training/test points and \(D\) the number of domains, we have the transformation

\[P_f \in \mathbb{C}^{N} \rightarrow P_d \in \mathbb{C}^{D,N_D}\]

where \(N_D\) is the maximum number of points in a domain (approximately \(N/D\) if the domains are all similar). In particular, \(p\in P_f\) is copied into \(P_d\) at the \(i\)-th row if \(p\) belongs to the \(i\)-th domain.

Notice that the division/splitting is almost never exact, therefore there are some elements in \(P_d\) that are empty and therefore ignored.

Together with \(P_d\) for both training and test points, the method provides the mask used to ignore leftover points and another tensor used to identify twin points on interfaces.

__call__(dataset, dd=False)#

It returns the currently saved boundary points (generated through extract_points()).

Parameters:
  • dataset (str) – ‘training’ or ‘test’ option.

  • dd (bool) – If True, it returns the boundary points in the domain decomposition format (see extract_points_dd())

Returns:

  • points (torch.tensor) - Coordinates of the extracted points.

  • normals (torch.tensor) - Coordinates of the boundary outward vectors at the points locations.

  • bc_idxs (torch.tensor) - Type of BC at the corresponding points.

  • bc_values (torch.tensor) - Assigned BC value at the corresponding points.

is_inside(points)#

Verifies whether some coordinates are inside or outside the boundary. It employs the ‘ray casting algorithm’.

Parameters:

points (torch.tensor) – Batch of points to inspect.

Returns:

inside (torch.tensor) - For each input point, True if it is inside and False if it outside.

adjust_orientation()#

This function is called internally to adjust the sign of the normals to the boundary. It auto-detects if the normals are inward and make them outward.

check_consistency()#

Checks if boundary is formed by a well-defined closed loop, throws a warning otherwise.