object_in_fluid package

Submodules

object_in_fluid.oif_classes module

class object_in_fluid.oif_classes.Angle(A, B, C, D)[source]

Bases: object

Represents angles in a mesh.

size()[source]
class object_in_fluid.oif_classes.Edge(A, B)[source]

Bases: object

Represents edges in a mesh.

length()[source]
class object_in_fluid.oif_classes.FixedPoint(pos, id)[source]

Bases: object

Represents mesh points, not connected to any ESPResSo particle.

get_id()[source]
get_pos()[source]
class object_in_fluid.oif_classes.Mesh(nodes_file=None, triangles_file=None, system=None, resize=(1.0, 1.0, 1.0), particle_type=-1, particle_mass=1.0, normal=False, check_orientation=True)[source]

Bases: object

Represents a triangular mesh.

check_orientation()[source]
copy(origin=None, particle_type=-1, particle_mass=1.0, rotate=None)[source]

Create particles in the system.

get_n_edges()[source]

Get the number of edges.

get_n_nodes()[source]

Get the number of mesh points.

get_n_triangles()[source]

Get the number of triangles.

mirror(mirror_x=0, mirror_y=0, mirror_z=0, out_file_name='')[source]
output_mesh_triangles(triangles_file=None)[source]

Write the current triangles into a file that can be used as input in the next simulations. This is useful after checking orientation, if any of the triangles were corrected.

surface()[source]
volume()[source]
class object_in_fluid.oif_classes.OifCell(cell_type=None, origin=None, particle_type=None, particle_mass=1.0, rotate=None)[source]

Bases: object

Represent a concrete elastic object (“cell”).

Parameters:
  • cell_type (OifCellType) – Template containing mesh nodes, triangle incidences, elasticity parameters and bond parameters, and a system, into which particles and bonds will be instantiated.

  • particle_type (int) – Must start at 0 for the first cell and monotonically increase for subsequent cells. Volume calculation of individual objects and interactions between objects are set up using these types.

  • origin ((3,) array_like of float) – Center of the cell object.

  • particle_mass (float) – Mass of each particle forming the cell.

  • rotate ((3,) array_like of float) – angles in radians, by which the cell will be rotated about the x, y, z axis. Default value is (0.0, 0.0, 0.0). Value (\(\pi/2, 0.0, 0.0\)) means that the object will be rotated by \(\pi/2\) radians clockwise around the x axis when looking in the positive direction of the axis.

append_point_data_to_vtk(file_name=None, data_name=None, data=None, first_append=None)[source]

Append the specified scalar data to a VTK file. This is useful for ParaView visualisation of local velocity magnitudes, magnitudes of forces, …, in the meshnodes and can be shown in ParaView by selecting the data_name in the Properties toolbar. It is possible to consecutively write multiple datasets; for the first one, the first_append parameter is set to True, for the following datasets, it needs to be set to False. This is to ensure the proper structure of the output file.

diameter()[source]

Compute the maximal pairwise distance between all mesh points. Computational complexity is \(\mathcal{O}(N^2)\).

elastic_forces(el_forces=(0, 0, 0, 0, 0, 0), f_metric=(0, 0, 0, 0, 0, 0), vtk_file=None, raw_data_file=None)[source]

This method can be used in two different ways. One is to compute the elastic forces locally for each mesh point, and the other is to compute the f-metric, which is an approximation of elastic energy.

To compute the elastic forces, use the vector el_forces. It is a sextuple of zeros and ones, e.g. el_forces = (1,0,0,1,0,0), where the ones denote the elastic forces to be computed. The order is (stretching, bending, local area, global area, volume, total). The output can be saved in two different ways: either by setting vtk_file = filename.vtk, which saves a VTK file that can be visualized using ParaView. If more than one elastic force was selected, they can be chosen in the Properties window in ParaView. The other type of output is raw_data_file*=filename.dat, which will save a datafile with the selected type of elastic force - one force per row, where each row corresponds to a single mesh node. Note that only one type of elastic force can be written this way at a time. Thus, if you need output for several elastic forces, this method should be called several times.

To compute the f-metric, use the vector f_metric. It is also a sextuple of zeros and ones, e.g. f_metric = (1,1,0,0,0,0), where the ones denote the elastic forces to be computed. The order is (stretching, bending, local area, global area, volume, total). The output is also a vector with six elements, each corresponding to the requested f-metric/”naive energy” computed as a sum of magnitudes of respective elastic forces over all mesh points.

get_approx_origin()[source]

Get the approximate location of the cell center. It is computed as average of 6 mesh points that have extremal x, y and z coordinates at the time of object loading.

get_n_nodes()[source]

Get the number of mesh points.

get_origin()[source]

Get the cell center in unfolded coordinates.

get_origin_folded()[source]

Get the cell center in folded coordinates.

get_velocity()[source]

Get the average velocity of the cell mesh points.

output_mesh_points(file_name=None)[source]

Write the positions of the mesh points to a white-space delimited text file. This file can later be read by set_mesh_points(). The center of the object is located at (0.0, 0.0, 0.0). This method is meant to store a deformed shape in order to be loaded later as a new shape template.

output_raw_data(file_name=None, data=None)[source]

Write the vector or matrix rawdata to a white-space delimited text file. The rows are ordered by the mesh points indices.

output_vtk_pos(file_name=None)[source]

Write the mesh information to a VTK file in unfolded coordinates. ParaView can directly visualize this file.

output_vtk_pos_folded(file_name=None)[source]

Write the mesh information to a VTK file in folded coordinates. ParaView can directly visualize this file.

pos_bounds()[source]

Compute six extremal coordinates of the cell. More precisely, run through all mesh points and return the minimal and maximal \(x\)-coordinate, \(y\)-coordinate and \(z\)-coordinate in the order (\(x_{max}\), \(x_{min}\), \(y_{max}\), \(y_{min}\), \(z_{max}\), \(z_{min}\)).

print_info()[source]

Print information about the cell.

set_force(new_force=(0.0, 0.0, 0.0))[source]

Set an external force to all mesh points. Note, that this command sets the external force in each integration step. So if you want to use the external force only in one iteration, you need to set zero external force in the following integration step.

set_mesh_points(file_name=None)[source]

Read a file containing a list of mesh point coordinates to deform the current cell. The current origin stays unchanged. The file should contain the coordinates of the mesh points with the origin location at (0.0, 0.0, 0.0). It can be generated by output_mesh_points().

set_origin(new_origin=(0.0, 0.0, 0.0))[source]

Set the cell center.

set_velocity(new_velocity=(0.0, 0.0, 0.0))[source]

Set the velocity of all cell mesh points.

surface()[source]

Get the cell surface.

volume()[source]

Get the cell volume.

class object_in_fluid.oif_classes.OifCellType(nodes_file='', triangles_file='', system=None, resize=(1.0, 1.0, 1.0), ks=0.0, kslin=0.0, kb=0.0, kal=0.0, kag=0.0, kv=0.0, kvisc=0.0, normal=False, check_orientation=True)[source]

Bases: object

Template to create elastic objects (“cells”) from a mesh file.

The switches ks, kb and kal set elastic parameters for local interactions: ks for edge stiffness, kb for angle preservation stiffness and kal for triangle area preservation stiffness. Currently, the stiffness is implemented to be uniform over the whole object, but with some tweaking, it is possible to have non-uniform local interactions. At least one of the elastic moduli should be set.

Note the difference between stretching (ks) and linear stretching (kslin): these two options cannot be used simultaneously. Linear stretching behaves like linear spring, where the stretching force is calculated as \(\mathbf{f_{ij}} = k_s \mathbf{d_{ij}}\), where \(\mathbf{d_{ij}}\) is the prolongation of the given edge. By default, the stretching is non-linear (neo-Hookean). The optional viscous damping (kvisc) is meant to reduce oscillations in the stretching force. This corresponds to the case \(\gamma^T = 0\) and \(\gamma^C = k_{\mathrm{visc}}\) in equation 8 of [Fedosov et al., 2010] (which uses the \(\times\) symbol for the dot product).

Parameters:
  • nodes_file (str) – Path to the mesh data file. Each line contains three real numbers. These are the x, y, z coordinates of individual surface mesh nodes of the objects centered at [0,0,0] and normalized so that the “radius” of the object is 1.

  • triangles_file (str) – Path to the triangles data file. Each line contains three integers representing the 0-indexed line number of the mesh nodes in nodes_file that form a triangle.

  • system (espressomd.system.System) – System in which particles will be created.

  • ks (float) – Elastic modulus for stretching forces.

  • kslin (float) – Elastic modulus for linear stretching forces.

  • kb (float) – Elastic modulus for bending forces.

  • kal (float) – Elastic modulus for local area forces.

  • kvisc (float) – Viscous damping for stretching forces.

  • kag (float) – Elastic modulus for global area forces.

  • kv (float) – Elastic modulus for volume forces.

  • resize ((3,) array_like of float) – Scaling factor by which the coordinates stored in nodes_file will be stretched in the x, y, z directions.

  • normal (bool) – If True, create list of neighbors to allow membrane collisions, and thus cell-cell interactions.

  • check_orientation (bool) – If True, check whether triangles_file contains triangles with correct orientation. If not, it corrects the orientation and created cells with corrected triangles. It is useful for new or unknown meshes, but not necessary for meshes that have already been tried out. Since it can take a few minutes for larger meshes (with thousands of nodes), it can be set to False. In that case, the check is skipped when creating the CellType and a warning is displayed.

    The order of indices in triangles_file is important. Normally, each triangle ABC should be oriented in such a way, that the normal vector computed as vector product ABxAC must point inside the object. For example, a sphere (or any other sufficiently convex object) contains such triangles that the normals of these triangles point towards the center of the sphere (almost).

    The check runs over all triangles, makes sure that they have the correct orientation and then calculates the volume of the object. If the result is negative, it flips the orientation of all triangles.

    Note, this method tells the user about the correction it makes. If there is any, it might be useful to save the corrected triangulation for future simulations using the method Mesh.output_mesh_triangles(), so that the check does not have to be used repeatedly.

print_info()[source]

Print information about this template.

class object_in_fluid.oif_classes.PartPoint(part, id, part_id)[source]

Bases: object

Represents mesh points, connected to ESPResSo particle.

get_force()[source]
get_mass()[source]
get_pos()[source]
get_type()[source]
get_vel()[source]
kill_motion()[source]
set_force(force)[source]
set_pos(pos)[source]
set_vel(vel)[source]
unkill_motion()[source]
class object_in_fluid.oif_classes.ThreeNeighbors(A, B, C)[source]

Bases: object

Represents three best spatially distributed neighbors of a point in a mesh.

outer_normal()[source]
class object_in_fluid.oif_classes.Triangle(A, B, C)[source]

Bases: object

Represents triangles in a mesh.

area()[source]

object_in_fluid.oif_utils module

object_in_fluid.oif_utils.angle_btw_triangles(P1, P2, P3, P4)[source]

Returns the size of an angle between triangles given by points P2, P1, P3 and P2, P3, P4 that share a common edge P2, P3.

Parameters:
  • P1 ((3,) array_like of float) – Point P1

  • P2 ((3,) array_like of float) – Point P2

  • P3 ((3,) array_like of float) – Point P3

  • P4 ((3,) array_like of float) – Point P4

object_in_fluid.oif_utils.area_triangle(a, b, c)[source]

Returns the area of a triangle given by points a, b, c.

Parameters:
  • a ((3,) array_like of float) – Point a

  • b ((3,) array_like of float) – Point b

  • c ((3,) array_like of float) – Point c

object_in_fluid.oif_utils.custom_str(realn)[source]
object_in_fluid.oif_utils.discard_epsilon(x)[source]

Returns zero if the argument is too small.

Parameters:

x (float) – real number

object_in_fluid.oif_utils.get_triangle_normal(a, b, c)[source]

Returns the normal vector of a triangle given by points a,b,c.

Parameters:
  • a ((3,) array_like of float) – Point a

  • b ((3,) array_like of float) – Point b

  • c ((3,) array_like of float) – Point c

object_in_fluid.oif_utils.norm(vect)[source]

Returns the norm of a vector.

Parameters:

vect ((3,) array_like of float) – Input vector

object_in_fluid.oif_utils.oif_calc_bending_force(kb, pA, pB, pC, pD, phi0, phi)[source]

Calculates bending forces for four points on two adjacent triangles.

Parameters:
  • kb (float) – coefficient of the stretching, spring stiffness

  • pA ((3,) array_like of float) – position of the first particle

  • pB ((3,) array_like of float) – position of the second particle

  • pC ((3,) array_like of float) – position of the third particle

  • pD ((3,) array_like of float) – position of the fourth particle

  • phi0 (float) – relaxed angle btw two triangles

  • phi (float) – current angle btw two triangles

object_in_fluid.oif_utils.oif_calc_global_area_force(kag, pA, pB, pC, Ag0, Ag)[source]

Calculates global area forces between three points in a triangle.

Parameters:
  • kag (float) – coefficient of the stretching, spring stiffness

  • pA ((3,) array_like of float) – position of the first particle

  • pB ((3,) array_like of float) – position of the second particle

  • pC ((3,) array_like of float) – position of the third particle

  • Ag0 (float) – relaxed surface area of the cell

  • Ag (float) – current surface area of the cell

object_in_fluid.oif_utils.oif_calc_linear_stretching_force(ks, pA, pB, dist0, dist)[source]

Calculates linear stretching forces between two points on an edge.

Parameters:
  • ks (float) – coefficient of the stretching, spring stiffness

  • pA ((3,) array_like of float) – position of the first particle

  • pB ((3,) array_like of float) – position of the second particle

  • dist0 (float) – relaxed distance btw particles

  • dist (float) – current distance btw particles

object_in_fluid.oif_utils.oif_calc_local_area_force(kal, pA, pB, pC, A0, A)[source]

Calculates local area forces between three points in one triangle.

Parameters:
  • kal (float) – coefficient of the stretching, spring stiffness

  • pA ((3,) array_like of float) – position of the first particle

  • pB ((3,) array_like of float) – position of the second particle

  • pC ((3,) array_like of float) – position of the third particle

  • A0 (float) – relaxed area of the triangle

  • A (float) – current area of the triangle

object_in_fluid.oif_utils.oif_calc_stretching_force(ks, pA, pB, dist0, dist)[source]

Calculates nonlinear stretching forces between two points on an edge.

Parameters:
  • ks (float) – coefficient of the stretching, spring stiffness

  • pA ((3,) array_like of float) – position of the first particle

  • pB ((3,) array_like of float) – position of the second particle

  • dist0 (float) – relaxed distance btw particles

  • dist (float) – current distance btw particles

object_in_fluid.oif_utils.oif_calc_volume_force(kv, pA, pB, pC, V0, V)[source]

Calculates volume forces for three points in a triangle.

Parameters:
  • kv (float) – coefficient of the stretching, spring stiffness

  • pA ((3,) array_like of float) – position of the first particle

  • pB ((3,) array_like of float) – position of the second particle

  • pC ((3,) array_like of float) – position of the third particle

  • V0 (float) – relaxed volume of the cell

  • V (float) – current volume of the cell

object_in_fluid.oif_utils.oif_neo_hookean_nonlin(lambd)[source]

Defines neo-Hookean non-linear factor (equation 19 in [Dupin et al., 2007]).

Parameters:

lambd (float) – real number

object_in_fluid.oif_utils.output_vtk_cylinder(cyl_shape, n, out_file)[source]

Outputs the VTK files for visualisation of a cylinder in e.g. ParaView.

Parameters:
  • cyl_shape (espressomd.shapes.Cylinder) – cylindrical shape

  • n (int) – number of discretization sections

  • out_file (str) – filename for the output

object_in_fluid.oif_utils.output_vtk_lines(lines, out_file)[source]

Outputs the VTK files for visualisation of lines in e.g. ParaView.

Parameters:
  • lines (array_like float) – lines is a list of pairs of points p1, p2 each pair represents a line segment to output to vtk each line in lines contains 6 floats: p1x, p1y, p1z, p2x, p2y, p2z

  • out_file (str) – filename for the output

object_in_fluid.oif_utils.output_vtk_pore(axis, length, outer_rad_left, outer_rad_right, pos, rad_left, rad_right, smoothing_radius, m, out_file)[source]

Outputs the VTK files for visualisation of a pore in e.g. ParaView.

Parameters:
  • axis ((3,) array_like of float) – The axis

  • length (float) – length of pore

  • outer_rad_left (float) – outer left radius of pore

  • outer_rad_right (float) – outer right radius of pore

  • rad_left (float) – inner left radius of pore

  • rad_right (float) – inner right radius of pore

  • smoothing_radius (float) – smoothing radius for surface connecting outer and inner radii of the pore

  • pos ((3,) array_like of float) – Position of the center of the pore

  • m (int) – number of discretization sections

  • out_file (str) – filename for the output

object_in_fluid.oif_utils.output_vtk_rhomboid(rhom_shape, out_file)[source]

Outputs the VTK files for visualisation of a rhomboid in e.g. ParaView.

Parameters:
object_in_fluid.oif_utils.vec_distance(a, b)[source]

Returns the length of vector between points a and b.

Parameters:
  • a ((3,) array_like of float) – Point a

  • b ((3,) array_like of float) – Point b

Module contents