Getting the Profile of Result along a Line
This is an example of a run(scenario)
script that loads coarse-graining (cg) dataset and gets the profile of a result along a line. The data of the profile is saved into the scenario as graph (raw data is also saved into a CSV file) and the graph is exported into a interactive HTML file.
'''This scripts loads the cg_dataset of a scenario. For a given timestep, mesh name and result, it gets the profile of
the result along a line. The data of the profile is saved into the scenario and into a CSV file, and the graph is
exported into a HTML file'''
import iota
def run(scenario):
## Settings for the line profile ##
mesh_name = 'Simulation_Domain' #Name of the mesh that contains the result
res_name = 'Velocity' #Name of the result
res_component = 3 #Component of the result (X=0, Y=1, Z=2, Magnitude=3)
res_analysis = 'none' #Name of the analysis of the result
Start_point = [0,0,0] #Start point for the line profile
End_point = [0,0,1] #End point for the line profile
Npoints = 50 #Number of points to get for the line profile
t = '2.5' #Value of the timestep to get line from.
########################################
#### Settings for graph saving ######
Name_graph = 'Profile {} from {} to {} at {} s'.format(res_name, Start_point, End_point, t) #Name for the graph
Title_graph = 'Profile {} at {}'.format(res_name,t) #Title to shown in the graph
xtitle = 'Distance (m)' #Title for x-axis
ytitle = 'Velocity Magnitude [m/s]' #Tile for y-axis
legend = ['{} to {}'.format(Start_point, End_point)] #Name of the trace for the graph legend
graph_file = '{}/graphs/{}'.format(scenario.directory,Name_graph) #Output name and path for exporting graph
########################################
cg_dataset = scenario.get_cg_dataset() #Get the coarse-graining dataset of the scenario
cg_data = cg_dataset.data() #Load the data of the coarse-graining dataset
ListOfTimesteps = cg_data.timesteps() #Get the list of time of the steps
step = ListOfTimesteps.index(t) #Get the step for time t.
x_data , y_data = cg_data.line_variation(step=step, mesh=mesh_name,
point_start=iota.Vector3d(Start_point), point_end=iota.Vector3d(End_point), num_points = Npoints,
result=res_name, analysis=res_analysis, component=res_component, x_type='dist') #Get line profile data
graph = scenario.add_graph(name=Name_graph, title=Title_graph, xdata=x_data, ydata=y_data,
xtitle=xtitle, ytitle=ytitle, legend=legend) #Save the graph data to database (including raw data to csv file)
graph.export_html(graph_file) #Export the graph into html format
PreviousCalculating a KPI and Exporting into a GraphNextCreating Multiple Result Line Variations and Plotting them in a Single Graph
Last updated
Was this helpful?