Hello Caster! I’m not sure if this fits your specific use case, but I’m sharing a small code snippet I use to monitor my simulations.
The key is running a loop inside STAT_NON_LINE / DYNA_NON_LINE by iterating over an array of target times and steps. Once the resolution of an interval is complete according to the requested ARCHIVAGE, I extract the displacements (or any required variable; for example, running a prior CALC_CHAMP if you need to extract SIEQ_NOEU).
Another key is "Pythonizing" the output of POST_RELEVE_T by converting it directly into a Pandas DataFrame using .EXTR_TABLE(), making it easy to export clean CSV files via df.to_csv(). In this implementation, the file gets updated/overwritten while maintaining previous time steps, though you can also parameterize the output path or filename if you prefer to save each step separately.
Hope this helps. Cheers!
# Save last result from previous analysis stage
RESNL_LAST = NONLIN
RESNL = [None] * RESNL_STEPS
# General output directory
OUTPUT_DIR = os.path.join(os.path.expanduser('~'), 'project_output', 'extract_depl')
os.makedirs(OUTPUT_DIR, exist_ok=True)
for j in range(RESNL_STEPS):
# Define initial state and time increment steps
if j == 0:
initial_state = [_F(EVOL_NOLI=RESNL_LAST)]
increment_step = [_F(
LIST_INST=l_times_3,
NUME_INST_FIN=NUMBER_OF_SAVES[j],
INST_INIT=paso_anterior
)]
else:
initial_state = [_F(EVOL_NOLI=RESNL[j-1])]
increment_step = [_F(
LIST_INST=l_times_3,
NUME_INST_FIN=NUMBER_OF_SAVES[j],
NUME_INST_INIT=NUMBER_OF_SAVES[j-1]
)]
# Non-linear dynamic analysis computation
RESNL[j] = DYNA_NON_LINE(
ARCHIVAGE=_F(LIST_INST=steps_3),
CHAM_MATER=FIELDMAT,
reuse=NONLIN,
ETAT_INIT=initial_state,
COMPORTEMENT=COMPORTAMIENTO,
EXCIT=excit_nonlin2,
INCREMENT=increment_step,
AMOR_RAYL_RIGI='ELASTIQUE',
SCHEMA_TEMPS=_F(
SCHEMA='HHT',
FORMULATION='DEPLACEMENT',
MODI_EQUI='OUI',
ALPHA=-0.1
),
CONVERGENCE=_F(
ITER_GLOB_MAXI=30, # Increase iterations for generalized Newton solver
RESI_GLOB_RELA=1.E-6 # Standard convergence threshold
),
METHODE='NEWTON',
MODELE=MECA_MOD,
SOLVEUR=SOLV_STABLE,
**contact_keywords
)
# Partial results extraction
SCL_TABLE = POST_RELEVE_T(
ACTION=(
_F(
INTITULE='N_EXTR_PLAC',
OPERATION='EXTRACTION',
TOUT_ORDRE='OUI',
RESULTAT=RESNL[j],
NOM_CHAM='DEPL',
TOUT_CMP="OUI",
GROUP_NO='N_EXTR_PLAC'
),
_F(
INTITULE='N_EXTR_TOP',
OPERATION='EXTRACTION',
TOUT_ORDRE='OUI',
RESULTAT=RESNL[j],
NOM_CHAM='DEPL',
TOUT_CMP="OUI",
GROUP_NO='N_EXTR_TOP'
),
)
)
# Convert extracted table to DataFrame and export to CSV
table_data = SCL_TABLE.EXTR_TABLE()
df_result = pd.DataFrame(table_data.rows)
output_file = os.path.join(OUTPUT_DIR, f'{test_id}-DISPL_LOAD.csv')
df_result.to_csv(output_file, index=False)