lululxvi / deepxde

A library for scientific machine learning and physics-informed learning
https://deepxde.readthedocs.io
GNU Lesser General Public License v2.1
2.59k stars 732 forks source link

Failed to generate irregular domain via geometry.csg.CSGDifference() function. #1575

Open zyh867336431 opened 9 months ago

zyh867336431 commented 9 months ago

Dear all: I am generating a complex domain via geometry.csg.CSGDifference() function, here is my code:

import numpy as np import pandas as pd from matplotlib import pyplot as plt from scipy import interpolate as inter import deepxde as dde

def geom_generation(xmin, ymin, xmax, ymax, points, num_inner, num_outer, ref_l = 1, offset_x = 0, offset_y = 0, is_save = False): farfield = dde.geometry.geometry_2d.Rectangle([xmin, ymin], [xmax, ymax]) # outer domain points = np.divide(points, ref_l) mat = np.hstack([np.full((points.shape[0],1), offset_x), np.full((points.shape[0],1), offset_y)]) points = points + mat fossil = dde.geometry.pointcloud.PointCloud(points) # generate inner domain geom = dde.geometry.csg.CSGDifference(farfield, fossil) # outer - inner inner_points = geom.random_points(num_inner) farfield_points = farfield.random_boundary_points(num_outer) geom_points = np.append(inner_points, farfield_points, axis = 0) plt.figure(figsize=(20,10), dpi = 500) plt.scatter(geom_points[:, 0], geom_points[:, 1], 0.1)

plt.scatter(points[:, 0], points[:, 1], 0.1)

plt.axis('equal')
if is_save:
    np.savetxt("geom.csv", geom_points)
return geom_points

print(points.shape) plt.figure(figsize=(10,5), dpi = 300) plt.scatter(points[:, 0], points[:, 1], 0.5) plt.axis('equal')

num_inner, num_outer = 40000, 10000

xmin, xmax = -1.0, 1.0 # define outer domain ymin, ymax = -0.5, 0.5

ref_l, offset_x, offset_y = 1, -0, 0 geom_generation(xmin, ymin, xmax, ymax, points, num_inner, num_outer, ref_l, offset_x, offset_y, False)

The inner domain is a complex geometry defined by geometry.pointcloud.PointCloud(), as is shown below: image The outer domain is a rectangle defined by geometry.geometry_2d.Rectangle(). Thus, the expected output domain should be (outer domain - inner domain). However, it looks like the geometry.csg.CSGDifference() function does not work at all since only outer domain is generated, as is shown below:
image

My question here is how to generate the correct geometry. Many thanks for answer my question!

praksharma commented 9 months ago

Can you please paste your code in correct format? It is incredibly difficult to read the code.