AMCAX Kernel
Geometry kernel for CAD/CAE/CAM
AMCAX Kernel 1.0.0.0
Loading...
Searching...
No Matches
Mesh Size Control Example

Overview

This tutorial provides detailed configuration methods for various local size fields in mesh generation to control the size of generated meshes.

Feature Description

  • Control mesh size by setting local size fields, such as adaptive calculation based on curvature or narrow regions, or manually specifying sizes for specific areas.
  • Supports multiple local size fields. The base class in JSON files is LocalSizeField, with member functions including: AutomaticField, MaxField, MinField, BallField, BoxField, CylinderField, DistanceField, ThresholdField, RestrictField.

Local Size Field Settings

  • Multiple local size fields can be configured, but only one background field can be set which controls the global mesh size.
  • DistanceField is typically used together with ThresholdField.
  • The program will assert and prevent any cyclic dependencies in size field configuration. Example: MinField calls RestrictField, RestrictField calls ThresholdField, ThresholdField calls MinField. MinField->RestrictField->ThresholdField->MinField

JSON Template Example

{
"MeshSize": [
{
"MaxSize": 5,
"MinSize": 0.5,
"GrowthRate": 1.4,
"MeshingDim": 2,
"SelectedEntities": []
}
],
"LocalSizeField": {
"BGField": 1,
"AutomaticField": {
"CurvatureFactor": 0.5,
"NarrowRegionResolution2D": 1.0,
"NarrowRegionResolution3D": 0.5,
"GrowthRate": 1.4,
"Tag": 1
},
"MinField": {
"SelectedFieldTags": [
4,
6,
7
],
"Tag": 2
},
"MaxField": {
"SelectedFieldTags": [
4,
6,
7
],
"Tag": 3
},
"BallField": [
{
"Center": [
11.0,
13.0,
15.5
],
"Radius": 20.0,
"InterLocSize": 1,
"OutLocSize": 5,
"Thickness": 10,
"Tag": 4
},
{
"Center": [
11.0,
13.0,
15.5
],
"Radius": 20.0,
"InterLocSize": 1,
"OutLocSize": 5,
"Thickness": 10,
"Tag": 5
}
],
"BoxField": [
{
"MinPoint": [
0.0,
0.0,
0.0
],
"MaxPoint": [
20.0,
20.0,
20.0
],
"InterLocSize": 1.0,
"OutLocSize": 5,
"Thickness": 10,
"Tag": 6
}
],
"CylinderField": [
{
"Center": [
0.0,
0.0,
0.0
],
"Axis": [
0.0,
0.0,
1.0
],
"Radius": 20.0,
"InterLocSize": 1,
"OutLocSize": 5,
"Thickness": 10,
"Tag": 7
}
],
"DistanceField": [
{
"SelectedVertexTags": [
0,
1,
2
],
"SelectedEdgeTags": [
69,
73
],
"SelectedFaceTags": [
20,
48
],
"SelectedSolidTags": [],
"Tag": 8
}
],
"ThresholdField": [
{
"MinDist": 5.0,
"MaxDist": 10.0,
"MaxSize": 5.0,
"MinSize": 1.0,
"SelectedFieldTag": 8,
"Tag": 9
}
],
"RestrictField": [
{
"IsBoundary": true,
"SelectedVertexTags": [
0,
1,
2
],
"SelectedEdgeTags": [
73
],
"SelectedFaceTags": [
20
],
"SelectedSolidTags": [],
"SelectedFieldTag": 8,
"Tag": 10
}
]
}
}
Class Key Required Value Range Default Description
LocalSizeField BGField Yes Integer [1, inf] 1 The Tag value of the local size field, used as the background size field
LocalSizeField AutomaticField No Automatically calculates global mesh size based on curvature and narrow regions
AutomaticField CurvatureFactor No [0, inf] 0.5 Determines if curvature-based sizing is enabled. Smaller values result in smaller sizes (denser mesh) in high-curvature regions
AutomaticField NarrowRegionResolution2D No [0, inf] 1 Determines if sizing is calculated based on 2D narrow regions (self-intersections). Value represents number of mesh layers in narrow regions - higher values mean denser mesh
AutomaticField NarrowRegionResolution3D No [0, inf] 1 Determines if sizing is calculated based on 3D narrow regions (between surfaces). Value represents number of mesh layers in narrow regions - higher values mean denser mesh
AutomaticField GrowthRate Yes [1, inf] 1.4 Allowed growth rate between adjacent size transitions
AutomaticField Tag Yes Integer [1, inf] 1 Current size field's Tag (must not duplicate other Tags)
LocalSizeField MinField No Integer [1, inf] Takes the minimum size from all input size fields
MinField SelectedFieldTags Yes [1, 2, 3...] - Input the Tags of size fields to take minimum size from (must exist)
MinField Tag Yes Integer [1, inf] 1 Current size field's Tag
LocalSizeField MaxField No Takes the maximum size from all input size fields
MaxField SelectedFieldTags Yes [1, 2, 3...] - Input the Tags of size fields to take maximum size from (must exist)
MaxField Tag Yes Integer [1, inf] 1 Current size field's Tag
LocalSizeField BallField No Specifies size values within a defined sphere
BallField Center Yes Any 3D coordinates - Sphere center coordinates (three floating-point numbers)
BallField Radius Yes [0, inf] 0.0 Sphere radius
BallField InterLocSize Yes [0, inf] 0.0 Size value inside the sphere
BallField OutLocSize No [0, inf] 0.0 Size value outside the sphere
BallField Thickness No [0, inf] 0.0 Sphere boundary transition layer - size in this layer is interpolated between InterLocSize and OutLocSize. Setting Thickness requires OutLocSize
BallField Tag Yes Integer [1, inf] 1 Current size field's Tag
LocalSizeField BoxField No Specifies size values within a defined box (determined by min/max points)
BoxField MinPoint Yes Any 3D coordinates - Box minimum point
BoxField MaxPoint Yes Any 3D coordinates - Box maximum point
BoxField InterLocSize Yes [0, inf] 0.0 Size value inside the box
BoxField OutLocSize No [0, inf] 0.0 Size value outside the box
BoxField Thickness No [0, inf] 0.0 Box boundary transition layer (similar to BallField). Setting Thickness requires OutLocSize
BoxField Tag Yes Integer [1, inf] 1 Current size field's Tag
LocalSizeField CylinderField No Specifies size values within a defined cylinder
CylinderField Center Yes Any 3D coordinates - Cylinder center coordinates (three floating-point numbers)
CylinderField Axis Yes Any 3D non-zero vector - Cylinder axis (three floating-point numbers)
CylinderField Radius Yes [0, inf] 0.0 Cylinder radius
CylinderField InterLocSize Yes [0, inf] 0.0 Size value inside the cylinder
CylinderField OutLocSize No [0, inf] 0.0 Size value outside the cylinder
CylinderField Thickness No [0, inf] 0.0 Cylinder boundary transition layer (similar to BallField). Setting Thickness requires OutLocSize
CylinderField Tag Yes Integer [1, inf] 1 Current size field's Tag
LocalSizeField DistanceField No Uses distance to input geometry (points, edges, faces, solids) as size, typically used with ThresholdField
DistanceField SelectedVertexTags No [1, 2, 3...] - Input point Tags
DistanceField SelectedEdgeTags No [1, 2, 3...] - Input edge Tags
DistanceField SelectedFaceTags No [1, 2, 3...] - Input face Tags
DistanceField SelectedSolidTags No [1, 2, 3...] - Input solid Tags
DistanceField Tag Yes Integer [1, inf] 1 Current size field's Tag
LocalSizeField ThresholdField No Interpolates new sizes between MinDist and MaxDist based on input field's calculated sizes
ThresholdField MinDist Yes [0, inf] 0.0 Minimum size threshold
ThresholdField MaxDist Yes [0, inf] 0.0 Maximum size threshold
ThresholdField MaxSize Yes [0, inf] 0.0 Returns MaxSize if input field's calculated size exceeds MinDist
ThresholdField MinSize Yes [0, inf] 0.0 Returns MinSize if input field's calculated size is less than MinDist
ThresholdField SelectedFieldTag Yes Integer [1, inf] 1 Input size field Tag (typically DistanceField)
ThresholdField Tag Yes Integer [1, inf] 1 Current size field's Tag
LocalSizeField RestrictField No Only calculates sizes on input geometry (points, edges, faces, solids) using the input size field
RestrictField IsBoundary No [true, false] true Whether to calculate sizes on the boundary of input geometry
RestrictField SelectedVertexTags No [1, 2, 3...] - Input point Tags
RestrictField SelectedEdgeTags No [1, 2, 3...] - Input edge Tags
RestrictField SelectedFaceTags No [1, 2, 3...] - Input face Tags
RestrictField SelectedSolidTags No [1, 2, 3...] - Input solid Tags
RestrictField SelectedFieldTag Yes Integer [1, inf] 1 Input size field Tag
RestrictField Tag Yes Integer [1, inf] 1 Current size field's Tag

