Creating a New Result in a Dataset

This is an example of a run(scenario) script that loads coarse-graining (cg) dataset and creates a new result based on a existing result:

'''This scripts loads the cg_dataset of a scenario. For each timestep in the dataset, it loads the solid fraction
 for a specific mesh and calculates the voidage percentage = (1 - Solid Fraction)*100 and adds it as a new result of that mesh.'''

import iota

def run(scenario):

    ## Settings for results ##
    mesh_name = 'Simulation_Domain'                           #Name of the mesh that contains the result

    res1_name = 'Solid Fraction'                              #Name of the result to operate with
    res1_analysis = 'none'                                    #Name of the analysis of the res1

    new_res_name = 'Voidage'                                  #Name for the new result
    new_res_analysis = 'none'                                 #Name of the analysis for the new result
    ########################################

    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
    NumberOfSteps = len(cg_data.timesteps())                  # Get the number of timesteps of the dataset

    for cont in range(0,NumberOfSteps):                                                     # For each step in the dataset                  
        res1_values = cg_data.get_result(cont, mesh_name, res1_name, res1_analysis)      # Get the values of the Solid Fraction                  
        array_of_ones = iota.ArrayFloat(len(res1_values),1)                                 # Create an array of ones of the same length of res1
        new_res_values = (array_of_ones - res1_values)*100                                  # Caculate the values of the Voidage
        cg_data.add_result(cont, mesh_name, new_res_name, new_res_analysis, new_res_values) # Add the voidage result to the step

Last updated

Was this helpful?