Mechanical to Rocky: stress export and mapping

dayana_behrens Member Posts: 5
First Comment


I want to export and map a stress field from Mechanical to the particles in Rocky. As a start, So far I tried to access particles and overwrite their velocity component by the python shell. However I cannot find a way to overwrite the particle properties in Rocky to simulate drag force.
This script works to export or overwrite the velocity arrays or other properties to csv, but it does not ovewrwrite them intern in the Rocky simulation, so I can run the simulation with the new velocities:

import csv
import os

# Assuming you have already imported necessary modules and obtained study and particles

output_dir = r'C:\Users\dbehrens\Desktop\grosses Modell'
output_file = os.path.join(output_dir, 'particle_data_1.csv')

# Open the CSV file in write mode with newline=''
with open(output_file, 'w', newline='') as csvfile:
    writer = csv.writer(csvfile)
    study = app.GetStudy()
    particles = study.GetParticles()
    # Write header
    writer.writerow(['X', 'Y', 'Z', 'Absolute Translational Velocity', 'Particle ID', 'Particle Size'])

    # Iterate over particles
    # Geschwindigkeits-, Partikel-ID- und Partikelgrößenarrays für den Zeitpunkt 10 abrufen
    velocity_array = particles.GetGridFunction('Absolute Translational Velocity').GetArray(time_step=10)
    particle_id_array = particles.GetGridFunction('Particle ID').GetArray(time_step=10)
    particle_size_array = particles.GetGridFunction('Particle Size').GetArray(time_step=10)

    # Schleife durch die Partikel
    for i, particle in enumerate(particles.IterParticles(time_step=10)):
        # Koordinaten des Partikels
        x, y, z = particle.x, particle.y, particle.z
        # Absolute Translationsgeschwindigkeit des Partikels
        velocity = velocity_array[i]
        # Partikel-ID
        particle_id = particle_id_array[i]
        # Partikelgröße
        particle_size = particle_size_array[i]
        # Schreiben der Daten in die CSV-Datei
        writer.writerow([x, y, z, velocity, particle_id, particle_size])
        print("Particle Coordinates:", x, y, z)
        print("Absolute Translational Velocity:", velocity)
        print("Particle ID:", particle_id)
        print("Particle Size:", particle_size)

print(f"Data written to {output_file}")