Here's how you can accomplish this in ANSYS ACT with APDL:
1. Reading External Files in ACT
First, create an ACT extension to read your .txt files:
# In your ACT Python script
import os
def read_load_file(file_path):
"""Read XYZ Load format file"""
loads = []
with open(file_path, 'r') as f:
for line in f:
if line.strip():
parts = line.strip().split()
x, y, z, load_value = float(parts[0]), float(parts[1]), float(parts[2]), float(parts[3])
loads.append((x, y, z, load_value))
return loads
# Read your three files
heat_gen_1 = read_load_file("path/to/heat_generation_1.txt")
heat_gen_2 = read_load_file("path/to/heat_generation_2.txt")
surface_load = read_load_file("path/to/surface_load.txt")
2. Generate APDL Commands
Create APDL commands to apply the loads:
def generate_apdl_commands(heat_loads_1, heat_loads_2, surface_loads):
apdl_commands = []
# Start APDL block
apdl_commands.append("! Apply combined heat generation loads")
apdl_commands.append("FINISH")
apdl_commands.append("/PREP7")
# Combine heat generation loads and apply to elements
combined_heat_loads = {}
# Combine heat generation loads at same coordinates
for x, y, z, load in heat_loads_1 + heat_loads_2:
coord_key = (x, y, z)
if coord_key in combined_heat_loads:
combined_heat_loads[coord_key] += load
else:
combined_heat_loads[coord_key] = load
# Apply combined heat generation loads
apdl_commands.append("! Combined heat generation loads")
for (x, y, z), total_load in combined_heat_loads.items():
apdl_commands.append(f"! Heat generation at ({x}, {y}, {z})")
apdl_commands.append(f"NSEL,S,LOC,X,{x-0.001},{x+0.001}")
apdl_commands.append(f"NSEL,R,LOC,Y,{y-0.001},{y+0.001}")
apdl_commands.append(f"NSEL,R,LOC,Z,{z-0.001},{z+0.001}")
apdl_commands.append("ESLN,S,1")
apdl_commands.append(f"BFE,ALL,HGEN,1,{total_load}")
apdl_commands.append("ALLSEL,ALL")
# Apply surface loads
apdl_commands.append("! Surface loads")
for x, y, z, load in surface_loads:
apdl_commands.append(f"! Surface load at ({x}, {y}, {z})")
apdl_commands.append(f"NSEL,S,LOC,X,{x-0.001},{x+0.001}")
apdl_commands.append(f"NSEL,R,LOC,Y,{y-0.001},{y+0.001}")
apdl_commands.append(f"NSEL,R,LOC,Z,{z-0.001},{z+0.001}")
apdl_commands.append("ESLN,S,1")
apdl_commands.append(f"SFE,ALL,1,HFLUX,,{load}")
apdl_commands.append("ALLSEL,ALL")
apdl_commands.append("FINISH")
return apdl_commands
3. Alternative: Element-Based Application
If you need more precise element targeting:
def apply_loads_by_element_search(heat_loads_1, heat_loads_2, surface_loads):
apdl_commands = []
apdl_commands.append("FINISH")
apdl_commands.append("/PREP7")
# For each load point, find nearest element
all_coords = set()
for loads in [heat_loads_1, heat_loads_2, surface_loads]:
for x, y, z, _ in loads:
all_coords.add((x, y, z))
# Create coordinate systems and apply loads
coord_id = 1000
for x, y, z in all_coords:
# Find heat generation loads at this coordinate
heat_total = 0
for hx, hy, hz, hload in heat_loads_1 + heat_loads_2:
if abs(hx-x) < 0.001 and abs(hy-y) < 0.001 and abs(hz-z) < 0.001:
heat_total += hload
# Find surface load at this coordinate
surface_val = 0
for sx, sy, sz, sload in surface_loads:
if abs(sx-x) < 0.001 and abs(sy-y) < 0.001 and abs(sz-z) < 0.001:
surface_val = sload
if heat_total != 0 or surface_val != 0:
apdl_commands.append(f"! Loads at ({x}, {y}, {z})")
apdl_commands.append(f"WPCSYS,-1,{coord_id}")
apdl_commands.append(f"WPRO,,,,{x},{y},{z}")
apdl_commands.append(f"NSEL,S,LOC,X,{x-0.001},{x+0.001}")
apdl_commands.append(f"NSEL,R,LOC,Y,{y-0.001},{y+0.001}")
apdl_commands.append(f"NSEL,R,LOC,Z,{z-0.001},{z+0.001}")
apdl_commands.append("ESLN,S,1")
if heat_total != 0:
apdl_commands.append(f"BFE,ALL,HGEN,1,{heat_total}")
if surface_val != 0:
apdl_commands.append(f"SFE,ALL,1,HFLUX,,{surface_val}")
apdl_commands.append("ALLSEL,ALL")
coord_id += 1
return apdl_commands
4. Execute in ACT
Finally, execute the APDL commands in your ACT extension:
def execute_load_application():
# Read files
heat_gen_1 = read_load_file("C:/path/to/heat_gen_1.txt")
heat_gen_2 = read_load_file("C:/path/to/heat_gen_2.txt")
surface_load = read_load_file("C:/path/to/surface_load.txt")
# Generate APDL
apdl_lines = generate_apdl_commands(heat_gen_1, heat_gen_2, surface_load)
# Execute APDL
for line in apdl_lines:
ExtAPI.Application.ScriptByName("MAPDL").ExecuteCommand(line)
Key Points:
- Heat Generation: Uses
BFE,ALL,HGEN command to apply body loads to elements
- Surface Loads: Uses
SFE,ALL,1,HFLUX for surface heat flux
- Load Combination: Automatically sums heat generation loads at identical coordinates
- Element Selection: Uses coordinate-based selection with small tolerance
- File Format: Assumes space-separated X Y Z Load_Value format
Make sure your mesh is already created before running this script, and adjust the coordinate tolerance (0.001) based on your mesh density and coordinate precision.