Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function decorator for weakforms #208

Merged
merged 9 commits into from
Apr 24, 2022
Merged

Add function decorator for weakforms #208

merged 9 commits into from
Apr 24, 2022

Conversation

adtzlr
Copy link
Owner

@adtzlr adtzlr commented Apr 23, 2022

introduce a new function decorator @Form():

import numpy as np
from felupe.math import ddot
import felupe as fem

mesh = fem.mesh.triangulate(fem.Rectangle(n=6))
region = fem.RegionTriangle(mesh)
field = fem.Field(region)
coords = fem.Field(
    region, dim=mesh.dim, values=mesh.points
).interpolate()

@fem.Form(v=field, u=field, grad_v=True, grad_u=True)
def a(dv, du):
    return ddot(dv, du)

@fem.Form(v=field)
def L(v, coords):
    x, y = coords
    f = np.sin(np.pi * x) * np.sin(np.pi * y)
    return f * v

L.assemble(v=field, kwargs={"coords": coords})
a.assemble(v=field, u=field)

fixes #207

@adtzlr adtzlr added the enhancement New feature or request label Apr 23, 2022
@adtzlr adtzlr added this to the 3.0.0 milestone Apr 23, 2022
@adtzlr adtzlr self-assigned this Apr 23, 2022
@codecov-commenter
Copy link

codecov-commenter commented Apr 23, 2022

Codecov Report

Merging #208 (3b6fe1d) into main (9b2c1d8) will increase coverage by 0.00%.
The diff coverage is 98.63%.

@@           Coverage Diff           @@
##             main     #208   +/-   ##
=======================================
  Coverage   98.34%   98.35%           
=======================================
  Files          62       62           
  Lines        2543     2608   +65     
=======================================
+ Hits         2501     2565   +64     
- Misses         42       43    +1     
Impacted Files Coverage Δ
felupe/__init__.py 92.00% <ø> (ø)
felupe/_assembly/_base.py 93.50% <ø> (ø)
felupe/_field/_axi.py 95.45% <ø> (ø)
felupe/_field/_base.py 92.30% <ø> (ø)
felupe/element/_triangle.py 100.00% <ø> (ø)
felupe/tools/_save.py 100.00% <ø> (ø)
felupe/_assembly/_form.py 99.46% <98.46%> (-0.54%) ⬇️
felupe/_assembly/__init__.py 100.00% <100.00%> (ø)
felupe/math/__init__.py 100.00% <100.00%> (ø)
felupe/mesh/_convert.py 96.39% <100.00%> (ø)
... and 2 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9b2c1d8...3b6fe1d. Read the comment docs.

@adtzlr
Copy link
Owner Author

adtzlr commented Apr 23, 2022

Mixed-Field implementation is still broken as LinearFormMixed and BilinearFormMixed expect a list of weakforms. This can't be decorated. A new decorator has to be introduced...

@adtzlr
Copy link
Owner Author

adtzlr commented Apr 24, 2022

Mixed-Field Forms are applied on a helper function which returns a list of sub-forms (upper triangle part).

mesh = fe.Cube(n=3)
region = fe.RegionHexahedron(mesh)
fieldmixed = fe.FieldsMixed(region, n=2)
F, p = fieldmixed.extract()

def a_uu(v, u, F, p):
    return ddot(u, ddot(dya(F, F), v))

def a_up(v, r, F, p):
    return dot(p, r) * ddot(F, v)

def a_pp(q, r, F, p):
    return dot(p, q) * dot(r, p)

@fe.Form(v=fieldmixed, u=fieldmixed, grad_v=(True, False), grad_u=(True, False))
def a():
    return (a_uu, a_up, a_pp)

a.assemble(v=fieldmixed, u=fieldmixed, args=(F, p))

@adtzlr adtzlr merged commit 28394ce into main Apr 24, 2022
@adtzlr adtzlr deleted the add-form-decorator branch April 24, 2022 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a new weakform function decorator Form
2 participants