foamgen.geo_tools

GMSH CAD support module

synopsis

Manipulates .geo input files for gmsh.

Functions

collect_strings(edat)

Convert extracted data to string format.

create_walls(edat[, wall_thickness])

Creates walls by shring each cell.

extract_data(sdat)

Extract gmsh geometry data read by read_geo().

findall_top(regex, text)

Like re.findall, but returns only top level group in list.

fix_strings(strings)

Remove negative signs (orientation) from loops.

identify_duplicity(edat, key, number, eps)

Core algorithm for removing duplicities.

move_to_box(infile, wfile, outfile, mvol)

Moves periodic closed foam to periodic box.

other_surfaces(edat, surfs)

Find boundary surfaces, which are not in surfs.

periodic_surfaces(edat, surfaces, vec[, eps])

Find periodic surface pairs in specified direction.

prep_mesh_config(fname, sizing[, char_length])

Create file specifying meshing parameters.

read_geo(geo_file[, plane_surface])

Read gmsh input file and extract geometry information.

remove_duplicit_ids_from_keys(edat, dupl, key)

Removes duplicit IDs from IDs of entities.

remove_duplicit_ids_from_values(edat, dupl, key)

Removes duplicit IDs from values of entities.

remove_duplicity(edat[, eps])

Removes duplicit points, lines, etc.

restore_sizing(edat)

Add sizing info to all points.

save_geo(geo_file, sdat[, opencascade])

Save gmsh CAD geometry input to file.

split_loops(edat, key)

Makes sure that line and surface loops contain only one loop.

surfaces_in_plane(edat, coord, direction)

Finds surfaces that lie completely in specified plane.

foamgen.geo_tools.collect_strings(edat)[source]

Convert extracted data to string format.

Opposite of extract_data().

Parameters

edat (dict) – extracted geometry data

Returns

geometry data in string format

Return type

dict

foamgen.geo_tools.create_walls(edat, wall_thickness=0.01)[source]

Creates walls by shring each cell.

Each vertex is moved by toward the cell centroid as:

\[v_n = v_o + w (c - v_o)\]

where \(v_n\) is new vertex position, \(v_o\) is old vertex position, \(w\) is the wall_thickness, and \(c\) is the centroid position.

Parameters
  • edat (dict) – extracted geometry data

  • wall_thickness (float, optional) – shrinking parameter

foamgen.geo_tools.extract_data(sdat)[source]

Extract gmsh geometry data read by read_geo().

Only coordinates are taken from points. Point sizing if any is discarded.

Opposite of collect_strings().

Parameters

sdat (dict) – geometry data in string format

Returns

extracted geometry data

Return type

dict

foamgen.geo_tools.findall_top(regex, text)[source]

Like re.findall, but returns only top level group in list.

Parameters
  • regex (str) – regex patern

  • text (str) – text to search for patern

Returns

list of all matches

Return type

list

foamgen.geo_tools.fix_strings(strings)[source]

Remove negative signs (orientation) from loops.

Used for OpenCASCADE kernel compatibility.

Parameters

strings (list) – list of line or surface loops in string format

foamgen.geo_tools.identify_duplicity(edat, key, number, eps)[source]

Core algorithm for removing duplicities.

User should call remove_duplicity() instead.

Parameters
  • edat (dict) – extracted geometry data

  • key (str) – type of geometry

  • number (str) – number type (float or integer)

  • eps (float) – tolerance

Returns

duplicit objects

Return type

dict

foamgen.geo_tools.move_to_box(infile, wfile, outfile, mvol)[source]

Moves periodic closed foam to periodic box.

Uses gmsh, specifically boolean operations and transformations from OpenCASCADE. The result is unrolled to another geo file so that it can be quickly read and worked with in the follow-up work. Operations are performed two times. First for walls (first half of volumes) and then for cells.

Save output to outfile.

Parameters
  • infile (str) – input filename

  • wfile (str) – working filename

  • outfile (str) – output filename

  • mvol (int) – number of volumes

foamgen.geo_tools.other_surfaces(edat, surfs)[source]

Find boundary surfaces, which are not in surfs.

Assumes that inner surfaces are shared by two volumes. Remove duplicates before calling this function.

Parameters
  • edat (dict) – extracted geometry data

  • surfs (list) – list of surfaces, which should not be returned

Returns

boundary surfaces, which are not in surfs

Return type

list

foamgen.geo_tools.periodic_surfaces(edat, surfaces, vec, eps=1e-08)[source]

Find periodic surface pairs in specified direction.

Only linear periodicity is supported. Checks for surfaces with points offset by specified vector within a tolerance.

Parameters
  • edat (dict) – extracted geometry data

  • surfaces (list) – boundary surfaces

  • vec (ndarray) – offset vector specification

  • eps (float, optional) – tolerance

Returns

periodic surface pairs

Return type

list

foamgen.geo_tools.prep_mesh_config(fname, sizing, char_length=0.1)[source]

Create file specifying meshing parameters.

Creates *UMesh.geo. File will import *Morphology.geo.

Sizing specified at points, edges and cells and implemented through thresholds.

Additional info about gmsh mesh sizing here.

Parameters
  • fname (str) – base filename

  • sizing (list) – mesh size near points, edges and in cells

  • char_length (float, optional) – gmsh Mesh.CharacteristicLengthMax

foamgen.geo_tools.read_geo(geo_file, plane_surface=True)[source]

Read gmsh input file and extract geometry information.

Uses regular expressions. Some geo files use Surface, some Plane Surface. You should specify what you want to read.

Parameters
  • geo_file (str) – input filename

  • plane_surface (bool, optional) – input file contains “Plane Surface” keyword

Returns

dictionary with read lines separated into points, lines, etc.

Return type

dict

foamgen.geo_tools.remove_duplicit_ids_from_keys(edat, dupl, key)[source]

Removes duplicit IDs from IDs of entities.

Parameters
  • edat (dict) – extracted geometry data

  • dupl (dict) – duplicit objects

  • key (str) – type of geometry

foamgen.geo_tools.remove_duplicit_ids_from_values(edat, dupl, key)[source]

Removes duplicit IDs from values of entities.

Parameters
  • edat (dict) – extracted geometry data

  • dupl (dict) – duplicit objects

  • key (str) – type of geometry

foamgen.geo_tools.remove_duplicity(edat, eps=1e-10)[source]

Removes duplicit points, lines, etc.

Parameters
  • edat (dict) – extracted geometry data

  • eps (float) – tolerance

foamgen.geo_tools.restore_sizing(edat)[source]

Add sizing info to all points.

Adds fourth argument called “psize” to each point.

Parameters

edat (dict) – extracted geometry data

foamgen.geo_tools.save_geo(geo_file, sdat, opencascade=True)[source]

Save gmsh CAD geometry input to file.

Input is a dictionary with prepared string lines.

Parameters
  • geo_file (str) – filename

  • sdat (dict) – characterized geometry in string format

  • opencascade (bool, optional) – prepend OpenCASCADE keyword if True

foamgen.geo_tools.split_loops(edat, key)[source]

Makes sure that line and surface loops contain only one loop.

Surfaces and volumes with holes are instead defined in Surface and Volume entries, respectively. Needed because gmsh unrolls geometry in a way, which is unusable with OpenCASCADE kernel.

Parameters
  • edat (dict) – extracted geometry data

  • key (str) – type of geometry

foamgen.geo_tools.surfaces_in_plane(edat, coord, direction)[source]

Finds surfaces that lie completely in specified plane.

Plane must be normal to one of cartesian axes.

Parameters
  • edat (dict) – extracted geometry data

  • coord (float) – point on the chosen axis

  • direction (int) – order of coordinate axis

Returns

line loops in specified plane

Return type

list