Skip to content

Commit c101171

Browse files
committed
something is off
1 parent 2255f80 commit c101171

File tree

10 files changed

+3617
-41
lines changed

10 files changed

+3617
-41
lines changed

examples/ansys/Readme.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ For the linux machine:
2525
Create a new python env. Assuming you using windows powerhsell, install the required dependencies:
2626

2727
```bash
28-
pip install tesseract-core[runtime]
28+
pip install tesseract-core[runtime] trimesh
2929
```
3030

3131
Clone this repository, navigate to the `examples/ansys/spaceclaim_tess` directory and start the Tesseract runtime server with:
3232

3333
```bash
34-
tesseract-runtime serve --port <port_number_1>
34+
tesseract-runtime serve --port <port_number_1> --host 0.0.0.0
3535
```
3636
Note that we dont build a Tesseract image for SpaceClaim in this example. This is because SpaceClaim cannot be installed in a containerized environment. You can test it using git bash and your specific Spaceclaim.exe Path:
3737

3838
```bash
39-
curl -d '{"inputs":{"differentiable_bar_parameters": [[0, 3.14], [0.39, 3.53], [0.79, 3.93], [1.18, 4.32], [1.57, 4.71], [1.96, 5.11], [2.36, 5.50], [2.75, 5.89]], "differentiable_plane_parameters": [200, 600], "non_differentiable_parameters": [800, 100], "string_parameters":["F:\\Ansys installations\\ANSYS Inc\\v241\\scdm\\SpaceClaim.exe", "geometry_generation.scscript"]}}' -H "Content-Type: application/json" http://127.0.0.1:8000/apply
39+
curl -d '{"inputs":{"differentiable_bar_parameters": [[0, 3.14], [0.39, 3.53], [0.79, 3.93], [1.18, 4.32], [1.57, 4.71], [1.96, 5.11], [2.36, 5.50], [2.75, 5.89]], "differentiable_plane_parameters": [200, 600], "non_differentiable_parameters": [800, 100], "string_parameters":["F:\\ANSYS Inc\\v242\\scdm\\SpaceClaim.exe", "geometry_generation.scscript"]}}' -H "Content-Type: application/json" http://172.26.3.35:443/apply
4040
```
4141

42+
4243
or the equivalent on powershell:
4344

