Skip to content

Commit

Permalink
Merge branch 'gallery-of-examples' of github.com:kinnala/scikit-fem i…
Browse files Browse the repository at this point in the history
…nto gallery-of-examples
  • Loading branch information
kinnala committed Jul 20, 2020
2 parents d36e0a5 + 7274b8a commit 1d56c54
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ install:
- tar zvxf gmsh-4.5.2-Linux64.tgz
- sudo cp gmsh-4.5.2-Linux64/bin/gmsh /usr/bin
- cd ..
- wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
Expand Down
2 changes: 1 addition & 1 deletion skfem/assembly/basis/facet_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(self,

self.nelems = len(self.find)

self.basis = [self.elem.gbasis(self.mapping, Y, j, self.tind)
self.basis = [self.elem.gbasis(self.mapping, Y, j, tind=self.tind)
for j in range(self.Nbfun)]

self.dx = (np.abs(self.mapping.detDG(self.X, find=self.find))
Expand Down
2 changes: 1 addition & 1 deletion skfem/assembly/form/bilinear_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def assemble(self,

# initialize COO data structures
sz = u.Nbfun * v.Nbfun * nt
data = np.zeros(sz)
data = np.zeros(sz, dtype=self.dtype)
rows = np.zeros(sz)
cols = np.zeros(sz)

Expand Down
7 changes: 6 additions & 1 deletion skfem/assembly/form/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@ def __getattr__(self, attr):

class Form:

def __init__(self, form: Callable):
def __init__(self,
form: Callable = None,
dtype: type = np.float64):
self.form = form
self.dtype = dtype

def __call__(self, *args):
if self.form is None: # decorate
return type(self)(form=args[0], dtype=self.dtype)
return self.assemble(self.kernel(*args))

def _kernel(self):
Expand Down
2 changes: 1 addition & 1 deletion skfem/assembly/form/linear_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def assemble(self,

# initialize COO data structures
sz = v.Nbfun * nt
data = np.zeros(sz)
data = np.zeros(sz, dtype=self.dtype)
rows = np.zeros(sz)
cols = np.zeros(sz)

Expand Down
6 changes: 3 additions & 3 deletions skfem/element/element_composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ def _deduce_bfun(self, i: int):

return ns[i], inds[i]

def gbasis(self, mapping, X: ndarray, i: int, **kwargs):
def gbasis(self, mapping, X: ndarray, i: int, tind=None):
n, ind = self._deduce_bfun(i)
output = []
for k, e in enumerate(self.elems):
if n == k:
output.append(e.gbasis(mapping, X, ind, **kwargs)[0])
output.append(e.gbasis(mapping, X, ind, tind)[0])
else:
output.append(e.gbasis(mapping, X, 0, **kwargs)[0]
output.append(e.gbasis(mapping, X, 0, tind)[0]
.zeros_like())
return tuple(output)
25 changes: 25 additions & 0 deletions tests/test_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,5 +336,30 @@ def feqx(w):
self.assertAlmostEqual(feqx.assemble(basis, func=func, gunc=gunc), 2.)


class TestComplexValuedAssembly(unittest.TestCase):

def runTest(self):

m = MeshTri()
e = ElementTriP1()
basis = InteriorBasis(m, e)
self.interior_area = 1

@BilinearForm(dtype=np.complex64)
def complexmass(u, v, w):
return 1j*u*v

@LinearForm(dtype=np.complex64)
def complexfun(v, w):
return 1j*v

M = asm(complexmass, basis)
f = asm(complexfun, basis)
ones = np.ones(M.shape[1])

self.assertAlmostEqual(np.dot(ones, M @ ones), 1j*self.interior_area)
self.assertAlmostEqual(np.dot(ones, f), 1j*self.interior_area)


if __name__ == '__main__':
unittest.main()
29 changes: 28 additions & 1 deletion tests/test_basis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from skfem import BilinearForm, asm, solve, condense
from skfem.mesh import MeshTri, MeshTet, MeshHex
from skfem.assembly import InteriorBasis, Dofs
from skfem.assembly import InteriorBasis, FacetBasis, Dofs
from skfem.element import (ElementVectorH1, ElementTriP2, ElementTriP1,
ElementTetP2, ElementHexS2)

Expand Down Expand Up @@ -61,7 +61,34 @@ def bilinf(u, p, v, q, w):
self.assertTrue((basis.doflocs[:, D['up'].all()][1] == 1.).all())


class TestCompositeFacetAssembly(TestCase):

def runTest(self):

m = MeshTri()

fbasis1 = FacetBasis(m, ElementTriP1() * ElementTriP1(),
facets=m.facets_satisfying(lambda x: x[0] == 0))
fbasis2 = FacetBasis(m, ElementTriP1(),
facets=m.facets_satisfying(lambda x: x[0] == 0))

@BilinearForm
def uv1(u, p, v, q, w):
return u * v + p * q

@BilinearForm
def uv2(u, v, w):
return u * v

A = asm(uv1, fbasis1)
B = asm(uv2, fbasis2)

assert_allclose(A[0].todense()[0, ::2],
B[0].todense()[0])


class TestFacetExpansion(TestCase):

mesh_type = MeshTet
elem_type = ElementTetP2

Expand Down

0 comments on commit 1d56c54

Please sign in to comment.