pycbg.preprocessing.EntitySets¶
-
class
pycbg.preprocessing.
EntitySets
(mesh, particles, directory='')¶ Create and write to a file entity sets for nodes and particles.
- Parameters
mesh (
Mesh
object) – Simulation’s mesh. Has to be specified even if only particles sets are defined.particles (
Particles
object) – Simulation’s particles. Has to be specified even if only nodes sets are defined.directory (str, optional) – Directory in which the entity sets file will be saved. If the directory doesn’t already exist, it will be created. It is set by default to the current working directory.
-
nsets
¶ Each element is a list of nodes’ ids belonging to the same set. Its index is the id of the node set.
- Type
list of lists of ints
-
psets
¶ Each element is a list of particles’ ids belonging to the same set. Its index is the id of the particle set.
- Type
list of lists of ints
-
filename
¶ Path to the entity sets file from the current working directory.
- Type
str
Notes
The entity sets file is not written upon creating the object. It is thus necessary to run the write_file method once all entity sets are created.
The user has to define a function for each entity set that indicates which particle or node should be included. See create_set method’s documention for more informations.
Examples
Creating a node and a particle set in a one cell mesh :
>>> mesh = Mesh((1.,1.,1.), (1,1,1)) >>> particles = Particles(mesh, 2) >>> entity_sets = EntitySets(mesh, particles) >>> node_set_id = entity_sets.create_set(lambda x,y,z: x==0, typ="node") >>> particle_set_id = entity_sets.create_set(lambda x,y,z: x<.5, typ="particle")
Note that this example uses lambda functions to create sets with only one line. One could also use :
>>> def x_wall(x, y, z): return x==0 >>> node_set_id = entity_sets.create_set(x_wall, typ="node")
-
__init__
(mesh, particles, directory='')¶ Initialize self. See help(type(self)) for accurate signature.
Methods
Initialize self.
Create a set of nodes or particles and add it to the corresponding list.
Write the entity sets file formatted for CB-Geo.
-
create_set
(condition_function, typ='particle')¶ Create a set of nodes or particles and add it to the corresponding list. Nodes and particles are selected using condition_function.
- Parameters
condition_function (function) – Select particles or nodes using their positions. The inputs should be 3 parameters x, y and z that correspond to the position of a node or particle. Should return True if the node or particle belongs to the set, False otherwise.
typ ({"node", "particle"}, optional) – Type of set to be created. Default is “particle”.
- Returns
Id of the set just appended.
- Return type
int
Examples
Creating a node set using a mesh mesh and the particles particles previously defined :
>>> mesh = Mesh((1.,1.,1.), (1,1,1)) >>> particles = Particles(mesh, 2) >>> entity_sets = EntitySets(mesh, particles) >>> node_set_id = entity_sets.create_set(lambda x,y,z: x==0, typ="node") >>> particle_set_id = entity_sets.create_set(lambda x,y,z: x<.5, typ="particle")
-
write_file
()¶ Write the entity sets file formatted for CB-Geo.