示例#1
0
    def __init__(self, args, source_height=10):
        '''
        source_height represents the ammount of liquid in the first cup at the beginning of the episode. The height should be
        a value between 1cm and 10cm.
        '''
        self.args = args
        self.path = args.path
        self.min_x = args.min_x
        self.max_x = args.max_x
        self.min_y = args.min_y
        self.max_y = args.max_y
        self.max_volume = args.max_volume
        self.frames_per_action = 1  # How many frames to run before selecting a new action
        self.init_height = source_height

        # Loading the scene
        preonpy.show_progressbar = False
        self.scene = preonpy.Scene(self.path)

        # Load scene objects
        self.solver = self.scene.find_object("PreonSolver_1")
        self.sensor_cup1 = self.scene.find_object("Sensor_Cup1")
        self.sensor_cup2 = self.scene.find_object("Sensor_Cup2")
        self.cup1 = self.scene.find_object("Cup1")
        self.cup2 = self.scene.find_object("Cup2")
        self.Box = self.scene.find_object("BoxDomain_1")
        self.Source = self.scene.find_object("VolumeSource_1")

        # Get simulation parameters
        self.frame_rate = self.scene.__getitem__("simulation frame rate")
        self.timestep_per_frame = 1.0 / self.frame_rate
        #self.time_step = self.solver.__getitem__("timestep")
        #self.steps_per_frame = int((1/self.frame_rate) / self.time_step)

        # Set trajectorie points for the first 2 frames
        init_angle = np.array(self.cup1.__getitem__("euler angles"))[1]
        init_pos = np.array(self.cup1.__getitem__("position"))
        init_frames = 2

        # Set initial volume
        self.Source.__setitem__("scale", [0.1, 0.1, self.init_height / 100])

        self.trajectorie_angles = self._set_keyframes(
            [self.cup1, self.sensor_cup1], [], 0, init_angle,
            'euler angles theta')
        self.trajectorie_posx = self._set_keyframes(
            [self.cup1, self.sensor_cup1], [], 0, init_pos[0], 'position x')
        self.trajectorie_posy = self._set_keyframes(
            [self.cup1, self.sensor_cup1], [], 0, init_pos[2], 'position z')
        self.trajectorie_angles = self._set_keyframes(
            [self.cup1, self.sensor_cup1], self.trajectorie_angles,
            self.timestep_per_frame * init_frames, init_angle,
            'euler angles theta')
        self.trajectorie_posx = self._set_keyframes(
            [self.cup1, self.sensor_cup1], self.trajectorie_posx,
            self.timestep_per_frame * init_frames, init_pos[0], 'position x')
        self.trajectorie_posy = self._set_keyframes(
            [self.cup1, self.sensor_cup1], self.trajectorie_posy,
            self.timestep_per_frame * init_frames, init_pos[2], 'position z')

        # Run initial frames to allow liquid to settle down
        self.scene.simulate(0, init_frames)
        self.current_frame = init_frames

        # Get some values from the simulation
        self.init_particles = self.scene.get_statistic("Fluid Particles",
                                                       self.scene.elapsed_time)
        self.cup1_size = np.round(np.array(self.cup1.__getitem__("scale")) *
                                  100,
                                  decimals=2)[[0,
                                               2]]  # diameter and height in cm
        self.cup2_size = np.round(np.array(self.cup2.__getitem__("scale")) *
                                  100,
                                  decimals=2)[[0,
                                               2]]  # diameter and height in cm

        self.update_stats()
#The aim of this script is to launch ref_0bulk.prscene PreonLab E-motor model with several values of injection flow rates and rotation speeds
#For more information about this script, please contact [email protected]
#A description of all PreonLab Python functions is available at : http://fifty2.eu/PreonLab/preonpy-4.1/

import preonpy #Here, we import the Python interface of PreonLab. For more information, please refer to PreonLab manual.
import numpy as np #We will use numpy to create arrays

