Skip to content

Commit 9b6e872

Browse files
committed
removed some unnec code
1 parent da32bb7 commit 9b6e872

File tree

1 file changed

+37
-33
lines changed

1 file changed

+37
-33
lines changed

examples/ansys/pymapdl_tess/test.py

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,57 @@
1-
"""
2-
/usr/ansys_inc/v241/ansys/bin/ansys241 -port 50005 -grpc
3-
"""
1+
"""/usr/ansys_inc/v241/ansys/bin/ansys241 -port 50005 -grpc"""
2+
43
import os
54

65
import numpy as np
76
from tesseract_core import Tesseract
87

9-
108
# load the MAPDL server's address from your environment
119
host = os.getenv("MAPDL_HOST")
1210
if host is None:
13-
raise ValueError("Unable to read $MAPDL_HOST from the environment. " + \
14-
"Use 'export MAPDL_HOST=X.X.X.X' for local IP address of your MAPDL Instance.")
11+
raise ValueError(
12+
"Unable to read $MAPDL_HOST from the environment. "
13+
+ "Use 'export MAPDL_HOST=X.X.X.X' for local IP address of your MAPDL Instance."
14+
)
1515
port = os.getenv("MAPDL_PORT")
1616
if port is None:
17-
raise ValueError("Unable to read $MAPDL_PORT from the environment. " + \
18-
"Use 'export MAPDL_PORT=X' for the port of your MAPDL Instance.")
17+
raise ValueError(
18+
"Unable to read $MAPDL_PORT from the environment. "
19+
+ "Use 'export MAPDL_PORT=X' for the port of your MAPDL Instance."
20+
)
1921

2022

