tekigo package

Tékigô, an API for the Mesh adaptation tool with h!p.

Submodules

tekigo.base module

Base functions library for tekigo

tekigo.base.compute_metric(criteria, met_mix, n_node, max_refinement_ratio=0.6)

Calculate metric and estimates new number of nodes given refinement criteria and criteria choice method (‘met_mix’ parameter)

param criteria

a dictionary holding refinement criteria

type criteria

dict( )

param met_mix

type of metric mixing calculation method:

if the criteria choice method is set on “average”, the metric is computed as follows:

\[Metric = 1 - Rr_{max} < C >_i\]

if the criteria choice method is set on “abs_max”, the metric is computed as follows:

\[Metric = 1 - Rr_{max} \, C_i |_{ \tiny \displaystyle \max_{i \, \in \, C} | C_i |}\]

with Metric and C (criteria) vectors of size n_nodes, Rr as Refinement ratio.

type met_mix

string

param n_node

current number of nodes

type n_node

integer

param max_refinement_ratio

refinement parameter for metric computation

type max_refinement_ratio

float

returns

metric field

tekigo.base.filter_metric(vol_node, met_field, coarsen, nnode_max, min_vol)

Perform filtering on the metrics

Parameters
  • vol_node – the nodes volumes array

  • met_field – the metric field to be filtered

  • coarsen – boolean , allow coarsening or not

  • nnode_max – limit the final number of nodes

  • min_vol – limit the min volume

Returns

  • nnode_est : estimation of new number of nodes

  • met_field : metric field

tekigo.base.get_mesh_infos(mesh_f)
tekigo.base.metric_forecast(metric, mesh_file)
tekigo.base.update_h5_file(filename, parent_group, data_dict)

Update hdf5 file by adding a data dictionary to a parent group

Parameters
  • filename – the hdf5 file name

  • parent_group – the parent group under which new datasests are appended

  • data_dict – the data dictionary to append

tekigo.front module

Main functions for Tékigô

tekigo.front.adaptation_pyhip(tekigo_sol, max_spacing_gradient=1.4, hausdorff_distance=None, periodic_adaptation=False, frozen_patch_list=None, edge_high=None, edge_low=None)

Performs a hip adaptation on a tekigo solution

Args :

tekigoSol (obj) : TekigoSOlution object max_spacing_gradient (float): spacing gradient used to smooth the mesh (smoother if closing to 1) hausdorff_distance (float): control curvatuvre fidelity on CADs. periodic_adaptation (bool): allow adaptation on periodic patches frozen_patch_list (list): list of strings, pathecs that must not be changed edge_high (float): MMG3D will try to not get edges higher than this edge_low (float): MMG3D will try to not get edges lower than this

Returns :

f_nnode (int): final nb. of nodes f_ncell (int): final nb. of cells f_hmin (float): final minimal edge length

tekigo.front.calibrate_metric(tekigo_sol, custom_criteria, target_ncells, edge_min=1e-12, allow_coarsening=True, met_mix='abs_max')

Clip and rescale metric to meet global contraints NCELLS and EDGE_MIN.

As this is a compromise between opposed constraints, the method is not always converging. Put some sense in your inputs!

Args :

tekigo_solution: TekigoSolution object custom_criteria (dict): dict of numpy arrays btw -1 (coarsen), 0 (keep as is) and 1 (refine)

target_ncells (int): number of cells in the desired mesh edge_min (float): minimal edge size, metric yielding smaller sizes will be clipped allow_coarsening (bool): if False, no metric higher than 1 will be allowed. met_mix (str): method to mix the different criterias

Returns

the metric clipped and rescaled.

Return type

metric_field_filter (array)

..Note:

About met_mix: - abs_max: takes the absolute maximum (-.3 and 0.7 yields 0.7, -0.9 and 0.1 yields -0.9) - average : average among criterias (-.3 and 0.7 yields 0.2, -0.9 and 0.1 yields -0.4)

tekigo.hipster module

Toward an API for h!p

tekigo.hipster.hip_adapt(mesh_file, sol_file, out_prefix, max_spacing_gradient, hausdorff_distance, frozen_patch_list, edge_low=None, edge_high=None, metric_field='metric', periodic_adaptation=True)

