Skip to content
Snippets Groups Projects
Commit 54342089 authored by Yngve Levinsen's avatar Yngve Levinsen
Browse files

started on bdsim converter

parent cfc9646f
No related branches found
No related tags found
No related merge requests found
...@@ -344,6 +344,21 @@ class LATTICE: ...@@ -344,6 +344,21 @@ class LATTICE:
except AttributeError: except AttributeError:
pass pass
def get_bdsim(self,output_folder='bdsim'):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
file_name=os.path.join(output_folder,'bdsim.dat')
if self.lst[-1].gamma==1.0: self.update_gamma() # Assign gamma, if not done yet
with open(file_name,'w') as fname:
for fmap in self.fmap:
fname.write(self.fmap[fmap].get_bdsim(os.path.join(output_folder,fmap))+'\n')
for lat_i in self.lst:
if hasattr(lat_i,'get_bdsim'):
fname.write(lat_i.get_bdsim()+'\n')
class PROJECT: class PROJECT:
''' '''
- This is for running multiple simulations 1-by-1 under 1 project. - This is for running multiple simulations 1-by-1 under 1 project.
......
...@@ -98,6 +98,7 @@ from __future__ import print_function ...@@ -98,6 +98,7 @@ from __future__ import print_function
from numpy import * from numpy import *
import sys import sys
import shutil
#---- Constants #---- Constants
...@@ -122,7 +123,15 @@ class FIELD_MAP_DATA: ...@@ -122,7 +123,15 @@ class FIELD_MAP_DATA:
# Instances # Instances
self.dL =float(lin[0].split()[1])/int(lin[0].split()[0]) self.dL =float(lin[0].split()[1])/int(lin[0].split()[0])
self.field=map(float,lin[2:]) self.field=array(lin[2:], dtype=float)
self.file_name = file_name
def get_bdsim(self,path):
# Only support 1D edz for now!
with open(path+'.txt', 'w') as fmapout:
for i in range(len(self.field)):
fmapout.write('{} {} {} {}\n'.format(self.dL*i, 0.0, 0.0, self.field[i]))
return '{0}: field, type="ebmap2d", integrator=g4classicalrk4, electricFile=bdsim1d:{0}.txt;'.format(self.file_name[:-4])
#---- Parent classes #---- Parent classes
...@@ -298,6 +307,9 @@ class FIELD_MAP(ELEM): ...@@ -298,6 +307,9 @@ class FIELD_MAP(ELEM):
lin+='0 0 0 0 0' lin+='0 0 0 0 0'
return lin return lin
def get_bdsim(self):
return 'element, geometryFile="gdml:{0}.gdml", fieldVacuum="{0}", l={1}'.format(self.name_fmap,self.L)
#---- Active elements #---- Active elements
...@@ -361,6 +373,10 @@ class DRIFT(ELEM): ...@@ -361,6 +373,10 @@ class DRIFT(ELEM):
return lin return lin
def get_bdsim(self):
return 'drift, l={}*mm, beampipeRadius={}*mm;'.format(self.L,self.apt)
class QUAD(ELEM): class QUAD(ELEM):
''' '''
- Tilt not supported. - Tilt not supported.
...@@ -433,6 +449,11 @@ class QUAD(ELEM): ...@@ -433,6 +449,11 @@ class QUAD(ELEM):
return lin return lin
def get_bdsim(self):
return 'quadrupole, l={}*mm, k1={}, beampipeRadius={}*mm;'.format(self.L, self.G/Brho(self.gamma), self.apt)
class THIN_STEERING(ELEM): class THIN_STEERING(ELEM):
''' '''
- Only magnetic steerer supported. - Only magnetic steerer supported.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment