I am extracting power losses for a applied current profile (maximum and minimum) from Maxwell and mapping the corresponding power loss curve in Icepak for a Joule heating problem. This is manual method and taking 30min of time.
Hi,
This script processes power loss data from Maxwell simulations and prepares datasets for transient analysis in Icepak. The losses are extracted using the AEDT Field Calculator and used to generate square-wave power loss profiles, which are then applied as transient boundary conditions.
Before running this script, ensure that:
obj_list
from ansys.aedt.core import Icepak from ansys.aedt.core.maxwell import Maxwell3d def get_obj_losses(obj_list: list[str], app: Maxwell3d) -> dict: """ Extract power losses from Maxwell3D using the AEDT Field Calculator. Parameters: obj_list (list[str]): List of object names to extract losses from. app (Maxwell3d): Maxwell3D application instance. Returns: dict: A dictionary with object names as keys and their corresponding power losses as values. """ losses = {} for obj in obj_list: my_expression = { "name": "OhmicLossCalc", "description": "Compute ohmic losses", "design_type": ["Maxwell3D"], "fields_type": ["Fields"], "primary_sweep": "Freq", "assignment_type": ["Volume"], "operations": [ "NameOfExpression('Ohmic-Loss')", f"EnterVolume('{obj}')", "Operation('VolumeValue')", "Operation('Integrate')" ], "report": ["Data Table"] } xpr = app.post.fields_calculator.add_expression(my_expression, obj) losses[obj] = app.post.fields_calculator.evaluate(xpr) return losses def generate_dataset(y1: float, y2: float, t1: float, t2: float, n_cycles: int) -> tuple[list[float], list[float]]: """ Generate a time-dependent square wave dataset for transient analysis. The generated wave alternates between two power loss values (y1 and y2) over specified time intervals. Parameters: y1 (float): Power loss during the high state (W). y2 (float): Power loss during the low state (W). t1 (float): Duration of the high state (s). t2 (float): Duration of the low state (s). n_cycles (int): Number of cycles to generate. Returns: tuple[list[float], list[float]]: Two lists representing time (x-values) and corresponding power loss (y-values). """ x_values, y_values = [], [] period = t1 + t2 for i in range(n_cycles): t_start = i * period x_values += [t_start, t_start + t1, t_start + t1, t_start + period] y_values += [y1, y1, y2, y2] return x_values, y_values # List of objects for which losses will be computed obj_list = ["HVA", "HVB", "HVC"] # Initialize Maxwell3D application m3d = Maxwell3d() # Simulate for minimum current condition and extract losses min_current = "220A" # Set min_current and run simulation in Maxwell (custom setup needed) # ... min_losses = get_obj_losses(obj_list, m3d) # Simulate for maximum current condition and extract losses max_current = "340A" # Set max_current and run simulation in Maxwell (custom setup needed) # ... max_losses = get_obj_losses(obj_list, m3d) # Initialize Icepak application ipk = Icepak() # Generate datasets and apply transient boundary conditions in Icepak for obj in obj_list: x, y = generate_dataset(max_losses[obj], min_losses[obj], 10, 30, 5) dataset_name = f"{obj}_power" ds = ipk.create_dataset(name=dataset_name, x=x, y=y, x_unit="s", y_unit="W", is_project_dataset=False) ipk.assign_solid_block(obj, ipk.create_dataset_transient_assignment(ds.name), f"{obj}_block")