Generates hip.in file from template

Parameters
  • mesh_file (string) – full path to hip input file

  • max_spacing_gradient (number, optional) – maximum spacing gradient

  • hausdorff_distance (number, optional) – target hausdorff distance

  • frozen_patch_list (list of integers, optional) – list of patches to freeze during refinement

  • sol_file (optional) – solution file, if None a solution file is created

  • dry_run (boolean, optional) – if True no refinement is done

  • metric_field (string, optional) – metric index parameter

  • periodic_adaptation (boolean, optional) – if True periodic adaptation is activated in hip

Returns

output of hip

tekigo.hipster.hip_process(hip_cmd_lines, mesh_file)

runner for hipster, uses hip in subprocess, takes command lines, runs it and returns output

Parameters
  • hip_cmd_lines – hip script (with newlines) to be runned

  • mesh_file – mesh (and its directory !) to be read by hip.

tekigo.hipster.popen_execute(cmd, mesh_dir)

Execute comand with contant feedback

tekigo.tekigosol module

Module for object TekigoSolution

class tekigo.tekigosol.TekigoSolution(mesh, solution=None, additionals=True, out_dir='./Results')

Bases: object

Object storing a mesh and its INSTANTANEOUS solution

This is whe mesh and solution used as the basis for an adaptation. Many adaptations strategies exists, and somes do not need averaged CFD fields, But all need an instantaneous field to restart with the new mesh…

..note:

To load average fields into your tekigo solution, use: TekigoSolution.include_average(avg_sol, avg_field)

Parameters
  • mesh (string) – path to an AVBP mesh

  • solution (string) – path to an AVBP instantaneous solution

  • additionals (bool) – include additionals if solution is provided

  • out_dir (string) – path to a folder where results will be stored

add_field_to_solmesh(name, field, group='Adapt')

Add a numpy arry field to the Hdf5 sol file

add_fields_from_solution(sol_file, group, fields, group_suffix=None)

Include average fields to initial solution

Parameters
  • sol_file – str, path to average solution

  • group (str) – str, name of the group

  • fields (list) – list of str, paths of Hdf datasets

  • group_suffix (str) – suffix added to the group in the targed solution

Note

if a group_suffix is provided, the target group will be group+group_suffix this option is to load fields with the same name from different solutions

evaluate_metric(custom_metric, update_tkgsol=True)

Evaluate effects of metric prior to adaptation

  • results of evaluation are printed to log

  • If update_tkgsol is true ,Metrics and target edge

    are stored in solution and xmf file is refreshed

Args :

custom_metric (array) : metric of shape (nnode) : target_edge/init_edge

Returns :

e_nnode (int) : estimated nb. of nodes e_ncell (int) : estimated nb. of cells e_edge (float) : estimated minimal edge length

gatherscatter()

Returns a gathher Sactter object to make operations on fields

load_qoi(address)

Load a quantity of interest from solution

Parameters

address – str, paths of Hdf dataset

tekigo.tkg_logging module

module storing the tekigo specific logging functions

tekigo.tkg_logging.logging_banner(title)
tekigo.tkg_logging.logging_field(name, field)
tekigo.tkg_logging.logging_mesh(name, nnode, ncell, h_min)
tekigo.tkg_logging.logging_pyhip(hausdorff_distance, frozen_patch_list, max_spacing_gradient, periodic_adaptation)

log PyHIP parameters

tekigo.tkg_logging.logging_start(out_dir)

tekigo.tools module

module with tools for tekigo

class tekigo.tools.GatherScatter(connectivity, operation_type='smooth')

Bases: object

Internal Class to hold the sparse gather matrix and do the sparse gather scatter Efficient implementation of unstructured mesh operations

Originally created Feb 8th, 2018 by C. Lapeyre (lapeyre@cerfacs.fr)

Parameters
  • connectivity – connectivity of the tetrahedral mesh (param ‘tet->node’ in .h5 mesh)

  • operation_type (string) – [optional] either smooth or morph (morphing operations)

close(field, passes=1)

