How can I use csv file as a parameter to replace temp vs conv coeff of convection obj in Mechanical?
Rohith Patchigolla
Member, Moderator, Employee Posts: 218
✭✭✭✭
I have an optiSlang analysis where I generate a csv file having two columns temperature vs convection coefficient. How can I use the updated csv and use these values to define the temp vs conv coeff data in a particular convection object?
Tagged:
0
Answers
-
Solution: Python Code object with "Target Callback" --> "Before Solve"
Assumption: Semi-Colon as a delimiter, Convection object already defined with a dummy information with same number of rows as in csv. Convection object setup is as shown below.Script for Python Code:
def before_solve(this, analysis):# Do not edit this line import os import csv #Input name of convection object convection_obj_name = r"Convection_CSV" filepath = r"D:\del" filenameCSV = r"temp_conv_data.csv" filepathCSV = os.path.join(filepath,filenameCSV) convDataTemp = [] convDataHF = [] with open(filepathCSV, 'r') as csvfile: csv_reader = csv.reader(csvfile) for row in csv_reader: data = row[0].split(";") convDataTemp.append(Quantity(float(data[0]), 'C')) convDataHF.append(Quantity(float(data[1]), 'W mm^-1 mm^-1 C^-1')) convObj = DataModel.GetObjectsByName(convection_obj_name)[0] convObj.FilmCoefficient.Output.DiscreteValues = convDataHF convObj.FilmCoefficient.Inputs[0].DiscreteValues = convDataTemp
1