-
Notifications
You must be signed in to change notification settings - Fork 28
Fci: Add 3D MMS tests and fix neutral averaging #537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
totork
wants to merge
25
commits into
boutproject:fci
Choose a base branch
from
totork:fci-metric-mms
base: fci
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
6684f2e
Added first step of 3D MMS test
totork aefa708
More work on 2D axial MMS test
totork c6ee9f7
Update MMS notebook
totork 0fd8fcd
Add zoidberg to CI
totork 2e6be54
Try fix indent in CI
totork 61771f0
CI formatting
totork 34a2e92
Add zoidberg to CI
totork 721642a
CI formatting
totork d04e9b7
Add script to generate grids
totork 3429ada
Create grids in CMake
totork 70d47a3
Fix grid generation
totork bf9fbf6
Use actual grid in grid generation
totork cfaed9d
First commit of 3D conduction test
totork 0725963
Merge pull request #19 from totork/fci-metric-sheathtest
totork ea43b25
Add 3D test to CMake file
totork d9b8990
Adjust 3D Test to use pressure and proper normalization
totork b4e3aef
Add proper heat conduction to test
totork 36ebb4d
Corret mass in MMS test
totork 57b8c29
Fix amjuel reaction averaging that cause slow down
totork 2bc38b2
Merge pull request #23 from totork/fci-metric-fix-neutrals
totork 6449816
Delete more averaging
totork 0db3901
Merge pull request #25 from totork/fci-metric-fix-neutrals
totork 5febca3
Update .github/workflows/tests.yml
totork 807abb3
Merge branch 'fci-metric' into fci-metric-mms
totork af80f9c
Fix CI
totork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import zoidberg | ||
| from zoidberg.field import Slab | ||
| import numpy as np | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| class Axial_circular(Slab): | ||
| def __init__(self,rho_1,rho_2,Lz,By,R0, q0 = 3.0, q1 = 0.2): | ||
| self.rho_1 = float(rho_1) | ||
| self.rho_2 = float(rho_2) | ||
| self.Lz = float(Lz) | ||
| self.By = float(By) | ||
| self.R0 = R0 | ||
|
|
||
| def qprofile(self,x,z,phi): | ||
| theta=np.arctan2(z,x-self.R0) | ||
| r = np.sqrt(np.power(x-self.R0,2)+np.power(z,2)) | ||
| return q0 + q1 * r | ||
|
|
||
| def Bxfunc(self,x,z,phi): | ||
| theta=np.arctan2(z,x-self.R0) | ||
| r = np.sqrt(np.power(x-self.R0,2)+np.power(z,2)) | ||
| q = self.qprofile(x,z,phi) | ||
| return -r * np.sin(theta) / q | ||
|
|
||
| def Bzfunc(self,x,z,phi): | ||
| theta=np.arctan2(z,x-self.R0) | ||
| r = np.sqrt(np.power(x-self.R0,2)+np.power(z,2)) | ||
| q = self.qprofile(x,z,phi) | ||
| return r * np.cos(theta) / q | ||
|
|
||
| def Byfunc(self,x,z,phi): | ||
| return np.full(x.shape,self.By) | ||
|
|
||
|
|
||
|
|
||
|
|
||
| R0 = 1.5 | ||
| rho_1 = 0.4 | ||
| rho_2 = 0.6 | ||
| B0 = 1.0 | ||
| Ly = 2.0 * np.pi | ||
| q0 = 3.0 | ||
| q1 = 0.0 | ||
| field = Axial_circular(rho_1, rho_2, Ly, B0,R0, q0=q0, q1=q1) | ||
|
|
||
| folder = "mms_axial_circular_fci/" | ||
|
|
||
| if not os.path.exists(folder): | ||
| os.mkdir(folder) | ||
|
|
||
| force = "-f" in sys.argv or "--force" in sys.argv | ||
|
|
||
|
|
||
|
|
||
| for scale in [1,2]: | ||
| nx = scale * 16 | ||
| nz = scale * 64 | ||
| ny = scale * 8 | ||
|
|
||
| filename = f"Axial_circular_q_{nx}_{nz}_{rho_1}_{rho_2}_{q0}_{q1}.fci.grid.nc" | ||
| fn = folder + filename | ||
|
|
||
| if os.path.exists(fn) and not force: | ||
| print(fn, " exists") | ||
| continue | ||
|
|
||
|
|
||
| inner = zoidberg.rzline.shaped_line(R0=R0,a=rho_1,n=nz) | ||
| outer = zoidberg.rzline.shaped_line(R0=R0,a=rho_2,n=nz) | ||
|
|
||
| pol_grid = zoidberg.poloidal_grid.grid_annulus(inner,outer,nx+4,nz) | ||
| pol_grids = [] | ||
| for i in range(ny): | ||
| pol_grids.append(pol_grid) | ||
|
|
||
| grid = zoidberg.grid.Grid(pol_grids, np.linspace(0.0, 2.0 * np.pi, ny, endpoint=False),Ly,yperiodic=True) | ||
| maps = zoidberg.zoidberg.make_maps(grid, field) | ||
|
|
||
| maps["forward_xt_prime"][2,:,:] = 2.0 | ||
| maps["backward_xt_prime"][2,:,:] = 2.0 | ||
|
|
||
| maps["forward_xt_prime"][-3,:,:] = float(nx+4-3) | ||
| maps["backward_xt_prime"][-3,:,:] = float(nx+4-3) | ||
|
|
||
| with zoidberg.zoidberg.MapWriter(fn) as mw: | ||
| mw.add_grid_field(grid, field) | ||
| mw.add_maps(maps) | ||
| mw.add_dagp() | ||
|
|
||
| print(fn, " done") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| (* ::Package:: *) | ||
|
|
||
| BeginPackage["axial`"] | ||
|
|
||
| (* To run the package, execute the following line in a notebook | ||
| <<axial.m | ||
| *) | ||
|
|
||
| (* | ||
| "Provides MMS solution and source for the anisotropic diffusion model in circular geometry | ||
| - Only Dirichlet boundary conditions in the perpendicular direction is considered | ||
| - Parallel boundaries (Penalisation) are not taken into account | ||
| - MMS solution is firstly is prescribed in cylindrical coordinates | ||
| (r,p,z) and afterwards a transformed to Cartesian coordinates (x,y,phi) used in GRILLIX | ||
| r = sqrt(x^2+y^2); p = arctan(y/x); z = phi, t = time | ||
| - Paramters of model are: chi_par, chi_perp, safety factor q, and limiting flux surfaces rmin and rmax" | ||
| *) | ||
|
|
||
|
|
||
| Print["Computing MMS Terms"]; | ||
|
|
||
| (* | ||
| define x,y and parallel derivatives in terms of r,p,z derivative \ | ||
| and normalised radial coordinate rn | ||
| *) | ||
| absb[x_] = Sqrt[1 + x^2/q[x]^2]; | ||
| pgrad[f_, x_, z_, y_, t_] = (D[f[x,z,y,t],y] + 1/q[x]*D[f[x,z,y,t],z])/absb[x]; | ||
| ddx[f_, r_, p_, z_, t_] = D[f[r, p, z, t], r]; | ||
| ddy[f_, r_, p_, z_, t_] = D[f[r, p, z, t], r]*Sin[p] + D[f[r, p, z, t], p]*Cos[p]/r; | ||
| d2dx2[f_, r_, p_, z_, t_] = D[ddx[f, r, p, z, t], r]; | ||
| d2dy2[f_, r_, p_, z_, t_] = D[ddy[f, r, p, z, t], r]*Sin[p] + D[ddy[f, r, p, z, t], p]*Cos[p]/r; | ||
|
|
||
|
|
||
| LaplacePerpMmsSol[f_,r_, p_, z_, t_] = d2dx2[f, r, p, z, t] + d2dy2[f, r, p, z, t]; | ||
|
|
||
| LaplacePerp[f_,r_,p_,z_,t_] = D[f[r,p,z,t],{r,2}] + D[f[r,p,z,t],r]/r + 1.0/(r*r)*D[f[r,p,z,t],{p,2}]; | ||
|
|
||
|
|
||
|
|
||
| xn[x_] = (x-xmin)/(xmax-xmin); | ||
|
|
||
| d2dpar2[f_, x_, z_, y_, t_] = (D[D[f[x, z, y, t], y], y] + 2/q[x]*D[D[f[x, z, y, t], y], z] + 1/q[x]^2*D[D[f[x, z, y, t], z], z])/absb[x]^2; | ||
|
|
||
|
|
||
|
|
||
| (* | ||
| Define normalised rho and MMS solution in terms of mode numbers \ | ||
| given above | ||
| *) | ||
| MmsDens[x_, z_, y_, t_] = amp*Sin[2.0*Pi*kx*xn[x]]*Sin[kz*z - phz]*Cos[ky*y- phy]+offset; | ||
| MmsUpar[x_, z_, y_, t_]=1; | ||
| rhos = 0.0002284697436697996 | ||
| Bnorm = 1.0 | ||
| qe = 1.60217663*^-19 | ||
| Me = 9.1093837*^-31 | ||
| e0 = 8.85418781*^-12 | ||
| Omegaci = qe * Bnorm / (1836.0*Me) | ||
|
|
||
|
|
||
| pflux[x_, z_, y_, t_]=MmsDens[x, z, y, t]; | ||
| (*Smms[x_, z_, y_, t_]=D[MmsDens[x,z,y,t],t]-d2dpar2[MmsDens,x,z,y,t]-Laplaceperpe[MmsDens,x,z,y,t];*) | ||
| Smms[x_, z_, y_, t_]=D[MmsDens[x,z,y,t],t]-Dperp/(rhos*rhos*Omegaci) * LaplacePerp[MmsDens,x,z,y,t] * (rhos*rhos)- | ||
| Dpar/(rhos*rhos*Omegaci)*d2dpar2[MmsDens,x,z,y,t]* (rhos*rhos); | ||
|
|
||
|
|
||
| Print["Finished MMS Terms"]; | ||
| Print[Omegaci] | ||
| (* Set a dummy return value *) | ||
| 1 | ||
|
|
||
|
|
||
| EndPackage[ ] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
so we get the next boutdata automatically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last time I used boutdata=0.4.0, I would get weird errors and the CI would fail all over the place. I am not sure if this is the case anymore.