示例#1
0
def test_voxelizationRoutine():

    # Test if FileNotFoundError is raised
    with pytest.raises(FileNotFoundError):
        voxelizationRoutine(12597856985475)

    # create an temporary input file for user defined statistics
    cwd = os.getcwd()
    json_dir = cwd + '/json_files'
    dump_dir = cwd + '/dump_files'
    stat_inp = cwd + '/stat_input.json'

    # create an temporary 'json' directory for reading files from
    to_write = {
        'Equivalent diameter': {
            'std': 0.531055,
            'mean': 2.76736,
            'cutoff_min': 1.0,
            'cutoff_max': 2.0
        },
        'Aspect ratio': {
            'mean': 2.5
        },
        'Orientation': {
            'sigma': 28.8,
            'mean': 87.4
        },
        'RVE': {
            'side_length': 3,
            'voxel_per_side': 10
        },
        'Simulation': {
            'nsteps': 1000,
            'periodicity': 'True',
            'output_units': 'mm'
        }
    }

    with open(stat_inp, 'w') as outfile:
        json.dump(to_write, outfile, indent=2)

    particleStatGenerator(stat_inp)

    # create an temporary 'dump' directory for reading files from
    with open(json_dir + '/RVE_data.json') as json_file:
        RVE_data = json.load(json_file)

    with open(json_dir + '/particle_data.json') as json_file:
        particle_data = json.load(json_file)

    sim_box = Simulation_Box(RVE_data['RVE_size'], RVE_data['RVE_size'],
                             RVE_data['RVE_size'])
    Particles = particle_generator(particle_data, sim_box)

    write_dump(Particles, sim_box, len(Particles))

    voxelizationRoutine(0)

    assert os.path.isfile(json_dir + '/nodeDict.json')
    assert os.path.isfile(json_dir + '/elmtDict.json')
    assert os.path.isfile(json_dir + '/elmtSetDict.json')

    os.remove(stat_inp)
    shutil.rmtree(json_dir)
    shutil.rmtree(dump_dir)
示例#2
0
def test_voxelizationRoutine():

    # create an temporary input file for user defined statistics
    cwd = os.getcwd()
    json_dir = cwd + '/json_files'
    dump_dir = cwd + '/dump_files'
    stat_inp = cwd + '/input_test.json'

    # create an temporary 'json' directory for reading files from
    to_write = {
        'Grain type': 'Elongated',
        'Equivalent diameter': {
            'std': 0.531055,
            'mean': 2.76736,
            'cutoff_min': 1.0,
            'cutoff_max': 2.0
        },
        'Aspect ratio': {
            'std': 0.3,
            'mean': 2.5,
            'cutoff_min': 2.0,
            'cutoff_max': 4.0
        },
        'Tilt angle': {
            'std': 28.8,
            'mean': 87.4,
            "cutoff_min": 75.0,
            "cutoff_max": 105.0
        },
        'RVE': {
            "sideX": 3,
            "sideY": 3,
            "sideZ": 3,
            "Nx": 15,
            "Ny": 15,
            "Nz": 15
        },
        'Simulation': {
            'periodicity': 'True',
            'output_units': 'mm'
        }
    }

    with open(stat_inp, 'w') as outfile:
        json.dump(to_write, outfile, indent=2)

    RVEcreator(stat_inp)

    # create an temporary 'dump' directory for reading files from
    with open(json_dir + '/RVE_data.json') as json_file:
        RVE_data = json.load(json_file)

    with open(json_dir + '/particle_data.json') as json_file:
        particle_data = json.load(json_file)

    sim_box = Simulation_Box(RVE_data['RVE_sizeX'], RVE_data['RVE_sizeY'],
                             RVE_data['RVE_sizeZ'])
    sim_box.sim_ts = 500
    Particles = particle_generator(particle_data, sim_box)

    write_dump(Particles, sim_box, len(Particles))

    voxelizationRoutine()

    assert os.path.isfile(json_dir + '/nodeDict.json')
    assert os.path.isfile(json_dir + '/elmtDict.json')
    assert os.path.isfile(json_dir + '/elmtSetDict.json')

    os.remove(stat_inp)
    shutil.rmtree(json_dir)
    shutil.rmtree(dump_dir)
示例#3
0
def particle_grow(sim_box, Ellipsoids, periodicity, nsteps):
    """
    Initializes the :class:`entities.Octree` class and performs recursive subdivision with 
    collision checks and response for the ellipsoids. At each time step of the simulation it 
    increases the size of the ellipsoid by a factor, which depends on the user-defined value for total number of time steps. 

    :param sim_box: Simulation box representing RVE.
    :type sim_box: :obj:`entities.Simulation_Box`  
    :param Ellipsoids: Ellipsoids for the packing routine.
    :type Ellipsoids: list    
    :param periodicity: Status of periodicity.
    :type periodicity: boolean 
    :param nsteps:  Total simulation steps.
    :type nsteps: int       

    .. note:: :meth:`kanapy.input_output.write_dump` function is called at each time step of the simulation to
              write output (.dump) files. By default, periodic images are written to the output file, 
              but this option can be disabled within the function.         
    """
    # Reduce the size of the particles to (1/nsteps)th of its original size
    for ell in Ellipsoids:
        ell.a, ell.b, ell.c = ell.oria / nsteps, ell.orib / nsteps, ell.oric / nsteps

    # Simulation loop for particle growth and interaction steps
    for i in tqdm(range(nsteps + 1)):

        # Initialize Octree and test for collision between ellipsoids
        tree = Octree(
            0,
            Cuboid(sim_box.left, sim_box.top, sim_box.right, sim_box.bottom,
                   sim_box.front, sim_box.back), Ellipsoids)
        tree.update()

        # Dump the ellipsoid information to be read by OVITO (Includes duplicates at periodic boundaries)
        write_dump(Ellipsoids, sim_box, len(Ellipsoids))

        # Delete duplicates if existing (Active only if periodicity is True)
        # find all the items which are not duplicates
        inter_ell = [ell for ell in Ellipsoids if not isinstance(ell.id, str)]
        Ellipsoids = inter_ell

        # Dump the ellipsoid information to be read by OVITO (Doesn't include duplicates at periodic boundaries)
        #write_dump(Ellipsoids, sim_box, len(Ellipsoids))

        dups = []
        # Loop over the ellipsoids: move, set Bbox, & check for wall collision / PBC
        for ellipsoid in Ellipsoids:
            # Move the ellipsoid according to collision status
            ellipsoid.move()
            # grow the ellipsoid
            ellipsoid.growth(nsteps)
            # Check for wall collision or create duplicates
            ell_dups = ellipsoid.wallCollision(sim_box, periodicity)
            dups.extend(ell_dups)
            # Update the BBox of the ellipsoid
            ellipsoid.set_cub()

        # Update the actual list with duplicates
        Ellipsoids.extend(dups)

        # Update the simulation time
        sim_box.sim_ts += 1

    return