2123
# Initialize Tesseract from api (for testing)
2224
try:
23-
tess_simp_compliance = Tesseract.from_tesseract_api(
24-
"./tesseract_api.py"
25+
tess_simp_compliance = Tesseract.from_tesseract_api("./tesseract_api.py")
26+
except RuntimeError:
27+
raise RuntimeError(
28+
"Unable to load tesseract from api. "
29+
"Ensure that you have installed the build requirements using 'pip install -r tesseract_requirements.txt'"
2530
)
26-
except RuntimeError as e:
27-
raise RuntimeError("Unable to load tesseract from api. " \
28-
"Ensure that you have installed the build requirements using 'pip install -r tesseract_requirements.txt'")
29-
31+
3032
# TODO
3133
# we should probably create some re-usable mesh constructors...
3234
# create a simple Hex mesh using Pyvista
3335
import pyvista as pv
36+
3437
Lx, Ly, Lz = 3, 2, 1
3538
Nx, Ny, Nz = 60, 40, 20
3639
Nx, Ny, Nz = 6, 4, 2
3740
grid = pv.ImageData(
3841
dimensions=np.array((Nx, Ny, Nz)) + 1,
39-
#origin=(-Lx / 2, -Ly / 2, -Lz / 2), # The bottom left corner of the data set
40-
origin=(0, 0, 0), # TODO
41-
spacing=(Lx / Nx, Ly / Ny, Lz / Nz), # These are the cell sizes along each axis
42+
# origin=(-Lx / 2, -Ly / 2, -Lz / 2), # The bottom left corner of the data set
43+
origin=(0, 0, 0), # TODO
44+
spacing=(Lx / Nx, Ly / Ny, Lz / Nz), # These are the cell sizes along each axis
4245
)
4346
# repeated casts will eventually expose cell_connectivitiy
44-
mesh = grid.cast_to_structured_grid().cast_to_explicit_structured_grid().cast_to_unstructured_grid()
47+
mesh = (
48+
grid.cast_to_structured_grid()
49+
.cast_to_explicit_structured_grid()
50+
.cast_to_unstructured_grid()
51+
)
4552

4653
from tesseract_api import HexMesh
54+
4755
hex_mesh = HexMesh(
4856
points=mesh.points,
4957
faces=mesh.cell_connectivity.reshape((Nx * Ny * Nz, 8)),
@@ -58,7 +66,7 @@
5866
# dirichlet_mask = np.zeros(hex_mesh.n_points)
5967
# dirichlet_mask[dirichlet_indices] = 1
6068
dirichlet_mask = np.where(on_lhs)[0]
61-
dirichlet_values = np.zeros((dirichlet_mask.shape[0]))
69+
dirichlet_values = np.zeros(dirichlet_mask.shape[0])
6270

6371
# von Neumann condition (select nodes at x=Lx with constraints on y and z)
6472
x_lim = Lx
@@ -69,20 +77,22 @@
6977
von_neumann = np.logical_and(
7078
mesh.points[:, 0] >= x_lim,
7179
np.logical_and(
72-
np.logical_and(mesh.points[:,1] >= y_min, mesh.points[:,1] <= y_max),
73-
np.logical_and(mesh.points[:,2] >= z_min, mesh.points[:,2] <= z_max)
74-
)
80+
np.logical_and(mesh.points[:, 1] >= y_min, mesh.points[:, 1] <= y_max),
81+
np.logical_and(mesh.points[:, 2] >= z_min, mesh.points[:, 2] <= z_max),
82+
),
7583
)
7684
# TODO should this be an n_node array?
7785
von_neumann_mask = np.where(von_neumann)[0]
78-
von_neumann_values = (0, 0.0, 0.1 / len(von_neumann_mask)) + np.zeros((von_neumann_mask.shape[0], 3))
86+
von_neumann_values = (0, 0.0, 0.1 / len(von_neumann_mask)) + np.zeros(
87+
(von_neumann_mask.shape[0], 3)
88+
)
7989

8090
# Create a test density field varying from 0 to 1
8191
n_elem = Nx * Ny * Nz
8292
rho = (np.arange(0, n_elem, 1) / n_elem).reshape((n_elem, 1))
8393
rho = 0.5 * np.ones((n_elem, 1))
84-
85-
94+
95+
8696
inputs = {
8797
"dirichlet_mask": dirichlet_mask,
8898
"dirichlet_values": dirichlet_values,
@@ -98,12 +108,6 @@
98108
"vtk_output": "mesh_density.vtk",
99109
}
100110

101-
# cells = np.array([8, 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 10, 11, 12, 13, 14, 15])
102-
cells = np.concatenate([np.array([[8]] * hex_mesh.n_faces), hex_mesh.faces], 1)
103-
celltypes = np.full(hex_mesh.n_faces, pv.CellType.HEXAHEDRON, dtype=np.uint8)
104-
mesh2 = pv.UnstructuredGrid(cells.ravel(), celltypes, hex_mesh.points)
105-
print(mesh.cell_connectivity)
106-
107111
outputs = tess_simp_compliance.apply(inputs)
108112

109113
# Verify relationship between compliance and strain energy
@@ -117,7 +121,7 @@
117121
print(f"Ratio (should be ~1.0): {total_strain_energy / (0.5 * compliance):.6f}")
118122

119123
# Finite difference check
120-
num_tests = 5 # set to 0 if you don't want to run this check
124+
num_tests = 0 # set to 0 if you don't want to run this check
121125
FD_delta = 1.0e-3
122126
f0 = outputs["compliance"]
123127
sensitivity = outputs["sensitivity"]
@@ -130,7 +134,7 @@
130134
# FD_sensitivity[i] = (fupp - f0) / FD_delta
131135
# inputs["rho"][i] -= FD_delta
132136

133-
inputs["rho"][i] -= 2.0*FD_delta
137+
inputs["rho"][i] -= 2.0 * FD_delta
134138
outputs = tess_simp_compliance.apply(inputs)
135139
fdown = outputs["compliance"]
136140
FD_sensitivity[i] = (fupp - fdown) / FD_delta / 2.0

0 commit comments

Comments
 (0)