File size: 6,738 Bytes
4f9c6ae
62b5731
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4f9c6ae
 
 
d0685cf
 
 
5243431
d0685cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c12466d
d0685cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c00c9d
d0685cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2c00c9d
d0685cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c12466d
d0685cf
 
 
 
 
 
3a87703
 
 
 
 
bb4255d
d0685cf
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
---
tags:
- chain-of-thought
- cot-reasoning
- step-by-step-reasoning
- systematic-analysis
- problem-decomposition
- structured-output
- structured-thinking
- reasoning-model
- gmsh-scripting
- mesh-generation
- computational-geometry
- finite-element-analysis
- engineering-simulation
- cad-mesh-automation
- geometric-modeling
- numerical-methods
- engineering-research
- computational-engineering
- mesh-optimization
- geometry-processing
- simulation-preprocessing
- technical-code-generation
- domain-specific-reasoning
- engineering-assistant
- 8b-parameters
- dense-decoder-model
- open-source-model
- GMeshNet-OSS-8B
- GMeshNet-OSS
- GMeshNet
license: apache-2.0
language:
- en
---
# GMeshNet-OSS-8B

GMeshNet-OSS-8B is an open-source, dense, decoder-only 8B parameter large language model optimized for **chain-of-thought reasoning**, designed to produce structured analyses and generate robust **Gmsh meshing scripts**. 

---


## Quickstart

### Install Dependencies
```
pip install -U torch transformers accelerate
```

### Run Inference

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

# Input your prompt here
USER_INPUT = """
Generate a GMSH script to create a 2D rectangular mesh with a circular hole at the center, applying finer mesh refinement near the hole and coarser mesh at the boundaries.
"""

def load_model(model_path):
    model = AutoModelForCausalLM.from_pretrained(
        model_path,
        torch_dtype=torch.float16,
        device_map="auto",
        trust_remote_code=True
    )
    
    tokenizer = AutoTokenizer.from_pretrained(
        model_path,
        trust_remote_code=True
    )
    
    with open(f"{model_path}/chat_template.jinja", "r") as f:
        tokenizer.chat_template = f.read()
    
    return model, tokenizer

def generate_response(model, tokenizer, user_input):

    formatted_input = f"<gmsh_instruction>{user_input.strip()}</gmsh_instruction>"
    messages = [{"role": "user", "content": formatted_input}]
    
    prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
    inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
    
    outputs = model.generate(
        **inputs,
        max_new_tokens=2000,
        temperature=0.7,
        do_sample=True,
        pad_token_id=tokenizer.eos_token_id
    )
    
    response = tokenizer.decode(outputs[0], skip_special_tokens=False)
    return response.split("<|im_start|>assistant\n")[-1].replace("<|im_end|>", "").strip()

def run_inference():
    model_path = "./" # Path to your model weights
    
    model, tokenizer = load_model(model_path)
    result = generate_response(model, tokenizer, USER_INPUT)
    
    print(result)

if __name__ == "__main__":
    run_inference()
```

---

## Example Output

~~~
<think>
I need to analyze this meshing task step by step to create an effective GMSH script.

1. Geometry Requirements:
   - Main domain: Rectangular plate (let's assume 10x10 units)
   - Internal feature: Circular hole at center (radius 1 unit)
   - Mesh requirements: Finer elements near hole, coarser elements at boundaries

2. Meshing Approach:
   - Unstructured triangular mesh for flexibility around complex features
   - Size field to control element gradation from fine near hole to coarse at boundaries
   - Boundary layer not strictly necessary but could be added if flow simulation is intended

3. Construction Steps:
   - Define rectangle points (4 corners)
   - Define circle points (center + 4 quadrant points)
   - Create line loops for both shapes
   - Create surface with hole using Plane Surface command
   - Set up size field for gradation control
   - Generate mesh
</think>
<response>
1. High-level overview:
   - Create 10x10 rectangular domain centered at origin
   - Add circular hole of radius 1 at center
   - Use distance-based size field to refine mesh near hole
   - Generate unstructured triangular mesh with smooth gradation

2. Step-by-step instructions:
   a) Create rectangle points (4 corners)
   b) Create circle points (center + 4 quadrants)
   c) Connect points with lines/arcs
   d) Form line loops
   e) Create surface with hole
   f) Set up size field
   g) Generate mesh

3. Complete GMSH script:

```
// Rectangle with circular hole - graded mesh example

// Geometry parameters
rect_size = 5;  // Half-width/height of rectangle
hole_radius = 1; // Radius of central hole

// Points for rectangle
Point(1) = {-rect_size, -rect_size, 0};
Point(2) = {rect_size, -rect_size, 0};
Point(3) = {rect_size, rect_size, 0};
Point(4) = {-rect_size, rect_size, 0};

// Points for circle (center + 4 quadrants)
Point(5) = {0, 0, 0}; // Center
Point(6) = {hole_radius, 0, 0};
Point(7) = {0, hole_radius, 0};
Point(8) = {-hole_radius, 0, 0};
Point(9) = {0, -hole_radius, 0};

// Lines for rectangle
Line(1) = {1, 2};
Line(2) = {2, 3};
Line(3) = {3, 4};
Line(4) = {4, 1};

// Circle arcs
Circle(5) = {6, 5, 7};
Circle(6) = {7, 5, 8};
Circle(7) = {8, 5, 9};
Circle(8) = {9, 5, 6};

// Line loops
Line Loop(1) = {1, 2, 3, 4}; // Outer rectangle
Line Loop(2) = {5, 6, 7, 8}; // Inner circle

// Surface with hole
Plane Surface(1) = {1, 2};

// Mesh size control - fine near hole, coarse at boundaries
Field[1] = Distance;
Field[1].NodesList = {5}; // Measure distance from center point
Field[1].NNodesByEdge = 100;

Field[2] = Threshold;
Field[2].InField = 1;
Field[2].SizeMin = 0.05; // Fine mesh near hole
Field[2].SizeMax = 0.5;  // Coarse mesh far away
Field[2].DistMin = hole_radius;
Field[2].DistMax = 2*hole_radius;

Background Field = 2;

// Physical groups for boundaries
Physical Curve("OuterBoundary", 1) = {1, 2, 3, 4};
Physical Curve("InnerBoundary", 2) = {5, 6, 7, 8};
Physical Surface("Domain", 1) = {1};

// Mesh settings
Mesh.Algorithm = 6; // Frontal-Delaunay
Mesh.Smoothing = 5;
Mesh.CharacteristicLengthExtendFromBoundary = 1;

// Generate 2D mesh
Mesh 2;
```

4. Implementation Notes:
   - To run: Open in GMSH → Mesh → 2D
   - Adjust parameters as needed:
     * rect_size: Change rectangle dimensions
     * hole_radius: Modify hole size
     * SizeMin/SizeMax: Control mesh density
     * DistMin/DistMax: Control refinement region extent
   - For structured mesh option, add Transfinite lines/surface commands
   - Visualize geometry first (Geometry tab) before meshing
   - Common errors to avoid:
     * Missing line loops
     * Incorrect point references in curves
     * Overlapping or intersecting geometries
</response>
~~~

---

## Citation

```bibtex
@software{Callimesh_GMeshNet-OSS-8B_v1.0,
  author = {{Callimesh}},
  title = {GMeshNet-OSS-8B},
  version = {1.0.0},
  url = {https://huggingface.co/Callimesh/GMeshNet-OSS-8B},
  doi = {10.57967/hf/6325} 
}
```