SimuList = [0, 1, 2, 3, 4, 5, 6, 7] #Will be useful to get index of each load case
OilFlowRate = np.array([0.5, 0.5, 3, 3, 1, 1, 1, 1]) #L/min The list of flow rates
ShaftVelocity = np.array([2000, 14000, 2000, 14000, 2000, 4000, 7000, 14000]) #RPM The list of rotation speeds
SimulationTime = np.array([0.6, 0.2, 0.6, 0.2, 0.6, 0.5, 0.3, 0.2]) #as higher rotation speed makes simulation faster to converge, we will set the simulation time for each case.
NbOfFramesPerSimu = 50 #The number of frames we want to save for each case

for SimuRef in SimuList: #We create a loop to iterate over SimuList
    print("Simulating "+str(ShaftVelocity[SimuRef])+" RPM, "+str(OilFlowRate[SimuRef])+" l/min, "+str(SimulationTime[SimuRef])+" s") #Text : current load case
    s=preonpy.Scene("C:/Data/PREONLAB/ref_0bulk.prscene") #Opens the reference case
    s.save("C:/Data/PREONLAB/Simulation/DOE/"+"FR"+str(OilFlowRate[SimuRef]).replace('.','')+"ShaftVel"+str(ShaftVelocity[SimuRef])+".prscene", as_portable=False) #Saves the case as a new file in a folder
    Rotation = s.find_object("ROTATION") #Here, a transform group named "ROTATION" is master for the transformation of all shaft parts. We will set its rotation speed to the desired one.
    Rotation["revolutions per second"] = ShaftVelocity[SimuRef]/60 #Sets the rotation speed in rotation per second according to ShaftVelocity list
    Source = s.find_object("AreaSource_1") #The injector source is named "AreaSource_1"
    Source["volume flow rate"] = OilFlowRate[SimuRef]/1000/60 #We set the flow rate in m3/s according to OilFlowRate list
    s.framerate = NbOfFramesPerSimu/SimulationTime[SimuRef] #We set the framerate so that NbOfFramesPerSimu frames are saved in SimulationTime duration
    s.view_framerate = NbOfFramesPerSimu/SimulationTime[SimuRef] #We set the view framerate equal to simulation framerate
    s.save() #save the current configuration
    s.simulate(0, str(SimulationTime[SimuRef])+"s") #Launches the simulation according to SimulationTime duration
    #C:/AVL_AST/PreonLab/PreonLab/ffmpeg-20190212-9f33b0e-win64-static/bin/ffmpeg.exe -f image2 -start_number 0 -framerate 10 -i C:/Avamar/U22P37/PreonScenes/untitled/Visualization/PreonRenderer_1/CamPersp/%06d.png -vf "pad=width=iw+mod(iw\,2):height=ih+mod(ih\,2):x=0:y=0:color=black" -r 10 -c:v libx264 -pix_fmt yuv420p -crf 23 -t 8.6 C:/Avamar/U22P37/PreonScenes/outputfile.mp4
    
    
    
    
    
示例#3
0
    I = np.identity(3)
    K = np.array([[0, -v[2], v[1]], [v[2], 0, -v[0]], [-v[1], v[0], 0]])
    R = I + K + K @ K * ((1 - c) / (s ** 2))
    sy = math.sqrt(R[0, 0] * R[0, 0] + R[1, 0] * R[1, 0])
    singular = sy < 1e-6
    if not singular:
        x = math.atan2(R[2, 1], R[2, 2])
        y = math.atan2(-R[2, 0], sy)
        z = math.atan2(R[1, 0], R[0, 0])
    else:
        x = math.atan2(-R[1, 2], R[1, 1])
        y = math.atan2(-R[2, 0], sy)
        z = 0
    return np.array([x, y, z]) * 180 / np.pi

s=preonpy.Scene(scene_path + scene_name + ".prscene")
i = 0;
for obj_name in s.object_names: 
    obj = s.find_object(obj_name)
    if obj.type == "Mesh" and inlet_name in obj_name :
        print(obj_name + " is area source")
        obj["behavior"] = "inactive"
        obj["render mode"] = "invisible"
        source = s.create_object("Area source")
        source["inflow unit"] = "volumeFlowRate"
        source["volume flow rate"] = flow_rates[i]
        ressource = obj.get_connected_objects("MeshResource", 0)
        ressource = ressource[0]
        meshpath = ressource["mesh file"]
        if mesh_path_is_relative :
            meshpath = scene_path + scene_name + "/" + meshpath
示例#4
0

def find_object_active_frames(s, obj):
    #Find Heat Flux object activity frames
    keys = obj.get_keyframes("behavior")
    keys_times = [key[0] for key in keys]
    keys_frames = [
        preonpy.to_frame(key_time, scene=s) for key_time in keys_times
    ]
    keys_val = [1 if i == 'active' else 0 for i in [key[1] for key in keys]]
    return keyframes_to_active_frames(s, keys_frames, keys_val)


#Load file. If several are available, only the first one will be loaded !
File = glob.glob('*.prscene')[0]
s = preonpy.Scene(File)

HeatFluxSensors = find_heat_flux_sensors(s)
for HeatFluxSensor in HeatFluxSensors:
    if (sensor_plane_is_connected(HeatFluxSensor)
            and keyframe_is_done(HeatFluxSensor)):
        #Find solids objects connected to heat flux sensors (only the first one is considered !)
        Solid = HeatFluxSensor.get_connected_objects("TriangleMesh", False)[0]
        print(HeatFluxSensor.name + " gets its mesh from " + Solid.name)

        #Find temperature reference sensor plane, if any (only the first one is considered !)
        SensorPlane = HeatFluxSensor.get_connected_objects(
            "SensorPlaneTemperature", False)[0]
        print(HeatFluxSensor.name + " gets its reference temperature from " +
              SensorPlane.name)
        SensorActiveFrames = find_object_active_frames(s, HeatFluxSensor)
OilFlowRate = np.array([120,120,120,66,66,120,66]) #L/min The list of flow rates
ShaftVelocity = np.array([2530,2530,1500,2530,520,520,1500]) #RPM The list of rotation speeds
NbOfRotations = 10
NbOfFramesPerSimu = 200 #The number of frames we want to save for each case
NbOfSources = 75
OilDensity = np.array([930,902,930,930,930,930,930]) #kg/m3
OilViscosity = np.array([0.00699,0.00321,0.00699,0.00699,0.00699,0.00699,0.00699]) #Pa.s
OilSurfaceTension = np.array([0.0293,0.0275,0.0293,0.0293,0.0293,0.0293,0.0293]) #N/m
OilTemperature = np.array([80,120,80,80,80,80,80]) #°C
Spacing = 0.0002
DOEdir = "C:/Data/PREONLAB/---/"


for SimuRef in SimuList: #We create a loop to iterate over SimuList
    print("Simulating "+str(ShaftVelocity[SimuRef])+" RPM, "+str(OilFlowRate[SimuRef])+" l/min, "+str(OilTemperature[SimuRef])+" °C") #Text : current loadcase
    s=preonpy.Scene("C:/Data/PREONLAB/---/REF.prscene") #Opens the reference case
    ModelName = str(OilFlowRate[SimuRef]).replace('.','')+"lmin"+str(ShaftVelocity[SimuRef])+"RPM"+str(OilTemperature[SimuRef])+"C"
    s.save(DOEdir+ModelName+".prscene", as_portable=False) #Saves the case as a new file in a folder
    Rotation = s.find_object("Rotation") #Here, a transform group named "ROTATION" is master for the transformation of all shaft parts. We will set its rotation speed to the desired one.
    Rotation["revolutions per second"] = ShaftVelocity[SimuRef]/60 #Sets the rotation speed in rotation per second accordind to ShaftVelocity list
    
    for obj_name in s.object_names:
        obj = s.find_object(obj_name)
        if obj.type == "Area source":
            s.find_object(obj_name)["volume flow rate"]  = OilFlowRate[SimuRef]/1000/60/NbOfSources #We set the flow rate in m3/s according to OilFlowRate list
            print(obj_name + " is area source")
            
    SimulationTime = np.round(1/ShaftVelocity[SimuRef]*60*NbOfRotations,4)
    s['view frame rate'] = np.floor(NbOfFramesPerSimu/SimulationTime) #We set the framerate so that NbOfFramesPerSimu frames are saved in SimulationTime duration
    s['simulation frame rate'] = np.floor(NbOfFramesPerSimu/SimulationTime) #We set the view framerate equal to simulation framerate
    Solver = s.find_object("PreonSolver_1")