Integrating a Result over a Mesh

This is an example of a run(scenario) script that loads coarse-graining (cg) dataset and integrates a result over a mesh for each timestep in the datase. The data of temporal evolution of the result integral 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 mesh name and result, it integrates the result
    over the mesh for each timestep in the dataset. A graph with the data 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 integral ##
    mesh_name = 'Simulation_Domain'                           #Name of the mesh that contains the result

    res_name = 'Density'                                      #Name of the result
    res_component = 0                                         #Component of the result 
    res_analysis = 'none'                                     #Name of the analysis of the result  
    ########################################

    #### Settings for graph saving ######
    Name_graph = 'Integral {} over {}'.format(res_name,mesh_name)         #Name for the graph
    Title_graph = 'Integral {} over {}'.format(res_name,mesh_name)        #Title to shown in the graph
    xtitle = 'time (s)'                                                   #Title for x-axis 
    ytitle = 'Integral {}'.format(res_name)                               #Tile for y-axis
    legend = ['{}'.format(mesh_name)]                                     #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.data()                                       #Load the data of the coarse-graining dataset

    x_data , y_data = cg_data.mesh_integral(mesh=mesh_name, result=res_name, analysis=res_analysis, component=res_component)  #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

Last updated

Was this helpful?