Commit 705d5c7c authored by Giovanni La Mura's avatar Giovanni La Mura
Browse files

Print a summary of the model after creating it

parent a608f4fc
Loading
Loading
Loading
Loading
+61 −4
Original line number Diff line number Diff line
@@ -57,7 +57,10 @@ def main():
        sconf, gconf = load_model(config['yml_file_name'])
        if (sconf is not None) and (gconf is not None):
            result = write_legacy_sconf(sconf)
            if (result == 0): result += write_legacy_gconf(gconf)
            if (result == 0):
                result += write_legacy_gconf(gconf)
            if (result == 0):
                print_model_summary(sconf, gconf)
        else:
            print("ERROR: could not create configuration.")
            result = 1
@@ -331,11 +334,11 @@ def load_model(model_file):
        use_refinement = True
        dyn_orders = True
        try:
            use_refinement = False if int(model['system_settings']['refinement']) == 0 else True
            use_refinement = False if int(model['runtime']['refinement']) == 0 else True
        except KeyError:
            use_refinement = True
        try:
            dyn_orders = False if int(model['system_settings']['dyn_orders']) == 0 else True
            dyn_orders = False if int(model['runtime']['dyn_orders']) == 0 else True
        except KeyError:
            dyn_orders = True
        str_polar = model['radiation_settings']['polarization']
@@ -457,8 +460,10 @@ def load_model(model_file):
            max_host_ram = int(model['system_settings']['max_host_ram'])
            if (max_host_ram > 0):
                max_host_ram_bytes = max_host_ram * 1024 * 1024 * 1024
                matrix_dim = 2 * gconf['nsph'] * gconf['li'] * (gconf['li'] + 2)
                matrix_dim = 2 * gconf['le'] * (gconf['le'] + 2)
                matrix_size_bytes = 16 * matrix_dim * matrix_dim
                matrix_size_Gb = float(matrix_size_bytes) / 1024.0 / 1024.0 / 1024.0
                print("INFO: estimated external matrix size is {0:.3g} Gb.".format(matrix_size_Gb))
                if (matrix_size_bytes < max_host_ram_bytes):
                    max_host_processes = int(max_host_ram_bytes / matrix_size_bytes / 2)
                    print("INFO: system supports up to %d simultaneous processes."%max_host_processes)
@@ -604,6 +609,56 @@ def print_help():
    print("--help                Print this help and exit.")
    print("                                               ")

## \brief Print a summary of model properties.
#
#  This function provides a summary of useful information concerning the
#  radii of the particle monomers and of the equivalent mass sphere, to
#  assist in the selection of the proper starting orders.
#
#  \parameter scatterer: `dict` A dictionary for the scatterer configuration.
#  \parameter geometry: `dict` A dictionary for the geometry configuration.
def print_model_summary(scatterer, geometry):
    avgX = 0.0
    avgY = 0.0
    avgZ = 0.0
    Rmin = 0.0
    Rmax = 0.0
    Reqm = 0.0
    R3tot = 0.0
    Rcirc = 0.0
    square_farthest = 0.0
    for i in range(scatterer['nsph']):
        avgX += geometry['vec_sph_x'][i]
        avgY += geometry['vec_sph_y'][i]
        avgZ += geometry['vec_sph_z'][i]
        sph_type_index = scatterer['vec_types'][i] - 1
        ros = scatterer['ros'][sph_type_index]
        R3tot += math.pow(ros, 3.0)
        if (ros > Rmax):
            Rmax = ros
        if (Rmin == 0.0 or ros < Rmin):
            Rmin = ros
    Reqm = math.pow(R3tot, 1.0 / 3.0)
    avgX /= scatterer['nsph']
    avgY /= scatterer['nsph']
    avgZ /= scatterer['nsph']
    for i in range(scatterer['nsph']):
        sph_type_index = scatterer['vec_types'][i] - 1
        ros = scatterer['ros'][sph_type_index]
        dX = geometry['vec_sph_x'][i] - avgX
        dY = geometry['vec_sph_y'][i] - avgY
        dZ = geometry['vec_sph_z'][i] - avgZ
        square_range = dX * dX + dY * dY + dZ * dZ + ros * ros
        if (square_range > square_farthest):
            square_farthest = square_range
    Rcirc = math.sqrt(square_farthest)
    if (Rmax == Rmin):
        print("INFO: monomer radius is Rsph = %.5em"%Rmin)
    else:
        print("INFO: smallest monomer radius is Rmin = %.5em"%Rmin)
        print("INFO: largest monomer radius is Rmax = %.5em"%Rmax)
    print("INFO: equivalent mass radius is Reqm = %.5em"%Reqm)
    print("INFO: minimum encircling radius is Rcirc = %.5em"%Rcirc)

## \brief Generate a random cluster aggregate from YAML configuration options.
#
@@ -715,6 +770,8 @@ def random_aggregate(scatterer, geometry, seed, max_rad, max_attempts=100):
            placed_spheres += 1
            vec_types.append(sph_type_index + 1)
            attempts = 0
        # end while loop
    # end for i loop
    scatterer['vec_types'] = vec_types
    sph_index = 0
    for sphere in sorted(vec_spheres, key=lambda item: item['itype']):