Function Description

The JSON file above provides the configuration methods for each size field. In practical use, you can set the corresponding size field according to your needs or change the value of BGField in the JSON file to use different size fields. Next, we will set different values for BGField in the JSON file to use different size fields.

AutomaticField: Automatically calculates global size based on curvature and narrow regions

Set "BGField": 1. In this case, BGField is the Tag parameter of AutomaticField, so AutomaticField will be used.

"AutomaticField": {
"CurvatureFactor": 0.5,
"NarrowRegionResolution2D": 1.0,
"NarrowRegionResolution3D": 0.5,
"GrowthRate": 1.4,
"Tag": 1
}

If coupling with other size fields is needed, set MinField or MaxField as the background field. Input the Tag of AutomaticField and other size fields to be coupled into MinField or MaxField.
The result is as follows:

MinField: Takes the minimum size from all input size fields

Set "BGField": 2. In this case, BGField is the Tag parameter of MinField, so MinField will be used.

"MinField": {
"SelectedFieldTags": [
4,
6,
7
],
"Tag": 2
}

For any point, the size is calculated from all input fields, and the minimum size is returned.The result is as follows:

MaxField: Takes the maximum size from all input size fields

Set "BGField": 3. In this case, BGField is the Tag parameter of MaxField, so MaxField will be used.

