APDLscript / app.py
jithenderchoudary's picture
Update app.py
f47e6ef verified
raw
history blame
3 kB
import gradio as gr
# APDL Script for ANSYS
apdl_script = """/CLEAR ! Clear any existing database
/PREP7 ! Enter preprocessor
! Define material properties
MP, EX, 1, 210E3 ! Young's Modulus (e.g., Steel)
MP, PRXY, 1, 0.3 ! Poisson's Ratio
! Define geometry (e.g., a rectangular plate)
RECTNG, 0, 100, 0, 50 ! Rectangle from (0,0) to (100,50)
! Define element type and mesh
ET, 1, PLANE183 ! 2D structural element
ESIZE, 5 ! Set element size
AMESH, ALL ! Mesh the area
! Apply boundary conditions
D, NODE(0, 0), ALL, 0 ! Fix the bottom-left corner
D, NODE(100, 0), UY, 0 ! Restrict vertical movement at bottom-right
! Apply loads
F, NODE(50, 50), FX, 1000 ! Apply a horizontal load at the top-middle node
! Solve
FINISH ! Exit preprocessor
/SOLU ! Enter solution processor
ANTYPE, 0 ! Static analysis
SOLVE ! Solve the system
FINISH ! Exit solution processor
! Post-processing for 2D view
/POST1 ! Enter post-processor
PLNSOL, U, SUM ! Plot nodal displacement (2D view)
/IMAGE, SAVE, '2D_View', JPG ! Save 2D view as an image
! Post-processing for 3D view
/VIEW, 1, 1, 1, 1 ! Set 3D view (isometric)
/DV3D ! Enable dynamic 3D view
PLNSOL, S, EQV ! Plot equivalent stress (3D view)
/IMAGE, SAVE, '3D_View', JPG ! Save 3D view as an image
! Exit ANSYS
FINISH
"""
def apdl_script_view():
"""Function to display the APDL script."""
return apdl_script
def upload_step_file(file):
"""Function to handle STEP file upload."""
return f"STEP file '{file.name}' uploaded successfully."
def modify_apdl_script(modified_script):
"""Function to modify and save the APDL script."""
global apdl_script
apdl_script = modified_script
return "APDL script updated successfully."
def execute_script():
"""Placeholder for executing the APDL script."""
# In a real scenario, you would interface with ANSYS here.
return "APDL script executed. Check generated views (2D_View.jpg, 3D_View.jpg)."
# Gradio interface
with gr.Blocks() as app:
gr.Markdown("# ANSYS APDL Script for 2D and 3D Views")
with gr.Row():
gr.Markdown("## Upload STEP File")
step_file = gr.File(label="Upload STEP File")
step_output = gr.Text(label="Upload Status")
with gr.Row():
gr.Markdown("## View or Modify APDL Script")
apdl_view = gr.Textbox(apdl_script, lines=20, label="APDL Script")
modify_button = gr.Button("Save Changes")
with gr.Row():
gr.Markdown("## Execute APDL Script")
execute_button = gr.Button("Run Script")
execution_output = gr.Text(label="Execution Status")
# Define interactions
step_file.upload(upload_step_file, inputs=step_file, outputs=step_output)
modify_button.click(modify_apdl_script, inputs=apdl_view, outputs=step_output)
execute_button.click(execute_script, outputs=execution_output)
# Launch the app
app.launch()