Skip to content

Commit

Permalink
update to dolfinx v0.7.2; test pass
Browse files Browse the repository at this point in the history
  • Loading branch information
pierricmora committed Dec 7, 2023
1 parent c64cf72 commit bd758cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions elastodynamicsx/pde/materials/elasticmaterial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# SPDX-License-Identifier: MIT

from dolfinx import fem
from dolfinx import fem, default_scalar_type
from petsc4py import PETSc
import ufl
import numpy as np
Expand Down Expand Up @@ -222,8 +222,8 @@ def DG_numerical_flux(self) -> 'function':
def DG_SIPG_regularization_parameter(self) -> 'dolfinx.fem.Constant':
"""Regularization parameter for the Symmetric Interior Penalty Galerkin methods (SIPG)"""
degree = self._function_space.ufl_element().degree()
gamma = fem.Constant(self._function_space.mesh, PETSc.ScalarType(degree*(degree+1) + 1)) #+1 otherwise blows with elements of degree 1
#gamma = fem.Constant(self._function_space.mesh, PETSc.ScalarType(160)) #+1 otherwise blows with elements of degree 1
gamma = fem.Constant(self._function_space.mesh, default_scalar_type(degree*(degree+1) + 1)) #+1 otherwise blows with elements of degree 1
#gamma = fem.Constant(self._function_space.mesh, default_scalar_type(160)) #+1 otherwise blows with elements of degree 1
P_mod = self.P_modulus
R_ = gamma*P_mod
return R_
Expand Down Expand Up @@ -476,23 +476,23 @@ def k1_CG(self) -> 'function':

@property
def k2_CG(self) -> 'function':
return lambda u,v: fem.Constant(u.ufl_function_space(), PETSc.ScalarType(0)) * ufl.inner(u,v) * self._dx
return lambda u,v: fem.Constant(u.ufl_function_space().mesh, default_scalar_type(0)) * ufl.inner(u,v) * self._dx

@property
def k3_CG(self) -> 'function':
return lambda u,v: ufl.inner(self.mu*self._L_onaxis(u), self._L_onaxis(v)) * self._dx

@property
def DG_numerical_flux_SIPG(self) -> 'function':
inner, avg, jump = ufl.inner, ufl.avg, ufl.jump
V = self._function_space
n = ufl.FacetNormal(V)
h = ufl.MinCellEdgeLength(V) #works!
h = ufl.MinCellEdgeLength(V) # works!
h_avg = (h('+') + h('-'))/2.0
R_ = self.DG_SIPG_regularization_parameter()
dS = self._dS
sigma = self.sigma

k_int_facets = lambda u,v: \
- inner(avg(sigma(u)), jump(v,n) ) * dS \
- inner(jump(u,n) , avg(sigma(v))) * dS \
Expand All @@ -510,7 +510,7 @@ def DG_numerical_flux_NIPG(self) -> 'function':
R_ = self.DG_SIPG_regularization_parameter()
dS = self._dS
sigma = self.sigma

k_int_facets = lambda u,v: \
- inner(avg(sigma(u)), jump(v,n) ) * dS \
+ inner(jump(u,n) , avg(sigma(v))) * dS \
Expand Down
16 changes: 8 additions & 8 deletions test/test_materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# TODO: currently only testing for build & compile, not for the validity of a result.

from dolfinx import mesh, fem
from dolfinx import mesh, fem, default_scalar_type
from mpi4py import MPI
from petsc4py import PETSc

Expand All @@ -27,29 +27,29 @@ def create_mesh(dim):
def tst_scalar_material(dim, eltname="Lagrange"):
# FE domain
V = fem.FunctionSpace(create_mesh(dim), (eltname, 1))

# Material
const = lambda x: fem.Constant(V.mesh, PETSc.ScalarType(x))
const = lambda x: fem.Constant(V.mesh, default_scalar_type(x))
mat = material(V, 'scalar', rho=const(1), mu=const(1))
mats = [mat]

# PDE
pde = PDE(V, materials=mats)

# Compile some matrices
_, _, _ = pde.M() , pde.C() , pde.K()
_, _, _ = pde.K1(), pde.K2(), pde.K3()

# The end



def tst_vector_materials(dim, nbcomps, eltname="Lagrange"):
# FE domain
V = fem.VectorFunctionSpace(create_mesh(dim), (eltname, 1), dim=nbcomps)
V = fem.FunctionSpace(create_mesh(dim), (eltname, 1, (nbcomps,)))

# Material
const = lambda x: fem.Constant(V.mesh, PETSc.ScalarType(x))
const = lambda x: fem.Constant(V.mesh, default_scalar_type(x))
rho = const(1)
Coo = const(1) #a dummy Cij
types= ('isotropic', 'cubic', 'hexagonal', 'trigonal', 'tetragonal', 'orthotropic', 'monoclinic', 'triclinic')
Expand Down

0 comments on commit bd758cb

Please sign in to comment.