Skip to content

Commit

Permalink
Merge pull request #1196 from BellaLq/master
Browse files Browse the repository at this point in the history
TriangleMesh增加device
  • Loading branch information
weihuayi authored Oct 13, 2024
2 parents 9d78523 + 1725cf8 commit d1e0d97
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
3 changes: 0 additions & 3 deletions fealpy/experimental/mesh/lagrange_triangle_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,6 @@ def jacobi_matrix(self, bc: TensorLike, p=None, index: Index=_S, return_grad=Fal
else:
return J, gphi

def uniform_refine(self, n=1):
pass

# fundamental form
def first_fundamental_form(self, bc: Union[TensorLike, Tuple[TensorLike]],
index: Index=_S, return_jacobi=False, return_grad=False):
Expand Down
18 changes: 11 additions & 7 deletions fealpy/experimental/mesh/triangle_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@
from scipy.sparse import spdiags, eye, tril, triu, bmat

class TriangleMesh(SimplexMesh, Plotable):
def __init__(self, node: TensorLike, cell: TensorLike) -> None:
def __init__(self, node: TensorLike, cell: TensorLike, device=None) -> None:
"""
"""
super().__init__(TD=2, itype=cell.dtype, ftype=node.dtype)
kwargs = bm.context(cell)
self.device = device

self.node = node
self.cell = cell
self.localEdge = bm.tensor([(1, 2), (2, 0), (0, 1)], **kwargs)
self.localFace = bm.tensor([(1, 2), (2, 0), (0, 1)], **kwargs)
self.ccw = bm.tensor([0, 1, 2], **kwargs)
self.localEdge = bm.tensor([(1, 2), (2, 0), (0, 1)], **kwargs, device=self.device)
self.localFace = bm.tensor([(1, 2), (2, 0), (0, 1)], **kwargs, device=self.device)
self.ccw = bm.tensor([0, 1, 2], **kwargsi, device=self.device)

self.localCell = bm.tensor([
(0, 1, 2),
(1, 2, 0),
(2, 0, 1)], **kwargs)
(2, 0, 1)], **kwargs, device=self.device)

self.construct()

Expand Down Expand Up @@ -1108,10 +1110,12 @@ def from_box(cls, box=[0, 1, 0, 1], nx=10, ny=10, threshold=None):
@param threshold Optional function to filter cells based on their barycenter coordinates (default: None)
@return TriangleMesh instance
"""
device = self.device

NN = (nx + 1) * (ny + 1)
NC = nx * ny
x = bm.linspace(box[0], box[1], nx+1, dtype=bm.float64)
y = bm.linspace(box[2], box[3], ny+1, dtype=bm.float64)
x = bm.linspace(box[0], box[1], nx+1, dtype=bm.float64i, device=device)
y = bm.linspace(box[2], box[3], ny+1, dtype=bm.float64, device=device)
X, Y = bm.meshgrid(x, y, indexing='ij')

node = bm.concatenate((X.reshape(-1, 1), Y.reshape(-1, 1)), axis=1)
Expand Down

0 comments on commit d1e0d97

Please sign in to comment.