foamgen.geo_tools¶
GMSH CAD support module¶
- synopsis
Manipulates
.geo
input files forgmsh
.
Functions
|
Convert extracted data to string format. |
|
Creates walls by shring each cell. |
|
Extract |
|
Like |
|
Remove negative signs (orientation) from loops. |
|
Core algorithm for removing duplicities. |
|
Moves periodic closed foam to periodic box. |
|
Find boundary surfaces, which are not in |
|
Find periodic surface pairs in specified direction. |
|
Create file specifying meshing parameters. |
|
Read |
|
Removes duplicit IDs from IDs of entities. |
|
Removes duplicit IDs from values of entities. |
|
Removes duplicit points, lines, etc. |
|
Add sizing info to all points. |
|
Save |
|
Makes sure that line and surface loops contain only one loop. |
|
Finds surfaces that lie completely in specified plane. |
-
foamgen.geo_tools.
brep2geo
(brep_file, geo_file)[source]¶ Convert BREP CAD geometry to
gmsh
native format.gmsh
is used for the conversion. A temporary filebrep2geo.geo
is created (overwrites existing file if it exists).- Parameters
brep_file (str) – input filename
geo_file (str) – output filename
-
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
- Returns
[cell data, wall data]
- Return type
list
-
foamgen.geo_tools.
extract_data
(sdat)[source]¶ Extract
gmsh
geometry data read byread_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.
geo2brep
(geo_file, brep_file)[source]¶ Convert
gmsh
CAD geometry to BREP format.gmsh
is used for the conversion. A temporary filegeo2brep.geo
is created (overwrites existing file if it exists).- Parameters
geo_file (str) – input filename
brep_file (str) – output filename
-
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.
merge_and_label_geo
(inames, oname)[source]¶ Merge geometry files. Define periodic surfaces and physical volume.
Assumes bounding box [0, 1] in all directions.
- Parameters
inames (list) – input filenames
oname (str) – output filename
-
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
(iname, oname, sizing, char_length=0.1)[source]¶ Create file specifying meshing parameters.
Sizing specified at points, edges and cells and implemented through thresholds.
Additional info about gmsh mesh sizing here.
- Parameters
iname (str) – input filename
oname (str) – output 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.
This function is slow. It does not catch all loops.
- 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