38 lines
1.4 KiB
GLSL
38 lines
1.4 KiB
GLSL
SetFactory("OpenCASCADE");
|
|
|
|
// Define parameters - these can be overridden from the command line
|
|
// using the -setnumber flag, e.g., gmsh sphere.geo -setnumber Parameters/Order 2
|
|
DefineConstant[
|
|
radius = {1.0, Name "Parameters/Radius"},
|
|
coreRes = {0.01, Name "Parameters/CoreRes"},
|
|
outerRes = {0.1, Name "Parameters/OuterRes"},
|
|
kVal = {2.0, Name "Parameters/K"},
|
|
order = {2, Name "Parameters/Order"} // Mesh element order
|
|
];
|
|
|
|
// Define Geometry
|
|
Sphere(1) = {0, 0, 0, radius};
|
|
|
|
Physical Volume("sphere_volume", 1) = {1}; // Tag the volume
|
|
|
|
// Define variable mesh size using a MathEval Field
|
|
// Field Formula: a + (b-a) * (1 - Exp(-k*r))
|
|
// Need to handle r=0 case for Sqrt and Exp
|
|
Field[1] = MathEval;
|
|
Field[1].F = Sprintf("%.15g + (%.15g - %.15g) * (1 - Exp(-%.15g * Max(Sqrt(x*x+y*y+z*z), 1e-9)))", coreRes, outerRes, coreRes, kVal);
|
|
|
|
// Use this field as the background mesh size field
|
|
Background Field = 1;
|
|
|
|
// Set Mesh Options
|
|
Mesh.ElementOrder = order; // Set the mesh order (1=linear, 2=quadratic, etc.)
|
|
|
|
// Optional: Optimize high-order elements for better quality
|
|
// Mesh.HighOrderOptimize = 1;
|
|
|
|
// Optional: Choose 3D meshing algorithm if default isn't good (e.g., 1=MeshAdapt, 4=Frontal, 5=Delaunay, 6=Frontal-Delaunay, 7=MMG3D)
|
|
// Mesh.Algorithm3D = 7;
|
|
|
|
// Define Physical Groups (optional but good practice)
|
|
// Physical Volume("sphere_volume", 1) = {1}; // Tag the volume
|
|
// Physical Surface("sphere_surface", 2) = {1}; // Tag the boundary surface |