Close a field using standard gather/scatter

The LOCAL MAXIMUM is propagated, then the LOCAL MINIMUM. Features at the resolution limit are strengthened.

Parameters
  • field (array) – field compatible with mesh loaded

  • passes (int) – nb. of application of the operation

Returns

adjusted field

Return type

out_field (array)

dilate(field, passes=1)

Dilate a field using standard gather/scatter

The LOCAL MAXIMUM is propagated

Parameters
  • field (array) – field compatible with mesh loaded

  • passes (int) – nb. of application of the operation

Returns

adjusted field

Return type

out_field (array)

erode(field, passes=1)

Erode a field using standard gather/scatter

The LOCAL MINIUM is propagated

Parameters
  • field (array) – field compatible with mesh loaded

  • passes (int) – nb. of application of the operation

Returns

adjusted field

Return type

out_field (array)

open(field, passes=1)

Open a field using standard gather/scatter

The LOCAL MINIMUM is propagated, then the LOCAL MAXIMUM. Features ar the resolution limit are cleaned out.

Parameters
  • field (array) – field compatible with mesh loaded

  • passes (int) – nb. of application of the operation

Returns

adjusted field

Return type

out_field (array)

smooth(field, passes=1)

Smooth a field using standard gather/scatter.

The LOCAL AVERAGE is propagated

Parameters
  • field (array) – field compatible with mesh loaded

  • passes (int) – nb. of application of the operation

Returns

adjusted field

Return type

out_field (array)

tekigo.tools.approx_edge_from_vol_node(vol_node)

Function to approximate edge size from volume at node

\[e = (\frac{V_{node}}{4.5} \frac{12}{\sqrt(2)})^{1/3}\]
Parameters

vol_node – node volume to be computed into an edge size equivalent

Returns

edge size

tekigo.tools.approx_vol_cell_from_vol_node(vol_node, ratio=4.5)

Function to approximate cell volume from volume at node

Prefer to use the actual cell/node ratio of your initial mesh

Arg:

vol_node (array): shape(nnode), typical node volume at nodes locations ratio: typical cell/nnode

Returns

shape(nnode), typical cell volume at nodes locations

Return type

vol_cell (array)

tekigo.tools.approx_vol_node_from_edge(edge)

Function to approximate volume at node from edge size

\[V_{node} = (e^3 \frac{\sqrt(2)}{12}) * 4.5\]
Parameters

edge – edge size to be computed into a node volume equivalent

Returns

node volume

tekigo.tools.approx_vol_node_from_vol_cell(vol_cell, ratio=4.5)

Function to approximate volume at node from cell volume

Prefer to use the actual cell/node ratio of your initial mesh

Arg:

vol_cell (array): shape(nnode), typical cell volume at nodes locations ratio: typical cell/nnode

Returns

shape(nnode), typical node volume at nodes locations

Return type

vol_node (array)

tekigo.tools.auto_hist(values, bins=10, title='title', xlabel='value')

Automatic histogram of a numpy array for tekigo.

Note that the function filter_outlier() would strip this field of values lower than -3std and higher than +3std

tekigo.tools.filter_outliers(data, n=3.0)

Remove outliers using stantard deviation

Remove outlier data defined as N (defaiut 3) times the distance of the standard deviation with reference to the average value. Not suited to all fields at all!!!

..warning:

standard deviation is well defined for a gaussian distribution, still stand for a unimodeal distribution but is garbage for more comple distribution. Foe example, a temperature fiel is combustion is a bimodal distribution (hot gases and cold gases) Its standard deviation is not relevant. Same for HR, etc, etc.

Parameters

values (array) – shape (n), values, gaussian-like, or unimodal distibution

tekigo.tools.normalize_metric(values, expnt=10.0, floor=0.3)

A typical normalization function

This normalization occur in many adaptation recipes, but it is not universal. Read carefully what its does, in some cases this could be totally stupid to, use.

Parameters
  • values (array) – shape (n), any value.

  • expnt (float) – >0 exponent applied on the normalized values

  • floor (float) – [0-1[ floor of the final data.

Returns

the normalized metric

Return type

metric (array)