4445
```powershell
0 Bytes
Binary file not shown.

examples/ansys/fem_tess/tesseract_api.py

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ def stress(u_grad, theta):
117117
lmbda = E * nu / ((1 + nu) * (1 - 2 * nu))
118118

119119
epsilon = 0.5 * (u_grad + u_grad.T)
120-
sigma = lmbda * jnp.trace(epsilon) * jnp.eye(self.dim) + 2 * mu * epsilon
121120

122121
sigma = lmbda * jnp.trace(epsilon) * jnp.eye(self.dim) + 2.0 * mu * epsilon
123122
return sigma
@@ -141,6 +140,7 @@ def set_params(self, params: jnp.ndarray) -> None:
141140
# Override base class method.
142141
full_params = jnp.ones((self.fe.num_cells, params.shape[1]))
143142
full_params = full_params.at[self.fe.flex_inds].set(params)
143+
print(self.fe.num_quads)
144144
thetas = jnp.repeat(full_params[:, None, :], self.fe.num_quads, axis=1)
145145
self.full_params = full_params
146146
self.internal_vars = [thetas]
@@ -209,6 +209,7 @@ def bc_factory(
209209
# Create a factory that captures the current value of i
210210
def make_location_fn(idx):
211211
def location_fn(point, index):
212+
# jax.debug.print("Mask at point {}: {}", point, jax.lax.dynamic_index_in_dim(masks, index, 0, keepdims=False))
212213
return (
213214
jax.lax.dynamic_index_in_dim(masks, index, 0, keepdims=False)
214215
== idx
@@ -218,12 +219,18 @@ def location_fn(point, index):
218219

219220
def make_value_fn(idx):
220221
def value_fn(point):
222+
# jax.debug.print("Value {} at point {}", jax.lax.dynamic_index_in_dim(values, idx, 0, keepdims=False), point)
221223
return values[idx]
222224

223225
return value_fn
224226

225227
def make_value_fn_vn(idx):
226228
def value_fn_vn(u, x):
229+
jax.debug.print(
230+
"Van Neumann Value {} at point {}",
231+
jax.lax.dynamic_index_in_dim(values, idx, 0, keepdims=False),
232+
x,
233+
)
227234
return values[idx]
228235

229236
return value_fn_vn
@@ -238,6 +245,9 @@ def value_fn_vn(u, x):
238245
dirichlet_values = jnp.array(dirichlet_values)
239246
van_neumann_values = jnp.array(van_neumann_values)
240247

248+
print(f"dirichlet_values: {dirichlet_values}")
249+
print(f"van_neumann_values: {van_neumann_values}")
250+
241251
dirichlet_location_fns, dirichlet_value_fns = bc_factory(
242252
dirichlet_mask, dirichlet_values
243253
)
@@ -281,40 +291,6 @@ def apply_fn(inputs: dict) -> dict:
281291
Returns:
282292
Dictionary containing the compliance of the structure.
283293
"""
284-
from typing import TypeVar
285-
286-
T = TypeVar("T")
287-
288-
def stop_grads_int(x: T) -> T:
289-
"""Stops gradient computation.
290-
291-
We cannot use jax.lax.stop_gradient directly because Tesseract meshes are
292-
nested dictionaries with arrays and integers, and jax.lax.stop_gradient
293-
does not support integers.
294-
295-
Args:
296-
x: Input value.
297-
298-
Returns:
299-
Value with stopped gradients.
300-
"""
301-
302-
def stop(x):
303-
return jax._src.ad_util.stop_gradient_p.bind(x)
304-
305-
return jax.tree_util.tree_map(stop, x)
306-
307-
# stop grads on all inputs except rho
308-
309-
# problem, fwd_pred = setup(
310-
# pts=stop_grads_int(inputs["hex_mesh"]["points"][: inputs["hex_mesh"]["n_points"]]),
311-
# cells=stop_grads_int(inputs["hex_mesh"]["faces"][: inputs["hex_mesh"]["n_faces"]]),
312-
# dirichlet_mask=stop_grads_int(inputs["dirichlet_mask"]),
313-
# dirichlet_values=stop_grads_int(inputs["dirichlet_values"]),
314-
# van_neumann_mask=stop_grads_int(inputs["van_neumann_mask"]),
315-
# van_neumann_values=stop_grads_int(inputs["van_neumann_values"]),
316-
# )
317-
318294
# no stop grads
319295
problem, fwd_pred = setup(
320296
pts=inputs["hex_mesh"]["points"][: inputs["hex_mesh"]["n_points"]],

examples/ansys/gf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
images = []
44

5-
for i in range(30):
5+
for i in range(60):
66
filename = f"tmp_img/mesh_optim_{i:03d}.png"
77
images.append(imageio.imread(filename))
88
print(f"Added {filename} to gif.")
9-
imageio.mimsave("mesh_optim.gif", images, fps=10)
9+
# make sure the gif repeats forever
10+
imageio.mimsave("mesh_optim.gif", images, fps=10, loop=0)

examples/ansys/mesh_optim.gif

885 KB
Loading

examples/ansys/optim_bars.ipynb

Lines changed: 3597 additions & 0 deletions
Large diffs are not rendered by default.

examples/ansys/demo_2.ipynb renamed to examples/ansys/optim_grid.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,14 @@
8484
},
8585
{
8686
"cell_type": "code",
87-
"execution_count": 342,
87+
"execution_count": null,
8888
"id": "8a407fb1",
8989
"metadata": {},
9090
"outputs": [],
9191
"source": [
9292
"# design_tess = Tesseract.from_image(\"design-tube-sdf\")\n",
9393
"# design_tess.serve()\n",
94+
"IP = \"172.26.3.35\"\n",
9495
"design_tess = Tesseract.from_tesseract_api(\"hot_design_tess/tesseract_api.py\")\n",
9596
"bar_3d_tess = Tesseract.from_tesseract_api(\"bars_3d_tess/tesseract_api.py\")"
9697
]

examples/ansys/out

Whitespace-only changes.

examples/ansys/rho_optim.gif

-840 KB
Loading

examples/ansys/rho_optim_x.gif

2.23 MB
Loading

0 commit comments

Comments
 (0)