Triangulation¶
The top-level entry point for building a triangular mesh on a 2D domain.
triangulate¶
admesh.triangulate ¶
triangulate(domain: Domain | str | 'os.PathLike[str]', *, h_max: float | None = None, h_min: float | None = None, size_field: Callable[[ndarray], ndarray] | None = None, user_contribs: tuple[Callable[[ndarray], ndarray], ...] = (), combine: Callable[[list[ndarray]], ndarray] = np.minimum.reduce, background: str = 'uniform', seed: int | None = None, max_iter: int | None = None, initial_points: 'np.ndarray | None' = None, quality_gate: tuple[float, float] = (0.3, 0.6), ttol: float | None = None, dptol: float | None = None, medial_method: str | None = None) -> Mesh
Generate a triangular mesh on domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain
|
Domain, str, or os.PathLike
|
Domain object, file path (TOML/JSON/fort.14), or mesh_id string (from ADMESH-Domains registry if installed). |
required |
h_max
|
float or None
|
Target maximum edge length. If None, defaults to bbox_diagonal / 20. |
None
|
h_min
|
float or None
|
Minimum edge length for size field composition. |
None
|
size_field
|
callable or None
|
Pre-composed size field function. |
None
|
user_contribs
|
tuple of callables
|
User-defined size field contributions. |
()
|
combine
|
callable
|
Function to combine multiple size fields (default: np.minimum.reduce). |
reduce
|
background
|
str
|
Background grid strategy: 'uniform' (default) or 'octree' (adaptive octree-backed size field from spec-029). |
'uniform'
|
seed
|
int or None
|
Random seed for reproducibility. |
None
|
max_iter
|
int or None
|
Maximum iterations for mesh generation. |
None
|
quality_gate
|
tuple[float, float]
|
Advisory (min_q, mean_q) smoke thresholds. Default: (0.30, 0.60) — an MVP port-sanity floor, NOT a binding quality invariant (#140). Quality is driven by h_min/h_max/g; pass (0.0, 0.0) to disable the gate when knobs lower min quality. |
(0.3, 0.6)
|
ttol
|
float or None
|
Relative displacement threshold for Delaunay rebuild. Default: 0.27. |
None
|
dptol
|
float or None
|
Interior node movement tolerance for convergence. Default: 2e-3. |
None
|
medial_method
|
(None, 'grid', 'octree', 'vdt')
|
Optional channel-width size contribution, added to the other
contributions and combined through |
None
|
Returns:
| Type | Description |
|---|---|
Mesh
|
Triangulated mesh with quality metrics and boundaries. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If domain source cannot be resolved, quality gates fail, or
|
ImportError
|
If registry lookup is attempted without valence-domains installed. |
Adapts the v1 :class:`Domain` onto the faithful-port driver
|
|
:func:`admesh.routine.triangulate` without modifying it (Constitution
|
|
Principle I). Returns a :class:`Mesh` with per-element quality
|
|
populated and boundaries derived from the triangulation.
|
|
Source code in src/admesh/api.py
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 | |
triangulate_batch¶
Run triangulate over many domains on a process pool. Results come back in
input order and match a serial loop.
admesh.triangulate_batch ¶
Triangulate multiple domains on a process pool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domains
|
sequence
|
Sequence of Domain objects, file paths, or registry slugs — anything
:func: |
required |
n_jobs
|
int or None
|
Maximum number of worker processes. If None, defaults to
|
None
|
**kwargs
|
Keyword arguments forwarded unchanged to every :func: |
{}
|
Returns:
| Type | Description |
|---|---|
list of Mesh
|
Meshes in input order. Results from sequential in-process execution (n_jobs=1) are numerically identical to pool results; the pool is an execution detail only. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If n_jobs is not None and < 1. |
TypeError
|
If any domain or kwargs are not picklable (raised before pool creation to avoid silent serialization failures in workers). Message includes the domain index (for domains) or 'kwargs'. |
Notes
When n_jobs=1 or len(domains) == 1, the function runs a
sequential loop without spawning a process pool. This avoids
pickling overhead and permits unpicklable domains such as those
with lambda SDF functions.
For parallel execution (n_jobs > 1), each domain is pickled before the pool is created. Domains with lambda or local-scope SDF functions will raise TypeError. Use registry slugs, file paths, or module-level SDF callables instead, or set n_jobs=1.
Source code in src/admesh/batch.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |