sensotwin.lifetime_extrapolation.simulation.lib.staticAnalysisGravityCCX

  1import os
  2import numpy as np
  3from . import readVTT
  4
  5def f_setupStaticGravitySimulations(template_name, wind_speed, save_additional_fields = False, working_dir = './'):
  6    '''
  7    Sets up a static CCX simulation with the influence
  8    of gravity forces for the given azimuthal positions
  9    of the rotor blade.
 10
 11    Parameters:
 12    - template_name (string):
 13        Name of the template file in .inp format to adapt for
 14        the static simulation. The file specifies the geometry
 15        of the rotor blade. Element and Node sets have to be
 16        predefined. Boundary conditions, steps and outputs
 17        have to be predefined.
 18    - wind_speed (float):
 19        Average wind speed acting on the entire rotor disc in m/s.
 20    - save_additional_fields (bool):
 21        Flag to save S values for the gravity based simulations in
 22        the .dat file. This slows down the conversion from the .frd
 23        to .vtu file.
 24    - working_dir (string):
 25        Working directory to execute file in.
 26
 27    Returns:
 28    - None
 29    '''
 30    
 31    # define azimuthal positions
 32    numberPositions = 4
 33    stepSize = 360/numberPositions
 34    azimuth_angles = np.arange(0,360,stepSize)
 35    setwork_dir = working_dir
 36
 37    # open input file to add loads
 38    with open(os.path.join(setwork_dir,'IN', template_name + '.inp')) as input_file:
 39        input_lines = input_file.readlines()
 40
 41    nosave_input_lines = []
 42    line_idx = 0
 43    
 44    if not save_additional_fields:
 45        while line_idx < len(input_lines):
 46            current_line = input_lines[line_idx]
 47            if current_line.find('*EL PRINT, ELSET=ALL_ELMS, GLOBAL=YES') != -1:
 48                line_idx +=2
 49            else:
 50                nosave_input_lines.append(current_line)
 51                line_idx +=1
 52        
 53        line_idx = 0
 54        input_lines = nosave_input_lines
 55        nosave_input_lines = []
 56
 57        while line_idx < len(input_lines):
 58            current_line = input_lines[line_idx]
 59            if current_line.find('*NODE FILE, GLOBAL=NO') != -1:
 60                line_idx +=2
 61            else:
 62                nosave_input_lines.append(current_line)
 63                line_idx +=1
 64
 65    input_lines = nosave_input_lines
 66
 67    for i,azimuth_angle in enumerate(azimuth_angles):
 68
 69        step_block_inp = []
 70
 71        # set working directory
 72        # os.chdir(setwork_dir)
 73        folder_name = "Gravity-" + str(int(azimuth_angle))
 74        main_dir = os.path.join(setwork_dir,"OUT")
 75        save_dir = os.path.join(main_dir, folder_name)
 76
 77        if os.path.exists(save_dir) == False:
 78            os.mkdir(save_dir)
 79        
 80        # change working directory to save files in desired folder
 81        # os.chdir(save_dir)
 82
 83        # import gravity 
 84
 85        loads_data_df = readVTT.f_readVTT2DF(os.path.join(setwork_dir, 'IN', 'gravity_loads_transformed.vtt'))
 86        is_current_az = loads_data_df.iloc[0] == azimuth_angle
 87        is_current_az['WindSpeed'] = True
 88        is_current_az = is_current_az.values.tolist()
 89
 90        loads_data_current_df = loads_data_df.iloc[1:,is_current_az]
 91
 92        loads_data = np.array(loads_data_current_df.values.tolist())
 93
 94        # loads_data = np.genfromtxt("../../IN/LoadsTransformed_" + str(int(azimuth_angle)) + ".txt", delimiter =",")
 95        windspeed = loads_data[:,0]
 96        windspeed_float = [float(x) for x in windspeed]
 97        gravity = loads_data[:,1:4]
 98
 99        # find closest wind speed in gravity_loads_transformed.vtt
100        vwind_diff = []
101        for vwind in windspeed_float:
102            vwind_diff.append(abs(wind_speed - vwind))
103
104        windspeed_idx = np.argmin(vwind_diff)
105
106        
107        # # only compute if windspeed > 11.2
108        
109        # if windspeed_float[windspeed_idx] <= 11.2:
110        #     calculate_windspeed = 11.2
111        # else:
112        #     calculate_windspeed = windspeed_float[windspeed_idx]
113
114        load_gravity = 'Load-Gravity'
115
116        # length of centrifugal vector
117        norm_gravity = np.sqrt(np.power(gravity[windspeed_idx,0],2)
118                            + np.power(gravity[windspeed_idx,1],2)
119                            + np.power(gravity[windspeed_idx,2],2))
120
121        step_block_inp.append('** NAME: ' + load_gravity + '   Type: Gravity' + '\n')
122        step_block_inp.append('*DLOAD' + '\n')
123        step_block_inp.append('ALL_ELMS, GRAV,  ' + str(norm_gravity) + ', '
124                            + str((1/norm_gravity)*gravity[windspeed_idx,0]) + ', '
125                            + str((1/norm_gravity)*gravity[windspeed_idx,1]) + ', '
126                            + str((1/norm_gravity)*gravity[windspeed_idx,2]) + '\n')
127
128        # create new input file
129        new_input_lines = []
130        for line in input_lines:
131            current_line = line
132            if line.find('<enter wind speed dependent loads here>') != -1:
133                current_line = ''.join(step_block_inp)
134            new_input_lines.append(current_line)
135
136        # write new input file
137        with open(os.path.join(save_dir, template_name.strip('_TEMPLATE') + '_' + str(windspeed_float[windspeed_idx]).replace('.','_') + '.inp'), 'w') as output_file:
138            for line in new_input_lines:
139                output_file.write(line)
140
141def main():
142    template_name = 'STARTER_SNL61p5_13LY_S8R_29052024_TEMPLATE' # without .inp
143    wind_speed = 10
144    f_setupStaticGravitySimulations(template_name, wind_speed)
145
146if __name__ == '__main__':
147    main()
def f_setupStaticGravitySimulations( template_name, wind_speed, save_additional_fields=False, working_dir='./'):
  6def f_setupStaticGravitySimulations(template_name, wind_speed, save_additional_fields = False, working_dir = './'):
  7    '''
  8    Sets up a static CCX simulation with the influence
  9    of gravity forces for the given azimuthal positions
 10    of the rotor blade.
 11
 12    Parameters:
 13    - template_name (string):
 14        Name of the template file in .inp format to adapt for
 15        the static simulation. The file specifies the geometry
 16        of the rotor blade. Element and Node sets have to be
 17        predefined. Boundary conditions, steps and outputs
 18        have to be predefined.
 19    - wind_speed (float):
 20        Average wind speed acting on the entire rotor disc in m/s.
 21    - save_additional_fields (bool):
 22        Flag to save S values for the gravity based simulations in
 23        the .dat file. This slows down the conversion from the .frd
 24        to .vtu file.
 25    - working_dir (string):
 26        Working directory to execute file in.
 27
 28    Returns:
 29    - None
 30    '''
 31    
 32    # define azimuthal positions
 33    numberPositions = 4
 34    stepSize = 360/numberPositions
 35    azimuth_angles = np.arange(0,360,stepSize)
 36    setwork_dir = working_dir
 37
 38    # open input file to add loads
 39    with open(os.path.join(setwork_dir,'IN', template_name + '.inp')) as input_file:
 40        input_lines = input_file.readlines()
 41
 42    nosave_input_lines = []
 43    line_idx = 0
 44    
 45    if not save_additional_fields:
 46        while line_idx < len(input_lines):
 47            current_line = input_lines[line_idx]
 48            if current_line.find('*EL PRINT, ELSET=ALL_ELMS, GLOBAL=YES') != -1:
 49                line_idx +=2
 50            else:
 51                nosave_input_lines.append(current_line)
 52                line_idx +=1
 53        
 54        line_idx = 0
 55        input_lines = nosave_input_lines
 56        nosave_input_lines = []
 57
 58        while line_idx < len(input_lines):
 59            current_line = input_lines[line_idx]
 60            if current_line.find('*NODE FILE, GLOBAL=NO') != -1:
 61                line_idx +=2
 62            else:
 63                nosave_input_lines.append(current_line)
 64                line_idx +=1
 65
 66    input_lines = nosave_input_lines
 67
 68    for i,azimuth_angle in enumerate(azimuth_angles):
 69
 70        step_block_inp = []
 71
 72        # set working directory
 73        # os.chdir(setwork_dir)
 74        folder_name = "Gravity-" + str(int(azimuth_angle))
 75        main_dir = os.path.join(setwork_dir,"OUT")
 76        save_dir = os.path.join(main_dir, folder_name)
 77
 78        if os.path.exists(save_dir) == False:
 79            os.mkdir(save_dir)
 80        
 81        # change working directory to save files in desired folder
 82        # os.chdir(save_dir)
 83
 84        # import gravity 
 85
 86        loads_data_df = readVTT.f_readVTT2DF(os.path.join(setwork_dir, 'IN', 'gravity_loads_transformed.vtt'))
 87        is_current_az = loads_data_df.iloc[0] == azimuth_angle
 88        is_current_az['WindSpeed'] = True
 89        is_current_az = is_current_az.values.tolist()
 90
 91        loads_data_current_df = loads_data_df.iloc[1:,is_current_az]
 92
 93        loads_data = np.array(loads_data_current_df.values.tolist())
 94
 95        # loads_data = np.genfromtxt("../../IN/LoadsTransformed_" + str(int(azimuth_angle)) + ".txt", delimiter =",")
 96        windspeed = loads_data[:,0]
 97        windspeed_float = [float(x) for x in windspeed]
 98        gravity = loads_data[:,1:4]
 99
100        # find closest wind speed in gravity_loads_transformed.vtt
101        vwind_diff = []
102        for vwind in windspeed_float:
103            vwind_diff.append(abs(wind_speed - vwind))
104
105        windspeed_idx = np.argmin(vwind_diff)
106
107        
108        # # only compute if windspeed > 11.2
109        
110        # if windspeed_float[windspeed_idx] <= 11.2:
111        #     calculate_windspeed = 11.2
112        # else:
113        #     calculate_windspeed = windspeed_float[windspeed_idx]
114
115        load_gravity = 'Load-Gravity'
116
117        # length of centrifugal vector
118        norm_gravity = np.sqrt(np.power(gravity[windspeed_idx,0],2)
119                            + np.power(gravity[windspeed_idx,1],2)
120                            + np.power(gravity[windspeed_idx,2],2))
121
122        step_block_inp.append('** NAME: ' + load_gravity + '   Type: Gravity' + '\n')
123        step_block_inp.append('*DLOAD' + '\n')
124        step_block_inp.append('ALL_ELMS, GRAV,  ' + str(norm_gravity) + ', '
125                            + str((1/norm_gravity)*gravity[windspeed_idx,0]) + ', '
126                            + str((1/norm_gravity)*gravity[windspeed_idx,1]) + ', '
127                            + str((1/norm_gravity)*gravity[windspeed_idx,2]) + '\n')
128
129        # create new input file
130        new_input_lines = []
131        for line in input_lines:
132            current_line = line
133            if line.find('<enter wind speed dependent loads here>') != -1:
134                current_line = ''.join(step_block_inp)
135            new_input_lines.append(current_line)
136
137        # write new input file
138        with open(os.path.join(save_dir, template_name.strip('_TEMPLATE') + '_' + str(windspeed_float[windspeed_idx]).replace('.','_') + '.inp'), 'w') as output_file:
139            for line in new_input_lines:
140                output_file.write(line)

Sets up a static CCX simulation with the influence of gravity forces for the given azimuthal positions of the rotor blade.

Parameters:

  • template_name (string): Name of the template file in .inp format to adapt for the static simulation. The file specifies the geometry of the rotor blade. Element and Node sets have to be predefined. Boundary conditions, steps and outputs have to be predefined.
  • wind_speed (float): Average wind speed acting on the entire rotor disc in m/s.
  • save_additional_fields (bool): Flag to save S values for the gravity based simulations in the .dat file. This slows down the conversion from the .frd to .vtu file.
  • working_dir (string): Working directory to execute file in.

Returns:

  • None
def main():
142def main():
143    template_name = 'STARTER_SNL61p5_13LY_S8R_29052024_TEMPLATE' # without .inp
144    wind_speed = 10
145    f_setupStaticGravitySimulations(template_name, wind_speed)