"MaxField": {
"SelectedFieldTags": [
4,
6,
7
],
"Tag": 3
}

For any point, the size is calculated from all input fields, and the maximum size is returned. The result is as follows:

BallField: Specifies the mesh size inside a sphere

Set "BGField": 4. In this case, BGField is the Tag parameter of BallField, so BallField will be used.

"BallField": [
{
"Center": [
11.0,
13.0,
15.5
],
"Radius": 20.0,
"InterLocSize": 1,
"OutLocSize": 5,
"Thickness": 10,
"Tag": 4
}
]

Thickness and OutLocSize are optional.The result is as follows:

BoxField: Specifies the mesh size inside a box

Set "BGField": 6. In this case, BGField is the Tag parameter of BoxField, so BoxField will be used.

"BoxField": [
{
"MinPoint": [
0.0,
0.0,
0.0
],
"MaxPoint": [
20.0,
20.0,
20.0
],
"InterLocSize": 1.0,
"OutLocSize": 5,
"Thickness": 10,
"Tag": 6
}
]

Thickness and OutLocSize are optional.

The result is as follows:

CylinderField: Specifies the mesh size inside a cylinder

Set "BGField": 7. In this case, BGField is the Tag parameter of CylinderField, so CylinderField will be used.

"CylinderField": [
{
"Center": [
0.0,
0.0,
0.0
],
"Axis": [
0.0,
0.0,
1.0
],
"Radius": 20.0,
"InterLocSize": 1,
"OutLocSize": 5,
"Thickness": 10,
"Tag": 7
}
]

Thickness and OutLocSize are optional.

The result is as follows:

DistanceField: Calculates the distance from any point on the model to the input geometry (points, edges, faces, or solids)

Set "BGField": 8. In this case, BGField is the Tag parameter of DistanceField, so DistanceField will be used.

"DistanceField": [
{
"SelectedVertexTags": [
0,
1,
2
],
"SelectedEdgeTags": [
69,
73
],
"SelectedFaceTags": [
20,
48
],
"SelectedSolidTags": [],
"Tag": 8
}
]

The distance is used as the mesh size. Therefore, when the distance is smaller than the global minsize, minsize is used. When the distance is larger than the global maxsize, maxsize is used. Some geometries can be omitted.

The result is as follows:

ThresholdField: Returns an appropriate size based on the distance or size value of the lookup point

Set "BGField": 9. In this case, BGField is the Tag parameter of ThresholdField, so ThresholdField will be used.

"ThresholdField": [
{
"MinDist": 5.0,
"MaxDist": 10.0,
"MaxSize": 5.0,
"MinSize": 1.0,
"SelectedFieldTag": 8,
"Tag": 9
}
]

This is typically used in combination with DistanceField (i.e., specifying DistanceField as the selected size field in ThresholdField).

If the distance or size value ls of the lookup point is < MinDist, MinSize (from the threshold field) is returned.

If the distance or size value ls of the lookup point is > MaxDist, MaxSize (from the threshold field) is returned.

If the distance or size value ls of the lookup point is between MinDist and MaxDist, a new size is interpolated based on MinSize and MaxSize.
The result is as follows:

RestrictField: Applies the input size field only on the input geometry (points, edges, faces, or solids)

Set "BGField": 10. In this case, BGField is the Tag parameter of RestrictField, so RestrictField will be used.

"RestrictField": [
{
"IsBoundary": true,
"SelectedVertexTags": [
0,
1,
2
],
"SelectedEdgeTags": [
73
],
"SelectedFaceTags": [
20
],
"SelectedSolidTags": [],
"SelectedFieldTag": 8,
"Tag": 10
}
]

The result is as follows:

Click here example03 to get the complete source code for the mesh size control example. Everyone can download it as needed.