Create a Form object from a data-independent compiled form. Args: form: Compiled ufl form, V: List of function spaces associated with the form. Should match the number of arguments in the form. msh: Mesh to associate form with. subdomains: A map from
(
form: CompiledForm,
V: list[FunctionSpace],
msh: Mesh,
subdomains: dict[IntegralType, list[tuple[int, np.ndarray]]],
coefficient_map: dict[ufl.Coefficient, Function],
constant_map: dict[ufl.Constant, Constant],
entity_maps: Sequence[_EntityMap] | None = None,
)
| 605 | |
| 606 | |
| 607 | def create_form( |
| 608 | form: CompiledForm, |
| 609 | V: list[FunctionSpace], |
| 610 | msh: Mesh, |
| 611 | subdomains: dict[IntegralType, list[tuple[int, np.ndarray]]], |
| 612 | coefficient_map: dict[ufl.Coefficient, Function], |
| 613 | constant_map: dict[ufl.Constant, Constant], |
| 614 | entity_maps: Sequence[_EntityMap] | None = None, |
| 615 | ) -> Form: |
| 616 | """Create a Form object from a data-independent compiled form. |
| 617 | |
| 618 | Args: |
| 619 | form: Compiled ufl form, |
| 620 | V: List of function spaces associated with the form. Should |
| 621 | match the number of arguments in the form. |
| 622 | msh: Mesh to associate form with. |
| 623 | subdomains: A map from integral type to a list of pairs, where |
| 624 | each pair corresponds to a subdomain id and the set of of |
| 625 | integration entities to integrate over. Can be computed with |
| 626 | {py:func}`dolfinx.fem.compute_integration_domains`. |
| 627 | coefficient_map: Map from UFL coefficient to function with data. |
| 628 | constant_map: Map from UFL constant to constant with data. |
| 629 | to the integration domain ``msh``. The value of the map is |
| 630 | an array of integers, where the i-th entry is the entity in |
| 631 | the key mesh. |
| 632 | entity_maps: Entity maps to support cases where forms involve |
| 633 | sub-meshes. |
| 634 | |
| 635 | Return: |
| 636 | A Form object. |
| 637 | """ |
| 638 | if entity_maps is None: |
| 639 | _entity_maps = [] |
| 640 | else: |
| 641 | _entity_maps = [entity_map._cpp_object for entity_map in entity_maps] |
| 642 | |
| 643 | _subdomain_data = subdomains.copy() |
| 644 | for _, idomain in _subdomain_data.items(): |
| 645 | idomain.sort(key=lambda x: x[0]) |
| 646 | |
| 647 | # Extract all coefficients of the compiled form in correct order |
| 648 | coefficients = {} |
| 649 | original_coefficients = ufl.algorithms.extract_coefficients(form.ufl_form) |
| 650 | num_coefficients = form.ufcx_form.num_coefficients |
| 651 | for c in range(num_coefficients): |
| 652 | original_index = form.ufcx_form.original_coefficient_positions[c] |
| 653 | original_coeff = original_coefficients[original_index] |
| 654 | try: |
| 655 | coefficients[f"w{c}"] = coefficient_map[original_coeff]._cpp_object |
| 656 | except KeyError: |
| 657 | raise RuntimeError(f"Missing coefficient {original_coeff}") |
| 658 | |
| 659 | # Extract all constants of the compiled form in correct order |
| 660 | # NOTE: Constants are not eliminated |
| 661 | original_constants = ufl.algorithms.analysis.extract_constants(form.ufl_form) |
| 662 | num_constants = form.ufcx_form.num_constants |
| 663 | if num_constants != len(original_constants): |
| 664 | raise RuntimeError( |
nothing calls this directly
no test coverage detected