Git Product home page Git Product logo

Comments (9)

jorgensd avatar jorgensd commented on August 26, 2024

The manipulation of forms with mixed elements makes it hard to test.
Here is an example from ufl 2019.1.0 (when the extract_block at least gives a result):

from ufl import *
from ufl.domain import default_domain
from ufl.algorithms.formsplitter import block_split
domain = default_domain(triangle)

el = FiniteElement("CG", triangle, 1)
el2 = FiniteElement("CG", triangle, 2)

me = MixedElement([el, el2])
W = FunctionSpace(domain, me)
v, q = TestFunctions(W)
F00 = v*dx 
F01 = q*dx
F = F01 + F00
F0 = block_split(F,0)
print(f"{str(F)=}")
print(f"{str(F0)=}")
print(f"{str(F00)=}")

yielding:

str(F)='{ v_0[1] } * dx(<Mesh #-1>[everywhere], {})\n  +  { v_0[0] } * dx(<Mesh #-1>[everywhere], {})'
str(F0)='{ ([v_0, 0])[1] } * dx(<Mesh #-1>[everywhere], {})\n  +  { ([v_0, 0])[0] } * dx(<Mesh #-1>[everywhere], {})'
str(F00)='{ v_0[0] } * dx(<Mesh #-1>[everywhere], {})'

I don't see any good way of checking equality between F0 and F00 (thus checking the capabilities of extract block).
We could of course test this in FFCx, but I would like the test to be in ufl as the function can potentially be used by firedrake etc.
My main issue is:
'{ ([v_0, 0])[1] } * dx(<Mesh #-1>[everywhere], {})\n
which I believe is 0 if I understand the brackets correctly

from ufl.

wence- avatar wence- commented on August 26, 2024

Run it through the form preprocessing and those lists should simplify out, I think.

FWIW, we don't use the UFL function in firedrake because we want to reconstruct our own Arguments (that have concrete information attached to them)

from ufl.

jorgensd avatar jorgensd commented on August 26, 2024

Run it through the form preprocessing and those lists should simplify out, I think.

FWIW, we don't use the UFL function in firedrake because we want to reconstruct our own Arguments (that have concrete information attached to them)

Unfortunately that doesn't work. Mwe using
#285

import ufl
import ufl.algorithms
from ufl.finiteelement import FiniteElement, MixedElement



cell = ufl.triangle
domain = ufl.Mesh(FiniteElement("Lagrange", cell, 1, (2,), ufl.identity_pullback, ufl.H1))
fe_scalar = FiniteElement("Lagrange", cell, 1, (), ufl.identity_pullback, ufl.H1)
fe_vector = FiniteElement("Lagrange", cell, 2, (2, ), ufl.identity_pullback, ufl.H1)

me = MixedElement([fe_vector, fe_scalar])

W = ufl.FunctionSpace(domain, me)
wh =  ufl.Coefficient(W)
uh, ph = ufl.split(wh)
v, q = ufl.TestFunctions(W)
F_0 = ufl.inner(uh,v) * ufl.dx(domain=domain)
F_1 = ph * q *ufl. dx
F = F_0 + F_1
f_prec = ufl.algorithms.preprocess_form(ufl.extract_blocks(F, 0), False)
F_0_prec = ufl.algorithms.preprocess_form(F_0, False)
print(str(f_prec))
print()
print(str(F_0_prec))

yielding

{ sum_{i_8} ([([v_0[0], v_0[1], 0])[0], ([v_0[0], v_0[1], 0])[1]])[i_8] * ([w_0[0], w_0[1]])[i_8]  } * dx(<Mesh #0>[everywhere], {})
  +  { ([v_0[0], v_0[1], 0])[2] * w_0[2] } * dx(<Mesh #0>[everywhere], {})

{ sum_{i_9} ([v_0[0], v_0[1]])[i_9] * ([w_0[0], w_0[1]])[i_9]  } * dx(<Mesh #0>[everywhere], {})

Any suggestions as how to change the PR to restore the former capability and make a sensible check?

from ufl.

wence- avatar wence- commented on August 26, 2024

https://github.com/firedrakeproject/firedrake/blob/master/firedrake/formmanipulation.py#L18-L32

and https://github.com/firedrakeproject/firedrake/blob/master/firedrake/formmanipulation.py#L67-L72

from ufl.

jorgensd avatar jorgensd commented on August 26, 2024

How should I credit firedrake in the ufl file, as we would need these changes in form splitter?
The appropriate thing to do would be to copy the whole firedrake license into ufl.

from ufl.

dham avatar dham commented on August 26, 2024

Firedrake is LGPL and UFL is GPL so you can just lift the code under the licences. You are supposed to maintain copyright headers, but since git blame shows that Lawrence wrote that code, and Lawrence is already listed as an author of UFL, I think that's moot and you can just do it.

from ufl.

jorgensd avatar jorgensd commented on August 26, 2024

Firedrake is LGPL and UFL is GPL so you can just lift the code under the licences. You are supposed to maintain copyright headers, but since git blame shows that Lawrence wrote that code, and Lawrence is already listed as an author of UFL, I think that's moot and you can just do it.

Ok. That was what i wanted to clarify. @wence- let me know if this doesnโ€™t suit you :)

from ufl.

wence- avatar wence- commented on August 26, 2024

That's fine.

from ufl.

wence- avatar wence- commented on August 26, 2024

Note that if you do that, the usage I implemented there has this performance antipattern which you may wish to try and address firedrakeproject/firedrake#3560

from ufl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.