Skip to content

Commit

Permalink
Merge pull request #267 from gdmcbain/q0
Browse files Browse the repository at this point in the history
Q0
  • Loading branch information
kinnala authored Dec 3, 2019
2 parents ccc9ab1 + 4eb2980 commit d5e9a91
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
15 changes: 10 additions & 5 deletions docs/examples/ex25.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from skfem import *
from skfem.models.poisson import laplace
from skfem.models.poisson import laplace, mass

from math import ceil

Expand All @@ -10,9 +10,10 @@
length = 10.
peclet = 1e2

mesh = (MeshLine(np.linspace(0, length, ceil(mesh_inlet_n / height * length)))
* MeshLine(np.linspace(0, height / 2, mesh_inlet_n)))._splitquads()
basis = InteriorBasis(mesh, ElementTriP2())
mesh = MeshQuad.init_tensor(
np.linspace(0, length, ceil(mesh_inlet_n / height * length)),
np.linspace(0, height / 2, mesh_inlet_n))
basis = InteriorBasis(mesh, ElementQuad2())


@bilinear_form
Expand All @@ -31,11 +32,15 @@ def advection(u, du, v, dv, w):
t[dofs['floor'].all()] = 1.
t = solve(*condense(A, np.zeros_like(t), t, I=interior))

basis0 = InteriorBasis(mesh, ElementQuad0(), intorder=basis.intorder)
t0 = solve(asm(mass, basis0),
asm(mass, basis, basis0) @ t)


if __name__ == '__main__':

from pathlib import Path

mesh.plot(t[basis.nodal_dofs.flatten()], edgecolors='none')
mesh.plot(t0, edgecolors='none')
mesh.savefig(Path(__file__).with_suffix('.png'),
bbox_inches='tight', pad_inches=0)
1 change: 1 addition & 0 deletions skfem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'ElementHdiv',
'ElementHex1',
'ElementTriMorley',
'ElementQuad0',
'ElementQuad1',
'ElementQuad2',
'ElementTetN0',
Expand Down
2 changes: 1 addition & 1 deletion skfem/element/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .element_tri import ElementTriP1, ElementTriP2, ElementTriDG,\
ElementTriP0, ElementTriRT0, ElementTriMorley,\
ElementTriArgyris
from .element_quad import ElementQuad1, ElementQuad2
from .element_quad import ElementQuad0, ElementQuad1, ElementQuad2
from .element_tet import ElementTetP0, ElementTetP1, ElementTetP2,\
ElementTetRT0, ElementTetN0
from .element_hex import ElementHex1
Expand Down
1 change: 1 addition & 0 deletions skfem/element/element_quad/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .element_quad0 import ElementQuad0
from .element_quad1 import ElementQuad1
from .element_quad2 import ElementQuad2
13 changes: 13 additions & 0 deletions skfem/element/element_quad/element_quad0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import numpy as np
from ..element_h1 import ElementH1


class ElementQuad0(ElementH1):
interior_dofs = 1
dim = 2
maxdeg = 0
dofnames = ['u']
doflocs = np.zeros((1, 2))

def lbasis(self, X, i):
return np.ones(X.shape[1]), np.zeros_like(X)
4 changes: 3 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ def runTest(self):
class TestEx25(unittest.TestCase):
def runTest(self):
import docs.examples.ex25 as ex
self.assertAlmostEqual(np.mean(ex.t), 0.4642600944590631, places=5)
mu = np.mean(ex.t)
self.assertAlmostEqual(mu, 0.4642600944590631, places=5)
self.assertAlmostEqual(np.mean(ex.t0), mu, places=2)


class TestEx26(unittest.TestCase):
Expand Down

0 comments on commit d5e9a91

Please sign in to comment.