def main():
    """
    3D canteliver beam peridynamics simulation
    """
    parser = argparse.ArgumentParser()
    parser.add_argument("mesh_file_name",
                        help="run example on a given mesh file name")
    parser.add_argument('--optimised', action='store_const', const=True)
    parser.add_argument('--profile', action='store_const', const=True)
    parser.add_argument('--lumped', action='store_const', const=True)
    parser.add_argument('--lumped2', action='store_const', const=True)
    args = parser.parse_args()

    if args.profile:
        profile = cProfile.Profile()
        profile.enable()

    beams = [
        '1650beam792t.msh', '1650beam2652t.msh', '1650beam3570t.msh',
        '1650beam4095t.msh', '1650beam6256t.msh', '1650beam15840t.msh',
        '1650beam32370t.msh', '1650beam74800t.msh', '1650beam144900t.msh',
        '1650beam247500t.msh'
    ]
    assert args.mesh_file_name in beams, 'mesh_file_name = {} was not recognised, please check the mesh file is in the directory'.format(
        args.mesh_file_name)

    if args.optimised:
        print(args.mesh_file_name, 'EulerCromerOptimised')
    else:
        print(args.mesh_file_name, 'EulerCromer')
    mesh_file = pathlib.Path(__file__).parent.absolute() / args.mesh_file_name
    st = time.time()

    # Set simulation parameters
    volume_total = 1.65 * 0.6 * 0.25
    density_concrete = 2400
    youngs_modulus_concrete = 1. * 22e9
    youngs_modulus_steel = 1. * 210e9
    poisson_ratio = 0.25
    strain_energy_release_rate_concrete = 100
    strain_energy_release_rate_steel = 13000
    networks = {
        '1650beam792t.msh': 'Network1650beam792t.vtk',
        '1650beam2652t.msh': 'Network1650beam2652t.vtk',
        '1650beam3570t.msh': 'Network1650beam3570t.vtk',
        '1650beam4095t.msh': 'Network1650beam4095t.vtk',
        '1650beam6256t.msh': 'Network1650beam6256t.vtk',
        '1650beam15840t.msh': 'Network1650beam15840t.vtk',
        '1650beam32370t.msh': 'Network1650beam32370t.vtk',
        '1650beam74800t.msh': 'Network1650beam74800t.vtk',
        '1650beam144900t.msh': 'Network1650beam144900t.vtk',
        '1650beam247500t.msh': 'Network1650beam247500t.vtk'
    }
    network_file_name = networks[args.mesh_file_name]
    dxs = {
        '1650beam792t.msh': 0.075,
        '1650beam2652t.msh': 0.0485,
        '1650beam3570t.msh': 0.0485,
        '1650beam4095t.msh': 0.0423,
        '1650beam6256t.msh': 0.0359,
        '1650beam15840t.msh': 0.025,
        '1650beam32370t.msh': 0.020,
        '1650beam74800t.msh': 0.015,
        '1650beam144900t.msh': 0.012,
        '1650beam247500t.msh': 0.010
    }
    dx = dxs[args.mesh_file_name]
    horizon = dx * np.pi
    # Two materials in this example, that is 'concrete' and 'steel'
    # Critical strain, s0
    critical_strain_concrete = np.double(
        np.power(
            np.divide(5 * strain_energy_release_rate_concrete,
                      6 * youngs_modulus_steel * horizon), (1. / 2)))
    critical_strain_steel = np.double(
        np.power(
            np.divide(5 * strain_energy_release_rate_steel,
                      6 * youngs_modulus_steel * horizon), (1. / 2)))
    damping = 2.0e6  # damping term
    # Peridynamic bond stiffness, c
    bulk_modulus_concrete = youngs_modulus_concrete / (3 *
                                                       (1 - 2 * poisson_ratio))
    bulk_modulus_steel = youngs_modulus_steel / (3 * (1 - 2 * poisson_ratio))
    bond_stiffness_concrete = (np.double(
        (18.00 * bulk_modulus_concrete) / (np.pi * np.power(horizon, 4))))
    bond_stiffness_steel = (np.double(
        (18.00 * bulk_modulus_steel) / (np.pi * np.power(horizon, 4))))
    crack_length = np.double(0.0)
    model = OpenCL(mesh_file_name=args.mesh_file_name,
                   density=density_concrete,
                   horizon=horizon,
                   damping=damping,
                   bond_stiffness_concrete=bond_stiffness_concrete,
                   bond_stiffness_steel=bond_stiffness_steel,
                   critical_strain_concrete=critical_strain_concrete,
                   critical_strain_steel=critical_strain_steel,
                   crack_length=crack_length,
                   volume_total=volume_total,
                   bond_type=bond_type,
                   network_file_name=network_file_name,
                   initial_crack=[],
                   dimensions=3,
                   transfinite=0,
                   precise_stiffness_correction=1)
    saf_fac = 0.3  # Typical values 0.70 to 0.95 (Sandia PeridynamicSoftwareRoadmap) 0.5
    model.dt = (0.8 * np.power(
        2.0 * density_concrete * dx /
        (np.pi * np.power(model.horizon, 2.0) * dx *
         model.bond_stiffness_concrete), 0.5) * saf_fac)
    model.max_reaction = 500000  # in newtons, about 85 times self weight
    model.load_scale_rate = 1 / 500000

    # Set force and displacement boundary conditions
    boundary_function(model)
    boundary_forces_function(model)

    if args.optimised:
        if args.lumped:
            integrator = EulerCromerOptimisedLumped(model)
            method = 'EulerCromerOptimisedLumped'
        elif args.lumped2:
            integrator = EulerCromerOptimisedLumped2(model)
            method = 'EulerCromerOptimisedLumped2'
        else:
            integrator = EulerCromerOptimised(model)
            method = 'EulerCromerOptimised'
    else:
        integrator = EulerCromer(model)
        method = 'EulerCromer'

    # delete output directory contents, this is probably unsafe?
    shutil.rmtree('./output', ignore_errors=False)
    os.mkdir('./output')
    print(args.mesh_file_name, method)
    damage_sum_data, tip_displacement_data, tip_shear_force_data = model.simulate(
        model,
        sample=1,
        steps=200000,
        integrator=integrator,
        write=500,
        toolbar=0)
    plt.figure(1)
    plt.title('damage over time')
    plt.plot(damage_sum_data)
    plt.figure(2)
    plt.title('tip displacement over time')
    plt.plot(tip_displacement_data)
    plt.show()
    plt.figure(3)
    plt.title('shear force over time')
    plt.plot(tip_shear_force_data)
    plt.show()
    print('damage_sum_data', damage_sum_data)
    print('tip_displacement_data', tip_displacement_data)
    print('tip_shear_force_data', tip_shear_force_data)
    print('TOTAL TIME REQUIRED {}'.format(time.time() - st))
    if args.profile:
        profile.disable()
        s = StringIO()
        stats = Stats(profile, stream=s).sort_stats(SortKey.CUMULATIVE)
        stats.print_stats()
        print(s.getvalue())
    print('\n')
示例#2
0
def main():
    """
    3D canteliver beam peridynamics simulation
    """
    parser = argparse.ArgumentParser()
    parser.add_argument("mesh_file_name", help="run example on a given mesh file name")
    parser.add_argument('--optimised', action='store_const', const=True)
    parser.add_argument('--profile', action='store_const', const=True)
    parser.add_argument('--lumped', action='store_const', const=True)
    parser.add_argument('--lumped2', action='store_const', const=True)
    args = parser.parse_args()

    if args.profile:
        profile = cProfile.Profile()
        profile.enable()

    beams = ['3300beam952.msh',
             '3300beam2970.msh',
             '3300beam4392.msh',
             '3300beam6048.msh',
             '3300beam11836.msh',
             '3300beam17600.msh',
             '3300beam31680.msh',
             '3300beam64350.msh',
             '3300beam149600.msh',
             '3300beam495000.msh',
             '3300beam952t.msh',
             '3300beam2970t.msh',
             '3300beam4392t.msh',
             '3300beam6048t.msh',
             '3300beam11836t.msh',
             '3300beam17600t.msh',
             '3300beam31680t.msh',
             '3300beam64350t.msh',
             '3300beam149600t.msh',
             '3300beam495000t.msh']
    assert args.mesh_file_name in beams, 'mesh_file_name = {} was not recognised, please check the mesh file is in the directory'.format(args.mesh_file_name)

    if args.optimised:
        print(args.mesh_file_name, 'EulerCromerOptimised')
    else:
        print(args.mesh_file_name, 'EulerCromer')
    mesh_file = pathlib.Path(__file__).parent.absolute() / args.mesh_file_name
    st = time.time()

    # Set simulation parameters
    volume_total = 3.3 * 0.6 * 0.25
    density_concrete = 2400
    youngs_modulus_concrete = 1.*22e9
    youngs_modulus_steel = 1.*210e9
    poisson_ratio = 0.25
    strain_energy_release_rate_concrete = 100
    strain_energy_release_rate_steel = 13000
    networks = {'3300beam952.msh': 'Network3300beam952.vtk',
                '3300beam2970.msh': 'Network3300beam2970.vtk',
                '3300beam4392.msh': 'Network3300beam4392.vtk',
                '3300beam6048.msh': 'Network3300beam6048.vtk',
                '3300beam11836.msh': 'Network3300beam11836.vtk',
                '3300beam17600.msh': 'Network3300beam17600.vtk',
                '3300beam31680.msh': 'Network3300beam31680.vtk',
                '3300beam64350.msh': 'Network3300beam64350.vtk',
                '3300beam149600.msh': 'Network3300beam149600.vtk',
                '3300beam495000.msh': 'Network3300beam495000.vtk',
                '3300beam952t.msh': 'Network3300beam952t.vtk',
                '3300beam2970t.msh': 'Network3300beam2970t.vtk',
                '3300beam4392t.msh': 'Network3300beam4392t.vtk',
                '3300beam6048t.msh': 'Network3300beam6048t.vtk',
                '3300beam11836t.msh': 'Network3300beam11836t.vtk',
                '3300beam17600t.msh': 'Network3300beam17600t.vtk',
                '3300beam31680t.msh': 'Network3300beam31680t.vtk',
                '3300beam64350t.msh': 'Network3300beam64350t.vtk',
                '3300beam149600t.msh': 'Network3300beam149600t.vtk',
                '3300beam495000t.msh': 'Network3300beam495000t.vtk'}
    network_file_name = networks[args.mesh_file_name]
    dxs = {'3300beam952.msh': 0.0971,
           '3300beam2970.msh': 0.0611,
           '3300beam4392.msh': 0.0541,
           '3300beam6048.msh': 0.0458,
           '3300beam11836.msh': 0.0357,
           '3300beam17600.msh': 0.0313,
           '3300beam31680.msh': 0.0250,
           '3300beam64350.msh': 0.0200,
           '3300beam149600.msh': 0.0150,
           '3300beam495000.msh': 0.0100,
           '3300beam952t.msh': 0.0971,
           '3300beam2970t.msh': 0.0611,
           '3300beam4392t.msh': 0.0541,
           '3300beam6048t.msh': 0.0458,
           '3300beam11836t.msh': 0.0357,
           '3300beam17600t.msh': 0.0313,
           '3300beam31680t.msh': 0.0250,
           '3300beam64350t.msh': 0.0200,
           '3300beam149600t.msh': 0.0150,
           '3300beam495000t.msh': 0.0100}
    build_displacements = {'3300beam952.msh': 0.000536,
           '3300beam2970.msh': 0.000556,
           '3300beam4392.msh': 0.000536,
           '3300beam6048.msh': 0.000600,
           '3300beam11836.msh': 0.00140,
           '3300beam17600.msh': 0.00100,
           '3300beam31680.msh': 0.00170,
           '3300beam64350.msh': 0.00160,
           '3300beam149600.msh': 0.00260,
           '3300beam495000.msh': 0.00400,
           '3300beam952t.msh': 0.000536,
           '3300beam2970t.msh': 0.000556,
           '3300beam4392t.msh': 0.000536,
           '3300beam6048t.msh': 0.000600,
           '3300beam11836t.msh': 0.00140,
           '3300beam17600t.msh': 0.00100,
           '3300beam31680t.msh': 0.00170,
           '3300beam64350t.msh': 0.00160,
           '3300beam149600t.msh': 0.00260,
           '3300beam495000t.msh': 0.00400}
    time_steps = {'3300beam952.msh': 150000,
           '3300beam2970.msh': 150000,
           '3300beam4392.msh': 150000,
           '3300beam6048.msh': 150000,
           '3300beam11836.msh': 350000,
           '3300beam17600.msh': 200000,
           '3300beam31680.msh': 350000,
           '3300beam64350.msh': 350000,
           '3300beam149600.msh': 400000,
           '3300beam495000.msh': 350000,
           '3300beam952t.msh': 150000,
           '3300beam2970t.msh': 150000,
           '3300beam4392t.msh': 150000,
           '3300beam6048t.msh': 150000,
           '3300beam11836t.msh': 250000,
           '3300beam17600t.msh': 200000,
           '3300beam31680t.msh': 250000,
           '3300beam64350t.msh': 250000,
           '3300beam149600t.msh': 300000,
           '3300beam495000t.msh': 350000}
    dts = {'3300beam952.msh': 0.8,
           '3300beam2970.msh': 0.8,
           '3300beam4392.msh': 0.8,
           '3300beam6048.msh': 0.8,
           '3300beam11836.msh': 0.6,
           '3300beam17600.msh': 0.6,
           '3300beam31680.msh': 0.5,
           '3300beam64350.msh': 0.4,
           '3300beam149600.msh': 0.4,
           '3300beam495000.msh': 0.3,
           '3300beam952t.msh': 0.8,
           '3300beam2970t.msh': 0.8,
           '3300beam4392t.msh': 0.8,
           '3300beam6048t.msh': 0.8,
           '3300beam11836t.msh': 0.6,
           '3300beam17600t.msh': 0.6,
           '3300beam31680t.msh': 0.5,
           '3300beam64350t.msh': 0.4,
           '3300beam149600t.msh': 0.4,
           '3300beam495000t.msh': 0.3}
    dx = dxs[args.mesh_file_name]
    horizon = dx * np.pi 
    # Two materials in this example, that is 'concrete' and 'steel'
    # Critical strain, s0
    critical_strain_concrete = np.double(np.power(
            np.divide(5*strain_energy_release_rate_concrete, 6*youngs_modulus_steel*horizon),
            (1./2)
            ))
    critical_strain_steel = np.double(np.power(
    np.divide(5*strain_energy_release_rate_steel, 6*youngs_modulus_steel*horizon),
    (1./2)
    ))
    damping = 2.0e6 # damping term
    # Peridynamic bond stiffness, c
    bulk_modulus_concrete = youngs_modulus_concrete/ (3* (1 - 2*poisson_ratio))
    bulk_modulus_steel = youngs_modulus_steel / (3* (1- 2*poisson_ratio))
    bond_stiffness_concrete = (
    np.double((18.00 * bulk_modulus_concrete) /
    (np.pi * np.power(horizon, 4)))
    )
    bond_stiffness_steel = (
    np.double((18.00 * bulk_modulus_steel) /
    (np.pi * np.power(horizon, 4)))
    )
    crack_length = np.double(0.0)
    model = OpenCL(mesh_file_name = args.mesh_file_name, 
                   density = density_concrete, 
                   horizon = horizon,
                   damping = damping,
                   dx = dx,
                   bond_stiffness_concrete = bond_stiffness_concrete,
                   bond_stiffness_steel = bond_stiffness_steel, 
                   critical_strain_concrete = critical_strain_concrete,
                   critical_strain_steel = critical_strain_steel,
                   crack_length = crack_length,
                   volume_total=volume_total,
                   bond_type=bond_type,
                   network_file_name = network_file_name,
                   initial_crack=[],
                   dimensions=3,
                   transfinite=1,
                   precise_stiffness_correction=0)
    # If time step is too large, instability
    # if time step is too small, overdamped
    saf_fac = dts[args.mesh_file_name] # Typical values 0.70 to 0.95 (Sandia PeridynamicSoftwareRoadmap)
    model.dt = (
     0.8 * np.power( 2.0 * density_concrete * dx / 
     (np.pi * np.power(model.horizon, 2.0) * dx * model.bond_stiffness_concrete), 0.5)
     * saf_fac
     )
    model.max_reaction = 0 # in newtons, about 85 times self weight
    model.load_scale_rate = 1
    displacement_rate = 1e-8
    # Set force and displacement boundary conditions
    boundary_function(model, displacement_rate)
    boundary_forces_function(model)
    
    if args.optimised:
        if args.lumped:
            integrator = EulerCromerOptimisedLumped(model)
        elif args.lumped2:
            integrator = EulerCromerOptimisedLumped2(model)
        else:
            integrator = EulerCromerOptimised(model)
    else:
        integrator = EulerCromer(model)
    # delete output directory contents, this is probably unsafe?
    shutil.rmtree('./output', ignore_errors=False)
    os.mkdir('./output')
    damage_sum_data, tip_displacement_data, tip_acceleration_data, tip_force_data  = model.simulate(
            model, sample=1, steps=time_steps[args.mesh_file_name], integrator=integrator, write=1000, toolbar=0,
            displacement_rate = displacement_rate,
            build_displacement = build_displacements[args.mesh_file_name],
            final_displacement = build_displacements[args.mesh_file_name])
    print('damage_sum_data', damage_sum_data)
    print('tip_displacement_data', tip_displacement_data)
    print('tip_acceleration_data', tip_acceleration_data)
    print('tip_force_data', tip_force_data)
    print('TOTAL TIME REQUIRED {}'.format(time.time() - st))
    # Determine how many of the nodes were interface, rebar and concrete
    nnodes_rebar = 0
    for i in range(0, model.nnodes):
        if is_rebar(model.coords[i][:]):
            nnodes_rebar += 1
    nnodes_concrete = model.nnodes - nnodes_rebar
    print('no. steel nodes', nnodes_rebar)
    print('no concrete nodes', nnodes_concrete)   
    if args.profile:
        profile.disable()
        s = StringIO()
        stats = Stats(profile, stream=s).sort_stats(SortKey.CUMULATIVE)
        stats.print_stats()
        print(s.getvalue())
    print('\n')
示例#3
0
def main():
    """
    3D canteliver beam peridynamics simulation
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('--profile', action='store_const', const=True)
    args = parser.parse_args()

    if args.profile:
        profile = cProfile.Profile()
        profile.enable()
    
    bulk_modulus_concrete = 0.04
    critical_strain_concrete = 0.005
    horizon = np.pi*1.7e-3
    
    # Set simulation parameters
    model = OpenCL(mesh_file_name, 
                   density = 1.0,
                   horizon = horizon, 
                   damping = 1.0,
                   bond_stiffness_concrete = (
                       np.double((18.00 * bulk_modulus_concrete) /
                                 (np.pi * np.power(horizon, 4)))
                       ),
                   bond_stiffness_steel = (
                   np.double((18.00 * bulk_modulus_concrete) /
                             (np.pi * np.power(horizon, 4)))
                   ),
                   critical_strain_concrete = critical_strain_concrete, # was 0.005
                   critical_strain_steel = 1.0,
                   dx = 0.01,
                   crack_length = 0.0,
                   volume_total=(0.15*0.1 - np.pi *0.00148**2)*0.0017,
                   bond_type=bond_type,
                   network_file_name = 'Network_6.vtk',
                   initial_crack=[],
                   dimensions=3,
                   transfinite= 0,
                   precise_stiffness_correction = 1)
    

    model.dt = np.double(4.0e-5)
    # Set force and displacement boundary conditions
    displacement_rate = 5.0e-7
    boundary_function(model, displacement_rate)
    boundary_forces_function(model)
    # delete output directory contents, this is probably unsafe?
    shutil.rmtree('./output', ignore_errors=False)
    os.mkdir('./output')
    # MCMC wrapper function
    # read the data
    damage_data = read_data(model)
    samples = 10
    
    # Define start point of the Metropolis Hastings sampler w[1] is l, w[0] is sigma
    w_prev = [1.0, 1.0]
    
    # Define proposal density of the MCMC sampler
    w_cov = [[0.001, 0.0],[0.0, 0.001]]
    
    # Get the intial likelihood
    # update (l, sigma)
    model._set_D(w_prev[0], w_prev[1])
    integrator = EulerOpenCLMCMC(model)
    likelihood_prev = 0
    sample = 0
    realisation = 0
    integrator.reset(model)
    sample_data, tip_displacement_data, tip_shear_force_data = model.simulate(model, sample=1, steps=1000, integrator=integrator, write=1000, toolbar=0,
                                                                                  displacement_rate = displacement_rate)
    print(np.sum(sample_data), 'sum of damage, realisation #', realisation)
    likelihood_prev = mcmc.get_likelihood(damage_data, sample_data)
    assert likelihood_prev != 0, 'Floating point error on first likelihood value: likelihood must be more than 0'

    # Evaluate the pdf of the distribution we want to sample from
    prior_prev = mcmc.trunc_normal_prior_pdf(w_prev[0], 1.0, 1.0)*mcmc.trunc_normal_prior_pdf(w_prev[1], 1.0, 1.0)
    data = [[],[]]
    total_samples = 0
    
    for sample in range(samples):
        total_samples += 1
        print('Sample {}/{} Complete'.format(total_samples, samples))
        # Get proposal parameters
        w = sp.multivariate_normal.rvs(w_prev, w_cov, 1)
        # update (l, sigma)
        model._set_D(w[0], w[1])
        # Multiply two single variate prior distributions
        prior = mcmc.trunc_normal_prior_pdf(w[0], 1.0, 1.0)*mcmc.trunc_normal_prior_pdf(w[1], 1.0, 1.0)
        if prior ==0:
            None
        else:

            # Get the likelihood
            integrator.reset(model)
            sample_data, tip_displacement_data, tip_shear_force_data = model.simulate(model, sample=sample, steps=1000, integrator=integrator, write=1100, toolbar=0,
                                                                                  displacement_rate = displacement_rate)
            print(np.sum(sample_data), 'sum of damage, realisation #', realisation)
            likelihood = mcmc.get_likelihood(damage_data, sample_data)

            # compute acceptance ratio
            r = (prior * likelihood)/ (prior_prev * likelihood_prev)
            
            # Generate u from a unifrom distribution
            u = np.random.uniform()
            if u <= r:
                # accept the sample
                data[0].append(w[0])
                data[1].append(w[1])
                print('accepted sigma: ', w[0], 'accepted l: ', w[1])
                w_prev = w
                prior_prev = prior
                likelihood_prev = likelihood
                with open(pathlib.Path(__file__).parent.absolute() / "mcmc_current_6.csv", 'a', newline='') as myfile:
                    wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
                    wr.writerow([w[0],w[1]])
            else:
                None
    
    # Perform the burn on the first 100 values
    burn = 0
    
    data[0] = data[0][burn:]
    data[1] = data[1][burn:]
    
    print(len(data[0]), 'LENGTH')
    mean = np.divide(np.sum(data, axis = 1), len(data[0]))
    print(mean, mean.shape, 'MEAN AND SHAPE')
        
    with open(pathlib.Path(__file__).parent.absolute() / "mean_6.csv", "w") as output:
        writer = csv.writer(output, lineterminator='\n')
        for val in mean:
            writer.writerow([val])
    if total_samples == 0:
        pass
    else:
        print('The percentage of accepted samples was {}%'.format(len(data[0])*100/(total_samples)))
    
    # Write data to a file
    with open(pathlib.Path(__file__).parent.absolute() / "mcmc_6.csv", 'w', newline='') as myfile:
        wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
        data_zipped = zip(*data)
        wr.writerow(data_zipped)
    
    if args.profile:
        profile.disable()
        s = StringIO()
        stats = Stats(profile, stream=s).sort_stats(SortKey.CUMULATIVE)
        stats.print_stats()
        print(s.getvalue())
示例#4
0
def main():
    """
    3D canteliver beam peridynamics simulation
    """
    parser = argparse.ArgumentParser()
    parser.add_argument("mesh_file_name",
                        help="run example on a given mesh file name")
    parser.add_argument('--optimised', action='store_const', const=True)
    parser.add_argument('--profile', action='store_const', const=True)
    args = parser.parse_args()

    if args.profile:
        profile = cProfile.Profile()
        profile.enable()

    beams = [
        '3300beam952.msh', '3300beam2970.msh', '3300beam4392.msh',
        '3300beam6048.msh', '3300beam11836.msh', '3300beam17600.msh',
        '3300beam31680.msh', '3300beam64350.msh', '3300beam149600.msh',
        '3300beam495000.msh'
    ]
    assert args.mesh_file_name in beams, 'mesh_file_name = {} was not recognised, please check the mesh file is in the directory'.format(
        args.mesh_file_name)

    if args.optimised:
        print(args.mesh_file_name, 'EulerOptimised')
    else:
        print(args.mesh_file_name, 'Euler')
    mesh_file = pathlib.Path(__file__).parent.absolute() / args.mesh_file_name
    st = time.time()

    # Set simulation parameters
    volume_total = 3.3 * 0.6 * 0.25
    density_concrete = 2400
    youngs_modulus_concrete = 1. * 22e9
    youngs_modulus_steel = 1. * 210e9
    poisson_ratio = 0.25
    strain_energy_release_rate_concrete = 100
    strain_energy_release_rate_steel = 13000
    networks = {
        '3300beam952.msh': 'Network3300beam952.vtk',
        '3300beam2970.msh': 'Network3300beam2970.vtk',
        '3300beam4392.msh': 'Network3300beam4392.vtk',
        '3300beam6048.msh': 'Network3300beam6048.vtk',
        '3300beam11836.msh': 'Network3300beam11836.vtk',
        '3300beam17600.msh': 'Network3300beam17600.vtk',
        '3300beam31680.msh': 'Network3300beam31680.vtk',
        '3300beam64350.msh': 'Network3300beam64350.vtk',
        '3300beam149600.msh': 'Network3300beam149600.vtk',
        '3300beam495000.msh': 'Network3300beam495000.vtk'
    }
    network_file_name = networks[args.mesh_file_name]
    dxs = {
        '3300beam952.msh': 0.0971,
        '3300beam2970.msh': 0.0611,
        '3300beam4392.msh': 0.0541,
        '3300beam6048.msh': 0.0458,
        '3300beam11836.msh': 0.0357,
        '3300beam17600.msh': 0.0313,
        '3300beam31680.msh': 0.0250,
        '3300beam64350.msh': 0.0200,
        '3300beam149600.msh': 0.0150,
        '3300beam495000.msh': 0.0100
    }
    dx = dxs[args.mesh_file_name]
    horizon = dx * np.pi
    # Two materials in this example, that is 'concrete' and 'steel'
    # Critical strain, s0
    critical_strain_concrete = np.double(
        np.power(
            np.divide(5 * strain_energy_release_rate_concrete,
                      6 * youngs_modulus_steel * horizon), (1. / 2)))
    critical_strain_steel = np.double(
        np.power(
            np.divide(5 * strain_energy_release_rate_steel,
                      6 * youngs_modulus_steel * horizon), (1. / 2)))
    damping = 1.0  # damping term
    # Peridynamic bond stiffness, c
    bulk_modulus_concrete = youngs_modulus_concrete / (3 *
                                                       (1 - 2 * poisson_ratio))
    bulk_modulus_steel = youngs_modulus_steel / (3 * (1 - 2 * poisson_ratio))
    bond_stiffness_concrete = (np.double(
        (18.00 * bulk_modulus_concrete) / (np.pi * np.power(horizon, 4))))
    bond_stiffness_steel = (np.double(
        (18.00 * bulk_modulus_steel) / (np.pi * np.power(horizon, 4))))
    crack_length = np.double(0.0)
    model = OpenCL(mesh_file_name=args.mesh_file_name,
                   density=density_concrete,
                   horizon=horizon,
                   damping=damping,
                   bond_stiffness_concrete=bond_stiffness_concrete,
                   bond_stiffness_steel=bond_stiffness_steel,
                   critical_strain_concrete=critical_strain_concrete,
                   critical_strain_steel=critical_strain_steel,
                   crack_length=crack_length,
                   volume_total=volume_total,
                   bond_type=bond_type,
                   network_file_name=network_file_name,
                   initial_crack=[],
                   dimensions=3,
                   transfinite=1,
                   precise_stiffness_correction=0)
    model.dt = 1e-14
    model.max_reaction = 0  # in newtons, about 85 times self weight
    model.load_scale_rate = 1
    displacement_rate = 1e-8

    # Set force and displacement boundary conditions
    boundary_function(model, displacement_rate)
    boundary_forces_function(model)

    if args.optimised:
        integrator = EulerOpenCLOptimised(model)
    else:
        integrator = EulerOpenCL(model)

    # delete output directory contents, this is probably unsafe?
    shutil.rmtree('./output', ignore_errors=False)
    os.mkdir('./output')

    damage_sum_data, tip_displacement_data, tip_shear_force_data = model.simulate(
        model,
        sample=1,
        steps=1000,
        integrator=integrator,
        write=1000,
        toolbar=0,
        displacement_rate=displacement_rate)
    # =============================================================================
    #     plt.figure(1)
    #     plt.title('damage over time')
    #     plt.plot(damage_sum_data)
    #     plt.figure(2)
    #     plt.title('tip displacement over time')
    #     plt.plot(tip_displacement_data)
    #     plt.show()
    #     plt.figure(3)
    #     plt.title('shear force over time')
    #     plt.plot(tip_shear_force_data)
    #     plt.show()
    # =============================================================================
    print('damage_sum_data', damage_sum_data)
    print('tip_displacement_data', tip_displacement_data)
    print('tip_shear_force_data', tip_shear_force_data)
    print('TOTAL TIME REQUIRED {}'.format(time.time() - st))
    if args.profile:
        profile.disable()
        s = StringIO()
        stats = Stats(profile, stream=s).sort_stats(SortKey.CUMULATIVE)
        stats.print_stats()
        print(s.getvalue())
    print('\n')
示例#5
0
def main():
    """
    3D canteliver beam peridynamics simulation
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('--profile', action='store_const', const=True)
    args = parser.parse_args()
    if args.profile:
        profile = cProfile.Profile()
        profile.enable()

    st = time.time()

    horizon = 0.1
    # Set simulation parameters
    # =============================================================================
    #     model = OpenCLProbabilistic(mesh_file_name,
    #                                 density = 1.0,
    #                                 horizon = horizon,
    #                                 damping = 1.0,
    #                                 dx = 0.01,
    #                                 bond_stiffness_const = 1.0,
    #                                 critical_stretch_const = 1.0,
    #                                 sigma = np.exp(-2.5),
    #                                 l = np.exp(-30.0),
    #                                 crack_length = 0.3,
    #                                 volume_total=1.0,
    #                                 bond_type=bond_type,
    #                                 network_file_name = 'Network_2.vtk',
    #                                 initial_crack=[],
    #                                 dimensions=2,
    #                                 transfinite= 0,
    #                                 precise_stiffness_correction = 1)
    # =============================================================================
    model = OpenCL(mesh_file_name,
                   density=1.0,
                   horizon=horizon,
                   damping=1.0,
                   bond_stiffness_concrete=(np.double(
                       (18.00 * 0.05) / (np.pi * np.power(horizon, 4)))),
                   critical_strain_concrete=0.005,
                   crack_length=0.3,
                   volume_total=1.0,
                   bond_type=bond_type,
                   network_file_name='Network_2.vtk',
                   initial_crack=[],
                   dimensions=2,
                   transfinite=0,
                   precise_stiffness_correction=1)
    model.dt = np.double(1.2e-3)
    displacement_rate = 1e-5
    # Set force and displacement boundary conditions
    boundary_function(model, displacement_rate)
    boundary_forces_function(model)
    # delete output directory contents, this is probably unsafe?
    shutil.rmtree('./output', ignore_errors=False)
    os.mkdir('./output')
    # =============================================================================
    #     l = [-4.8, -4.8, -4.8, -4.8, -4.8, -4.8, -4.8, -4.8, -4.8, -4.8]
    #     s = [-3.8, -3.8, -3.8, -3.8, -3.8, -3.8, -3.8, -3.8, -3.8, -3.8]
    #     integrator = EulerStochasticOptimised(model)#, error_size_max=1e-6, error_size_min=1e-20)
    #     samples = 1
    #     for sample in range(samples):
    #         model._set_H(np.exp(l[sample]), np.exp(s[sample]), bond_stiffness_const = 1.0, critical_stretch_const = 1.0)
    #         integrator.reset(model, steps=350)
    #         damage_sum_data= model.simulate(model, sample=sample, realisation=1, steps=350, integrator=integrator, write=350, toolbar=0, displacement_rate = displacement_rate)
    # =============================================================================
    model._set_D(1.0, 1.5)
    integrator = EulerOpenCLMCMC(model)
    integrator.reset(model)
    damage_sum_data, tip_displacement_data, tip_shear_force_data = model.simulate(
        model,
        sample=1,
        steps=350,
        integrator=integrator,
        write=10,
        toolbar=0,
        displacement_rate=displacement_rate)
    print('damage_sum_data', damage_sum_data)
    print('TOTAL TIME REQUIRED {}'.format(time.time() - st))
    plt.figure(1)
    plt.title('damage over time')
    plt.plot(damage_sum_data)
    #plt.figure(2)
    #plt.title('tip displacement over time')
    #plt.plot(tip_displacement_data)
    #plt.show()
    if args.profile:
        profile.disable()
        s = StringIO()
        stats = Stats(profile, stream=s).sort_stats(SortKey.CUMULATIVE)
        stats.print_stats()
        print(s.getvalue())
def main():
    """
    3D canteliver beam peridynamics simulation
    """
    parser = argparse.ArgumentParser()
    parser.add_argument('--profile', action='store_const', const=True)
    args = parser.parse_args()

    if args.profile:
        profile = cProfile.Profile()
        profile.enable()

    st = time.time()

    volume_total = 1.0 * 0.2 * 0.1
    density_concrete = 2400
    #self_weight = 1.*density_concrete * volume_total * 9.81
    youngs_modulus_concrete = 1. * 22e9
    youngs_modulus_steel = 1. * 210e9
    # Set simulation parameters
    # Two materials in this example, that is 'concrete' and 'steel'
    dx = np.power(1. * volume_total / 81920, 1. / 3)
    horizon = dx * np.pi
    damping = 2.5e6  # damping term
    poisson_ratio = 0.25
    bulk_modulus_concrete = youngs_modulus_concrete / (3 *
                                                       (1 - 2 * poisson_ratio))
    bulk_modulus_steel = youngs_modulus_steel / (3 * (1 - 2 * poisson_ratio))
    bond_stiffness_concrete = (np.double(
        (18.00 * bulk_modulus_concrete) / (np.pi * np.power(horizon, 4))))
    bond_stiffness_steel = (np.double(
        (18.00 * bulk_modulus_steel) / (np.pi * np.power(horizon, 4))))
    #critical_strain_concrete = np.double(1.0) # so that bonds don't break
    critical_strain_concrete = np.double(0.000533)  # check this value
    critical_strain_steel = np.double(0.01)
    crack_length = np.double(0)
    model = OpenCL(mesh_file_name,
                   density=density_concrete,
                   horizon=horizon,
                   damping=damping,
                   dx=dx,
                   bond_stiffness_concrete=bond_stiffness_concrete,
                   bond_stiffness_steel=bond_stiffness_steel,
                   critical_strain_concrete=critical_strain_concrete,
                   critical_strain_steel=critical_strain_steel,
                   crack_length=crack_length,
                   volume_total=volume_total,
                   bond_type=bond_type,
                   network_file_name='Network.vtk',
                   initial_crack=[],
                   dimensions=3,
                   transfinite=1,
                   precise_stiffness_correction=0)
    # Typical values 0.70 to 0.95 (Sandia PeridynamicSoftwareRoadmap)
    # but if need be, can be 0.05 or lower
    saf_fac = 0.7
    model.dt = (0.8 * np.power(
        2.0 * density_concrete * dx /
        (np.pi * np.power(model.horizon, 2.0) * dx *
         model.bond_stiffness_concrete), 0.5) * saf_fac)
    model.max_reaction = 10000  # in newtons, about 85 times self weight
    model.load_scale_rate = 1 / 10000
    displacement_rate = 0
    # Set force and displacement boundary conditions
    boundary_function(model, displacement_rate)
    boundary_forces_function(model)

    integrator = EulerCromerOptimised(model)

    # delete output directory contents, this is probably unsafe?
    shutil.rmtree('./output', ignore_errors=False)
    os.mkdir('./output')
    damage_sum_data, tip_displacement_data, tip_shear_force_data = model.simulate(
        model,
        sample=1,
        steps=15000,
        integrator=integrator,
        write=500,
        toolbar=0)
    print(tip_displacement_data)
    print(tip_shear_force_data)
    print(damage_sum_data)
    print('TOTAL TIME REQUIRED {}'.format(time.time() - st))
    plt.figure(1)
    plt.title('damage over time')
    plt.plot(damage_sum_data)
    plt.figure(2)
    plt.title('tip displacement over time')
    plt.plot(tip_displacement_data)
    plt.show()
    if args.profile:
        profile.disable()
        s = StringIO()
        stats = Stats(profile, stream=s).sort_stats(SortKey.CUMULATIVE)
        stats.print_stats()
        print(s.getvalue())