MCPcopy Create free account
hub / github.com/FEniCS/dolfinx / __init__

Method __init__

python/dolfinx/fem/function.py:125–232  ·  view source on GitHub ↗

Create an Expression. Args: e: UFL expression. X: Array of points of shape ``(num_points, tdim)`` on the reference element. comm: Communicator that the Expression is defined on. form_compiler_options: Options used in FFCx compi

(
        self,
        e: ufl.core.expr.Expr,
        X: np.ndarray,
        comm: _MPI.Comm | None = None,
        form_compiler_options: dict | None = None,
        jit_options: dict | None = None,
        dtype: npt.DTypeLike | None = None,
        entity_maps: list[_EntityMap] | None = None,
    )

Source from the content-addressed store, hash-verified

123 _code: str
124
125 def __init__(
126 self,
127 e: ufl.core.expr.Expr,
128 X: np.ndarray,
129 comm: _MPI.Comm | None = None,
130 form_compiler_options: dict | None = None,
131 jit_options: dict | None = None,
132 dtype: npt.DTypeLike | None = None,
133 entity_maps: list[_EntityMap] | None = None,
134 ):
135 """Create an Expression.
136
137 Args:
138 e: UFL expression.
139 X: Array of points of shape ``(num_points, tdim)`` on the
140 reference element.
141 comm: Communicator that the Expression is defined on.
142 form_compiler_options: Options used in FFCx compilation of
143 this Expression. Run ``ffcx --help`` in the commandline
144 to see all available options.
145 jit_options: Options controlling JIT compilation of C code.
146 dtype: Type of the Expression values. If ``None``,
147 the dtype is deduced from the UFL expression.
148 entity_maps: Maps between different meshes.
149
150 Note:
151 This wrapper is responsible for the FFCx compilation of the
152 UFL Expr and attaching the correct data to the underlying
153 C++ Expression.
154 """
155 assert X.ndim < 3
156 num_points = X.shape[0] if X.ndim == 2 else 1
157 _X = np.reshape(X, (num_points, -1))
158
159 # Get MPI communicator
160 if comm is None:
161 try:
162 domains = ufl.domain.extract_domains(e)
163 if len(domains) == 0:
164 raise RuntimeError("Could not extract MPI communicator for Expression.")
165 domain = domains[0]
166 assert isinstance(domain, ufl.Mesh)
167 mesh = domain.ufl_cargo()
168 comm = mesh.comm
169 except AttributeError:
170 print(
171 "Could not extract MPI communicator for Expression. "
172 + "Maybe you need to pass a communicator?"
173 )
174 raise
175
176 # Attempt to deduce dtype
177 if dtype is None:
178 dtype = getattr(e, "dtype", default_scalar_type)
179
180 # Compile UFL expression with JIT
181 if form_compiler_options is None:
182 form_compiler_options = dict()

Callers

nothing calls this directly

Calls 1

ufl_function_spaceMethod · 0.80

Tested by

no test coverage detected