Skip to content

Commit a4b4299

Browse files
authored
Merge pull request #146 from boutproject/gridue_converter
Added the working gridue to bout converter.
2 parents 11f5d0a + 7853c91 commit a4b4299

2 files changed

Lines changed: 1036 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
This script was modified from B. Dudson's original gridue_to_bout.py script. It creates a BOUT grid file from a GRIDUE file.
2+
3+
It can be ran from the terminal.
4+
5+
To run it directly after the creation of a gridue file on INGRID the following code needs to be added to ingrid.py:
6+
7+
```python
8+
def ExportBOUTgrid(self, gridue_file, bout_grid_name: str = 'bout_from_in.grd.nc', plotting = True, verbose = True, ignore_checks = False):
9+
"""
10+
Export a BOUT grid file for the created grid.
11+
12+
Parameters
13+
----------
14+
gridue_file : str, mandatory
15+
Name of gridue file to convert to BOUT grid.
16+
17+
bout_grid_name : str, optional
18+
Name of BOUT grid file to save.
19+
20+
plotting : bool, optional
21+
If True, plot the gridue file before conversion.
22+
23+
verbose : bool, optional
24+
If True, print verbose output during conversion.
25+
26+
ignore_checks : bool, optional
27+
If True, ignore checks for gridue file format and structure.
28+
29+
"""
30+
bout_grid_name = gridue_file + "_" + bout_grid_name
31+
Convert_grids(gridue_file,bout_grid_name,plotting, verbose, ignore_checks)
32+
33+
```
34+
35+
And modifying the `ExportGridue` function to:
36+
37+
```python
38+
if type(self.CurrentTopology) in [SNL]:
39+
if self.WriteGridueSNL(self.CurrentTopology.gridue_settings, fname):
40+
print(f"# Successfully saved gridue file as '{fname}'")
41+
self.ExportBOUTgrid(fname, 'bout_from_in.grd.nc', plotting = True, verbose = True, ignore_checks = False)
42+
elif type(self.CurrentTopology) in [SF15, SF45, SF75, SF105, SF135, SF165, UDN, CDN]:
43+
if self.WriteGridueDNL(self.CurrentTopology.gridue_settings, fname):
44+
print(f"# Successfully saved gridue file as '{fname}'")
45+
self.ExportBOUTgrid(fname, 'bout_from_in.grd.nc', plotting = True, verbose = True, ignore_checks = False)
46+
```
47+
48+
*Note:* The created file will have
49+
`dimensions:
50+
x ;
51+
y ;
52+
z ;
53+
x2 ;
54+
y2 ;
55+
t = UNLIMITED ; //`
56+
57+
Where x has guard cells following INGRID's convention, and y doesn't have any. The converter takes the BOUT coordinates to be x -> y2 (and removes the guard cells) and y -> x2 (and adds the guard cells). So BOUT ends up using x2 as X and y2 as Y coordinates.

0 commit comments

Comments
 (0)