Skip to content

Commit

Permalink
Moved different models to different files.
Browse files Browse the repository at this point in the history
  • Loading branch information
kinnala committed Apr 3, 2018
1 parent 8681250 commit 423337c
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 33 deletions.
1 change: 1 addition & 0 deletions examples/ex2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from skfem import *
from skfem.models.poisson import unit_load
import numpy as np

m = MeshTri()
Expand Down
3 changes: 2 additions & 1 deletion examples/ex3.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from skfem import *
from skfem.models.elasticity import *
from scipy.sparse.linalg import eigsh
import numpy as np

Expand Down Expand Up @@ -35,4 +36,4 @@ def mass(u, du, v, dv, w):
y[I] = x[:, 4]

MeshQuad(np.array([m.p[0, :]+y[gb.dofnum.n_dof[0, :]], m.p[1, :]+y[gb.dofnum.n_dof[1, :]]]), m.t).draw()
m.show()
m.show()
3 changes: 2 additions & 1 deletion examples/ex4.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from skfem import *
from skfem.models import *
from skfem.mesh_importers import *
from skfem.models.elasticity import *
import numpy as np

m = read_comsol("examples/square_smalltris.mphtxt")
Expand Down
1 change: 1 addition & 0 deletions examples/ex6.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from skfem import *
from skfem.models.poisson import laplace

"""
High-order plotting test.
Expand Down
7 changes: 1 addition & 6 deletions examples/ex8.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
from skfem.mesh import *
from skfem.assembly import *
from skfem.element import *
from skfem.utils import *
from skfem.mapping import *
from skfem.extern_sfepy import *
from skfem import *
import matplotlib.pyplot as plt

"""
Expand Down
2 changes: 1 addition & 1 deletion examples/ex9.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from skfem import *
from skfem.models import *
from skfem.models.poisson import *

"""
Solve Laplace equation with zero Dirichlet BC
Expand Down
4 changes: 1 addition & 3 deletions skfem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ def _import_all_modules():
or filename == 'mesh.py' \
or filename == 'utils.py' \
or filename == 'element.py' \
or filename == 'mapping.py' \
or filename == 'extern_sfepy.py' \
or filename == 'models.py':
or filename == 'mapping.py':
modulename = filename.split('.')[0] # filename without extension
package_module = '.'.join([__name__, modulename])
try:
Expand Down
File renamed without changes.
25 changes: 4 additions & 21 deletions skfem/models.py → skfem/models/elasticity.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
# -*- coding: utf-8 -*-
"""
Weak forms for various PDE's
Linear elasticity
"""
import numpy as np
from skfem.utils import bilinear_form, linear_form

@bilinear_form
def laplace(u, du, v, dv, w):
if du.shape[0] == 2:
return du[0]*dv[0] + du[1]*dv[1]
elif du.shape[0] == 3:
return du[0]*dv[0] + du[1]*dv[1] + du[2]*dv[2]
else:
raise NotImplementedError("Laplace weakform not implemented for the used dimension.")

@bilinear_form
def mass(u, du, v, dv, w):
return u*v

@linear_form
def unit_load(v, dv, w):
return v

def plane_strain(Lambda=1.0, Mu=1.0):
@bilinear_form
def weakform(u, du, v, dv, w):
Expand Down Expand Up @@ -58,7 +41,7 @@ def ddot(A, B):
A[1, 0] * B[1, 0] + \
A[1, 1] * B[1, 1] + \
A[0, 2] * B[0, 2] + \
A[2, 0] * B[2, 0] + \
A[2, 0] * B[2, 0] + \
A[1, 2] * B[1, 2] + \
A[2, 1] * B[2, 1] + \
A[2, 2] * B[2, 2]
Expand All @@ -73,8 +56,8 @@ def C(T):

def Eps(dw):
return np.array([[dw[0][0], 0.5*(dw[0][1] + dw[1][0]), 0.5*(dw[0][2] + dw[2][0])],
[0.5*(dw[1][0] + dw[0][1]), dw[1][1], 0.5*(dw[1][2] + dw[2][1])],
[0.5*(dw[2][0] + dw[0][2]), 0.5*(dw[2][1] + dw[1][2]), dw[2][2]]])
[0.5*(dw[1][0] + dw[0][1]), dw[1][1], 0.5*(dw[1][2] + dw[2][1])],
[0.5*(dw[2][0] + dw[0][2]), 0.5*(dw[2][1] + dw[1][2]), dw[2][2]]])

return ddot(C(Eps(du)), Eps(dv))

Expand Down
23 changes: 23 additions & 0 deletions skfem/models/poisson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
"""
Poisson equation
"""
import numpy as np
from skfem.utils import bilinear_form, linear_form

@bilinear_form
def laplace(u, du, v, dv, w):
if du.shape[0] == 2:
return du[0]*dv[0] + du[1]*dv[1]
elif du.shape[0] == 3:
return du[0]*dv[0] + du[1]*dv[1] + du[2]*dv[2]
else:
raise NotImplementedError("Laplace weakform not implemented for the used dimension.")

@bilinear_form
def mass(u, du, v, dv, w):
return u*v

@linear_form
def unit_load(v, dv, w):
return v

0 comments on commit 423337c

Please sign in to comment.