File size: 3,592 Bytes
66c9c8a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from typing import Union, Optional

from warp.fem.domain import GeometryDomain, Cells
from warp.fem.space import FunctionSpace, SpaceRestriction, SpacePartition, make_space_partition, make_space_restriction

from .field import DiscreteField, SpaceField, FieldLike
from .restriction import FieldRestriction
from .test import TestField
from .trial import TrialField

from .nodal_field import NodalField


def make_restriction(
    field: DiscreteField,
    space_restriction: Optional[SpaceRestriction] = None,
    domain: Optional[GeometryDomain] = None,
    device=None,
) -> FieldRestriction:
    """
    Restricts a discrete field to a subset of elements.

    Args:
        field: the discrete field to restrict
        space_restriction: the function space restriction defining the subset of elements to consider
        domain: if ``space_restriction`` is not provided, the :py:class:`Domain` defining the subset of elements to consider
        device: Warp device on which to perform and store computations

    Returns:
        the field restriction
    """

    if space_restriction is None:
        space_restriction = make_space_restriction(space_partition=field.space_partition, domain=domain, device=device)

    return FieldRestriction(field=field, space_restriction=space_restriction)


def make_test(
    space: FunctionSpace,
    space_restriction: Optional[SpaceRestriction] = None,
    space_partition: Optional[SpacePartition] = None,
    domain: Optional[GeometryDomain] = None,
    device=None,
) -> TestField:
    """
    Constructs a test field over a function space or its restriction

    Args:
        space: the function space
        space_restriction: restriction of the space topology to a domain
        space_partition: if `space_restriction` is ``None``, the optional subset of node indices to consider
        domain: if `space_restriction` is ``None``, optional subset of elements to consider
        device: Warp device on which to perform and store computations

    Returns:
        the test field
    """

    if space_restriction is None:
        space_restriction = make_space_restriction(
            space_topology=space.topology, space_partition=space_partition, domain=domain, device=device
        )

    return TestField(space_restriction=space_restriction, space=space)


def make_trial(
    space: FunctionSpace,
    space_restriction: Optional[SpaceRestriction] = None,
    space_partition: Optional[SpacePartition] = None,
    domain: Optional[GeometryDomain] = None,
) -> TrialField:
    """
    Constructs a trial field over a function space or partition

    Args:
        space: the function space or function space restriction
        space_restriction: restriction of the space topology to a domain
        space_partition: if `space_restriction` is ``None``, the optional subset of node indices to consider
        domain: if `space_restriction` is ``None``, optional subset of elements to consider
        device: Warp device on which to perform and store computations

    Returns:
        the trial field
    """

    if space_restriction is not None:
        domain = space.domain
        space_partition = space.space_partition

    if space_partition is None:
        if domain is None:
            domain = Cells(geometry=space.geometry)
        space_partition = make_space_partition(
            space_topology=space.topology, geometry_partition=domain.geometry_partition
        )
    elif domain is None:
        domain = Cells(geometry=space_partition.geo_partition)

    return TrialField(space, space_partition, domain)