Skip to content

BilinearForm Discretization Issue 2 #523

@jowezarek

Description

@jowezarek

The discretization of the following BilinearForm, when domain is a mapped domain, does not work.

g       = BilinearForm((u1, v1), integral(domain, inner(curl(cross(u1, F)), curl(cross(v1, F)))))

This issue is not Pyccel related, as it occurs both with and without passing a backend variable.

I need to be able to discretize g to (hopefully) improve the convergence behaviour of my MHD code.

I include both a MWE and the corresponding error message.

import  time
from    mpi4py  import  MPI
import  numpy   as      np

from    sympde.calculus             import dot, cross, inner, curl
from    sympde.expr                 import BilinearForm, integral
from    sympde.topology             import element_of, elements_of, Cube, Mapping, Derham

from    psydac.api.discretization   import discretize
from    psydac.api.settings         import PSYDAC_BACKEND_GPYCCEL
from    psydac.fem.basic            import FemField

comm    = MPI.COMM_WORLD
backend = PSYDAC_BACKEND_GPYCCEL

# ----- Parameters to play around with -----

ncells      = [12, 8, 16]
degree      = [2, 4, 3]
periodic    = [False, True, False]
mult        = [1, 3, 2]

# Choose 
# None          for no mapping, or              (no issue here)
# 'analytical'  for an analytical mapping       (   issue here)
mapping_option = 'analytical' # None

# ------------------------------------------

#
#
#

logical_domain = Cube('C', bounds1=(0,1), bounds2=(0,1), bounds3=(0,1))

if mapping_option is None:

    domain = logical_domain

elif mapping_option == 'analytical':

    class SquareTorus(Mapping):

        _expressions = {'x': 'x1 * cos(x2)',
                        'y': 'x1 * sin(x2)',
                        'z': 'x3'}
        
        _ldim        = 3
        _pdim        = 3

    mapping = SquareTorus('ST')

    domain = mapping(logical_domain)

else:
    raise ValueError(f'mapping_option {mapping_option} not understood.')

derham = Derham(domain)

domain_h = discretize(domain, ncells=ncells, periodic=periodic, comm=comm)
derham_h = discretize(derham, domain_h, degree=degree, multiplicity=mult)

V1  = derham.V1
V2  = derham.V2

V1h = derham_h.V1
V2h = derham_h.V2

u1, v1  = elements_of(V1, names='u1, v1')
F       = element_of (V2, name='F')

# generate a random free FemField
F_coeffs = V2h.coeff_space.zeros()
rng = np.random.default_rng(seed=42)
for block in F_coeffs.blocks:
    rng.random(size=block._data.shape, dtype="float64", out=block._data)
F_field = FemField(V2h, F_coeffs)

g       = BilinearForm((u1, v1), integral(domain, inner(curl(cross(u1, F)), curl(cross(v1, F)))))

t0 = time.time()
g_h = discretize(g, domain_h, (V1h, V1h), backend=backend)
t1 = time.time()
print(f'g discretized in {t1-t0:.3g}')
print(f' ----- ')
print()
Traceback (most recent call last):
  File "/home/jubuntu/psydac/psydac/api/tests/mwe2.py", line 82, in <module>
    g_h = discretize(g, domain_h, (V1h, V1h), backend=backend)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jubuntu/psydac/psydac/api/discretization.py", line 604, in discretize
    a       = LogicalExpr (a, domain)
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jubuntu/psydac-hodge/.venv/lib/python3.11/site-packages/sympde/topology/mapping.py", line 880, in __new__
    r = cls.eval(expr, domain, **options)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jubuntu/psydac-hodge/.venv/lib/python3.11/site-packages/sympde/topology/mapping.py", line 1233, in eval
    body    = cls.eval(expr.expr, domain)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jubuntu/psydac-hodge/.venv/lib/python3.11/site-packages/sympde/topology/mapping.py", line 1226, in eval
    body   = cls.eval(expr.expr, domain)*det
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jubuntu/psydac-hodge/.venv/lib/python3.11/site-packages/sympde/topology/mapping.py", line 1090, in eval
    args = [cls.eval(arg, domain) for arg in expr.args]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jubuntu/psydac-hodge/.venv/lib/python3.11/site-packages/sympde/topology/mapping.py", line 1090, in <listcomp>
    args = [cls.eval(arg, domain) for arg in expr.args]
            ^^^^^^^^^^^^^^^^^^^^^
  File "/home/jubuntu/psydac-hodge/.venv/lib/python3.11/site-packages/sympde/topology/mapping.py", line 1037, in eval
    raise NotImplementedError('TODO')
NotImplementedError: TODO

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions