cr_trig_create module

Create irregular (triangular) meshes for CRMod/CRTomo from simple ASCII input files.

Create the input files “electrodes.dat”, “boundaries.dat”, “char_length.dat” according to the CRLab manual. An optional file “gmsh_commands.dat” file can be used to append GMSH commands at the end of the generated gmsh command file. Note that these command will be executed only after the initial meshing, but can be used to refine the mesh.

Then run the command cr_trig_create.

If an (optional) parameter is provided, use this as the output directory. This directory must not exist. In case no parameter is given, create a random directory using the uuid module.

The output directory is printed in the last line of program output.

The command line interface is documented as follows:

Usage: cr_trig_create [options]

Options:
  -h, --help            show this help message and exit
  -m NR, --add_stabilizer_nodes=NR
                        (for surface electrodes only!) How many nodes to put
                        between electrodes

Examples:

>>> # note that this is a shell example, not Python!
    cat electrodes.dat
1.0 0.0
2.0 0.0
>>> cat boundaries.dat
0.0 0.0 12
1.0 0.0 12
2.0 0.0 11
2.0 -2.0 11
0.0 -2.0 11
>>> cat char_length.dat
0.5
>>> cat extra_lines.dat
0.5 -0.5 1.5 -1.5
>>> cr_trig_create.py
class cr_trig_create.Mesh[source]

Bases: object

GMSH distinguishes three types of objects:

  • Points on the boundary (i.e., points that create the boundary)

  • Lines that connect Points to form the actual boundaries

  • Points in Surface, nodes (or points) that lie IN the grid and need to be connected to the grid

Note

TODO: I think we don’t need to add electrodes as POINTS, only as POINT IN SURFACE, because POINTs that do not belong to a line will not be included in the final mesh, or? Check. Possible Answer: We need to define the Points before we can add them with the IN SURFACe command.

Check for duplicate entries in input files

Can we test if all electrodes and extra-nodes lie in the boundaries?

Sort boundaries

Add extra-nodes (for inner-grid-structure)

Add extra-lines (for inner-grid-structure)

add_boundary(p1, p2, btype)[source]

Add a boundary line

add_line(p1, p2, char_length)[source]

Add a line to the list. Check if the nodes already exist, and add them if not.

Return the line index (1-indixed, starting with 1)

get_point_id(p, char_length)[source]

Return the id of the given point (x,y) tuple.

is_in(search_list, pair)[source]

If pair is in search_list, return the index. Otherwise return -1

read_char_lengths(filename, electrode_filename)[source]

Read characteristic lengths from the given file.

The file is expected to have either 1 or 4 entries/lines with characteristic lengths > 0 (floats). If only one value is encountered, it is used for all four entities. If four values are encountered, they are assigned, in order, to:

  1. electrode nodes

  2. boundary nodes

  3. nodes from extra lines

  4. nodes from extra nodes

Note that in case one node belongs to multiple entities, the smallest characteristic length will be used.

If four values are used and the electrode length is negative, then the electrode positions will be read in (todo: we open the electrode.dat file two times here…) and the minimal distance between all electrodes will be multiplied by the absolute value of the imported value, and used as the characteristic length:

\[l_{electrodes} = min(pdist(electrodes)) * |l_{electrodes}^{from file}|\]

The function scipy.spatial.distance.pdist is used to compute the global minimal distance between any two electrodes.

It is advisable to only used values in the range [-1, 0) for the automatic char length option.

read_electrodes(electrodes)[source]

Read in electrodes, check if points already exist

read_extra_lines(filename)[source]

Read extra lines from the given filename. Each line is defined in one line with four coordinates: x1 y1 x2 y2. (x1,y1) denotes the starting point, (x2, y2) the end point of the line.

read_extra_nodes(filename)[source]

Read extra nodes in. Format: x y

What happens if we add nodes on the boundaries, which are not included in the boundaries?

write_boundaries(filename)[source]

Write boundary lines X1 Y1 X2 Y2 TYPE to file

write_electrodes(filename)[source]

Write X Y coordinates of electrodes

write_extra_nodes(fid)[source]
write_geo_file(filename)[source]

Write the .geo file

write_in_plane_nodes(fid)[source]
write_lines(fid)[source]
write_points(fid)[source]

Write the grid points to the GMSH-command file.

Parameters:

fid (file object for the command file (.geo))

cr_trig_create._check_boundary_type_ordering(boundaries)[source]

Check that type 12 boundaries come before type 11 boundaries, and that type 11 and type 12 boundaries are continuous

cr_trig_create._check_for_duplicate_boundary_nodes(boundaries)[source]
cr_trig_create.add_stabilizer_nodes(boundaries_raw, electrodes, nr_nodes_between)[source]
Segmentation of nodes:

we have the existing nodes N.F is the ratio of required nodes and existing nodes first, add N nodes to each segment then, add one more node to the F first segments

  • assume ordered boundaries

cr_trig_create.check_boundaries(boundaries)[source]
cr_trig_create.handle_cmd_options()[source]
cr_trig_create.main()[source]