# pycbg.preprocessing.Simulation¶

class pycbg.preprocessing.Simulation(title='Sim_title', directory='', input_filename='input_file')

Includes all simulation ingredients in order to create an appropriate CB-Geo MPM .json input file with the write_input_file method, after attributes definition.

Parameters
• title (str, optional) – Simulation title. Default is ‘Sim_title’.

• directory (str, optional) – Path to the simulation’s directory (will be created if not existent. User-indication of a final ‘/’ is optional). Mesh, particles and entity sets files will be saved in this directory. The result folder is also set to be created by CB-Geo MPM in this directory. Default is title.

• input_filename (str, optional) – Name of the input file for CB-Geo MPM, the extension .json is automatically added. Default is ‘input_file’.

mesh

Simulation’s mesh. Created using the create_mesh method.

Type

Mesh object

particles

Simulation’s particles. Created using the create_particles method.

Type

Particles object

entity_sets

Simulation’s entity sets. Created using the init_entity_sets method.

Type

EntitySets object

materials

Simulation’s materials. Created upon creating the Simulation object.

Type

Materials object

init_stresses

Initial stresses for each particle, to define through the set_initial_particles_stresses method, if desired. Noting npart the number of particles, its shape is (npart, 3).

Type

numpy array

input_filename

Path to the CB-Geo MPM json input file to create, the extension ‘.json’ is automatically added.. If directory=’.’, the title of the simulation is automatically added before the user-specified filename. Default is ‘input_file’ in directory.

Type

str

title

Simulation title. Can be passed as an instantiation parameter.

Type

str

directory

Path to the simulation’s directory. Can be passed as an instantiation parameter.

Type

str

custom_params

Dictionary containing user-defined parameters. It will be saved in the Simulation object when the input file is written. Its element should be appended using the add_custom_parameters method.

Type

dict

Examples

Simulating under gravity a column made of two materials :

>>> sim = Simulation()
>>> sim.create_mesh(dimensions=(1.,1.,10.), ncells=(1,1,10))
>>> sim.create_particles(npart_perdim_percell=1)
>>> sim.init_entity_sets()
>>> lower_particles = sim.entity_sets.create_set(lambda x,y,z: z<10, typ="particle")
>>> upper_particles = sim.entity_sets.create_set(lambda x,y,z: z>=10, typ="particle")
>>> sim.materials.create_MohrCoulomb3D(pset_id=lower_particles)
>>> sim.materials.create_Newtonian3D(pset_id=upper_particles)
>>> walls = []
>>> walls.append([sim.entity_sets.create_set(lambda x,y,z: x==lim, typ="node") for lim in [0, sim.mesh.l0]])
>>> walls.append([sim.entity_sets.create_set(lambda x,y,z: y==lim, typ="node") for lim in [0, sim.mesh.l1]])
>>> walls.append([sim.entity_sets.create_set(lambda x,y,z: z==lim, typ="node") for lim in [0, sim.mesh.l2]])
>>> for direction, sets in enumerate(walls): _ = [sim.add_velocity_condition(direction, 0., es) for es in sets]
>>> sim.set_gravity([0,0,-9.81])
>>> sim.set_analysis_parameters(dt=1e-3, nsteps=1.5e8, output_step_interval=7.5e6)
>>> sim.write_input_file()

__init__(title='Sim_title', directory='', input_filename='input_file')

Methods

 __init__ add_custom_parameters Add dict content in custom_params. add_force Add a force on all the elements in a entity set. add_friction_condition Add a friction condition on a node set. add_math_function Add a math function to the simulation. add_velocity_condition Add a velocity condition on a node or particle set. create_mesh Create the simulation's mesh. create_particles Create the simulation's particles. init_entity_sets Create the simulation's EntitySets object. set_analysis_parameters Set the analysis parameters. set_gravity Set the value of gravity. set_initial_particles_stresses Set the initial stresses for each particle. write_input_file Write the input file.

Parameters

dic (dict) – Dictionary containing the parameters to be appended in custom_params.

Add a force on all the elements in a entity set.

Parameters
• dir ({0, 1, 2}) – Axis on which the force is imposed.

• force (float) – Imposed force’s value ($$N$$).

• entity_set (int) – Id of the entity set on which the force is imposed.

• typ ({"node", "particle"}, optional) – Type of set on which the force is imposed. Default is “node”.

• math_function_id (int, optional) – Id of the math function to use. Default value is None (the load is then static).

Add a friction condition on a node set.

Parameters
• dir ({0, 1, 2}) – Axis of the normal vector to the plane where friction is acting.

• sgn_n ({-1, 1}) – Sign of the normal vector to the plane where friction is acting.

• frict_value (float) – Imposed friction coefficient’s value.

• node_set (int) – Id of the node set on which friction is imposed.

Add a math function to the simulation. The function can only be piecewise-linear.

Parameters
• times (list of floats) – Contains the times at which the values of the math function are given. The first element should always be 0. and the last should always be nsteps*dt.

• values (list of floats) – Contains the values of the math function for each time given in times.

Returns

Id of the math function just appended.

Return type

int

Add a velocity condition on a node or particle set.

Parameters
• dir ({0, 1, 2}) – Axis on which the velocity is imposed.

• vel_value (float) – Imposed velocity’s value ($$m.s^{-1}$$).

• entity_set (int) – Id of the entity set on which the velocity is imposed.

• typ ({"node", "particle"}, optional) – Type of set on which the velocity is imposed. Default is “node”.

create_mesh(*args, **kwargs)

Create the simulation’s mesh.

Parameters
• dimensions (tuple of floats) – Dimensions of the mesh. Its length should be 3, with dimensions[n] the dimension of the mesh on the axis n.

• ncells (tuple of ints) – Number of cells in each direction. Its length should be 3, with ncells[n] the number of cells on the axis n.

• check_duplicates (bool, optional) – See CB-Geo documentation for informations on this parameter. Default is True.

• cell_type ({'ED3H8', 'ED3H20', 'ED3H64G'}, optional) – Type of cell. Only 3D Hexahedrons are supported. The number of nodes can be 8, 20 or 64. Default is ‘ED3H8’.

create_particles(*args, **kwargs)

Create the simulation’s particles.

Parameters
• npart_perdim_percell (int, optional) – Number of particles for each dimension in one cell. All cells will contain npart_perdim_percell**3 equally spaced particles. Note that particles are equally spaced within a cell, not between cells. Default is 1 .

• check_duplicates (bool, optional) – See CB-Geo MPM documentation for informations on this parameter. Default is True.

init_entity_sets()

Create the simulation’s EntitySets object.

Has to be called after mesh and particles creation.

set_analysis_parameters(type='MPMExplicit3D', mpm_scheme='usl', damping=0.05, locate_particles=False, dt=1e-05, velocity_update='flip', nsteps=2000, verbosity=1000, output_step_interval=100)

Set the analysis parameters. Has to be called before write_input_file.

Parameters
• type ({'MPMExplicit2D', 'MPMExplicit3D'}, optional) – Analysis type. Default is ‘MPMExplicit3D’.

• mpm_scheme ({'usf', 'usl', 'musl'}, optional) – MPM scheme for the stress update. The scheme can be “Update Stress First” (‘usf’), “Update Stress Last” (‘usl’) or “Modified Update Stress Last” (‘musl’).

• damping (float, optional) – Cundall’s damping. Should verify : 0 <= damping < 1. Default is 0.05 .

• locate_particles (bool, optional) – Stops the simulation when particles go outside the mesh if True. Default is False.

• dt (float, optional) – Time step ($$s$$). Default is 1e-5 $$s$$.

• velocity_update ({'pic', 'flip', 'apic'}, optional) – How to compute particle’s velocity. If ‘pic’ nodal velocity is directly interpolated to particles. If ‘flip’ nodal velocity is computed from the acceleration interpolated to particles. If ‘apic’, momentum is interpolated according to Jiang, Chenfanfu, et al., 2015. Default is ‘flip’.

• nsteps (int, optional) – Number of steps to be performed. Default is 2000.

• verbosity (int, optional) – Number of lines to be printed in the console. Default is 1000.

• output_step_interval (int, optional) – Number of steps between two data points. Default is 100.

set_gravity(gravity)

Set the value of gravity. If this method isn’t called, gravity is [0,0,0].

Parameters

gravity (list of floats) – Gravity’s value on each axis ($$m/s^2$$).

set_initial_particles_stresses(init_stresses)

Set the initial stresses for each particle.

Parameters

init_stresses (numpy array) – Initial stresses for each particle. Noting npart the number of particles, it should have the shape (npart, 6).

write_input_file()

Write the input file.