Skip to content

Instantly share code, notes, and snippets.

@XerxesZorgon
Created June 18, 2024 19:48
Show Gist options
  • Select an option

  • Save XerxesZorgon/ee8af85ae0c203997b5cddbf3574558b to your computer and use it in GitHub Desktop.

Select an option

Save XerxesZorgon/ee8af85ae0c203997b5cddbf3574558b to your computer and use it in GitHub Desktop.
Simple 2D Gmsh shock tube model
// Gmsh project created on Mon Jun 17, 2024
SetFactory("OpenCASCADE");
// Define points
L = 0.5; // Tube length
H = 0.05; // Tube width
N = 10; // Number of rectangles along length of the tube
Point(1) = {0, 0, 0, 1.0};
Point(2) = {L, 0, 0, 1.0};
Point(3) = {L, H, 0, 1.0};
Point(4) = {0, H, 0, 1.0};
// Connect points with lines to form the rectangle
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};
// Define the rectangle as a surface
Line Loop(5) = {1, 2, 3, 4};
Plane Surface(6) = {5};
// Define transfinite lines with a specific number of nodes
Transfinite Line {1,3} = N+1; // Adjust number for refinement in length of the tube
Transfinite Line {2,4} = 1; // Adjust number for refinement in the width of the tube
// Define transfinite surface using the specified lines
Transfinite Surface {6} = {1,2,3,4};
// Recombine the surface mesh into quadrilaterals
Recombine Surface {6};
// Set the mesh element size
Mesh.CharacteristicLengthMax = 0.1;
// Generate the 2D mesh
Mesh 2;
// Save the mesh to a file
Save "shock_tube.msh";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment