|
49 | 49 | from ansys.dyna.core import Deck
|
50 | 50 | from ansys.dyna.core import keywords as kwd
|
51 | 51 | from ansys.dyna.core.pre.examples.download_utilities import EXAMPLES_PATH, DownloadManager
|
52 |
| -from ansys.dyna.core.run.linux_runner import LinuxRunner |
| 52 | + |
| 53 | +# from ansys.dyna.core.run.linux_runner import LinuxRunner |
| 54 | +from ansys.dyna.core.run.local_solver import run_dyna |
53 | 55 | from ansys.dyna.core.run.options import MemoryUnit, MpiOption, Precision
|
54 |
| -from ansys.dyna.core.run.windows_runner import WindowsRunner |
| 56 | + |
| 57 | +# from ansys.dyna.core.run.windows_runner import WindowsRunner |
55 | 58 |
|
56 | 59 | # sphinx_gallery_thumbnail_path = '_static/pre/opt/plate_thickness.png'
|
57 | 60 |
|
@@ -276,16 +279,15 @@ def write_input_deck(**kwargs):
|
276 | 279 |
|
277 | 280 |
|
278 | 281 | def run_job(directory):
|
279 |
| - if os.name == "nt": |
280 |
| - runner = WindowsRunner( |
281 |
| - ncpu=2, memory=2, precision=Precision.SINGLE, mpi_option=MpiOption.MPP_INTEL_MPI, memory_unit=MemoryUnit.MB |
282 |
| - ) |
283 |
| - elif os.name == "posix": |
284 |
| - runner = LinuxRunner( |
285 |
| - ncpu=2, memory=2, precision=Precision.DOUBLE, mpi_option=MpiOption.MPP_INTEL_MPI, memory_unit=MemoryUnit.MB |
286 |
| - ) |
287 |
| - runner.set_input("input.k", directory) |
288 |
| - runner.run() # Run LS-DYNA simulation |
| 282 | + run_dyna( |
| 283 | + "input.k", |
| 284 | + working_directory=directory, |
| 285 | + ncpu=2, |
| 286 | + memory=2, |
| 287 | + precision=Precision.SINGLE, |
| 288 | + mpi_option=MpiOption.MPP_INTEL_MPI, |
| 289 | + memory_unit=MemoryUnit.MB, |
| 290 | + ) |
289 | 291 | assert os.path.isfile(os.path.join(directory, "d3plot")), "No result file found"
|
290 | 292 |
|
291 | 293 |
|
@@ -340,38 +342,47 @@ def get_plate_displacement(directory):
|
340 | 342 | # ~~~~~~~~~~~~~~~~~~~~~~
|
341 | 343 | #
|
342 | 344 |
|
343 |
| -for iteration in range(0, max_iterations): |
344 |
| - # Define thickness based on iteration |
| 345 | +all_results = [] |
| 346 | + |
| 347 | +for iteration in range(max_iterations): |
| 348 | + # Define thickness for this iteration |
345 | 349 | thickness = initial_thickness + thickness_increment * iteration
|
346 |
| - wd = os.path.join(workdir.name, "thickness_%.4s" % thickness) |
347 |
| - print(wd) |
| 350 | + wd = os.path.join(workdir.name, f"thickness_{thickness:.4f}") |
348 | 351 | pathlib.Path(wd).mkdir(exist_ok=True)
|
349 | 352 | # Create LS-Dyna input deck with new thickness
|
350 | 353 | write_input_deck(thickness=thickness, wd=wd)
|
351 |
| - # Run Solver |
352 | 354 | try:
|
| 355 | + # Run solver |
353 | 356 | run_job(wd)
|
354 |
| - # Run PyDPF Post |
| 357 | + # Post-process displacement |
355 | 358 | time_data, max_disp_data, min_disp_data = get_plate_displacement(wd)
|
356 |
| - reduced_time_data = [t * 1000 for t in time_data] |
357 |
| - # Determine if target displacement is reached |
| 359 | + reduced_time_data = [t * 1000 for t in time_data] # Convert to ms |
| 360 | + # Store result |
| 361 | + all_results.append({"thickness": thickness, "time": reduced_time_data, "max_disp": max_disp_data}) |
| 362 | + # Check if target displacement is reached |
358 | 363 | if max(max_disp_data) <= target_displacement:
|
359 |
| - print("Final Thickness: %.4s, Max Plate Displacement: %.5s" % (thickness, max(max_disp_data))) |
360 |
| - plt.plot( |
361 |
| - reduced_time_data, max_disp_data, "r", label="Max Plate Displacement with %.4s thickness" % thickness |
362 |
| - ) |
| 364 | + print(f"Target displacement reached at thickness {thickness:.4f}") |
363 | 365 | break
|
364 |
| - # Add series to the plot |
365 |
| - plt.plot(reduced_time_data, max_disp_data, "b") |
366 | 366 |
|
367 | 367 | except Exception as e:
|
368 |
| - print(e) |
| 368 | + print(f"Iteration {iteration} failed:", e) |
| 369 | + |
369 | 370 | ###############################################################################
|
370 | 371 | # Generate graphical output
|
371 | 372 | # ~~~~~~~~~~~~~~~~~~~~~~~~~
|
372 | 373 | #
|
373 | 374 |
|
374 |
| -plt.xlabel("Time (e^-3 s)") |
| 375 | +# Now plot all results |
| 376 | +plt.figure(figsize=(8, 5)) |
| 377 | +for res in all_results: |
| 378 | + thickness = res["thickness"] |
| 379 | + time_data = res["time"] |
| 380 | + max_disp_data = res["max_disp"] |
| 381 | + color = "r" if max(max_disp_data) <= target_displacement else "b" |
| 382 | + label = f"Thickness {thickness:.4f}" |
| 383 | + plt.plot(time_data, max_disp_data, color=color, label=label) |
| 384 | +plt.xlabel("Time (ms)") |
375 | 385 | plt.ylabel("Displacement (mm)")
|
376 |
| -plt.legend() |
| 386 | +plt.title("Plate Displacement vs Time for Different Thicknesses") |
| 387 | +plt.grid(True) |
377 | 388 | plt.show()
|
0 commit comments