From d4bb31b6b507f32384a58c5f2ffe4617bf15be02 Mon Sep 17 00:00:00 2001 From: Jonas Kellerer Date: Tue, 22 Nov 2022 18:09:24 +0100 Subject: [PATCH] Abstract, Intro, Implementation to karl code paper --- docs/paper/the-karl-code/elsarticle-num.bst | 1509 +++++++++++++++++++ docs/paper/the-karl-code/paper.tex | 594 ++++---- 2 files changed, 1845 insertions(+), 258 deletions(-) create mode 100755 docs/paper/the-karl-code/elsarticle-num.bst diff --git a/docs/paper/the-karl-code/elsarticle-num.bst b/docs/paper/the-karl-code/elsarticle-num.bst new file mode 100755 index 0000000..14499bf --- /dev/null +++ b/docs/paper/the-karl-code/elsarticle-num.bst @@ -0,0 +1,1509 @@ +%% +%% This is file `elsarticle-num.bst' (Version 2.1), +%% +%% Copyright 2007-2020 Elsevier Ltd +%% +%% This file is part of the 'Elsarticle Bundle'. +%% --------------------------------------------- +%% +%% It may be distributed under the conditions of the LaTeX Project Public +%% License, either version 1.2 of this license or (at your option) any +%% later version. The latest version of this license is in +%% http://www.latex-project.org/lppl.txt +%% and version 1.2 or later is part of all distributions of LaTeX +%% version 1999/12/01 or later. +%% +%% +%% $Id: elsarticle-num.bst 194 2020-11-23 11:29:27Z rishi $ +%% +%% $URL: https://lenova.river-valley.com/svn/elsarticle/trunk/elsarticle-num.bst $ +%% +%% ---------------------------------------- + +ENTRY + { address + author + booktitle + chapter + edition + editor + howpublished + institution + journal + key + month + note + number + organization + pages + publisher + school + series + title + type + volume + year + eprint % urlbst + doi % urlbst + url % urlbst + lastchecked % urlbst + } + {} + { label } + +INTEGERS { output.state before.all mid.sentence after.sentence after.block } + +STRINGS { urlintro eprinturl eprintprefix doiprefix doiurl openinlinelink closeinlinelink } % urlbst... +INTEGERS { hrefform inlinelinks makeinlinelink addeprints adddoiresolver } +FUNCTION {init.urlbst.variables} +{ + "Available from: " 'urlintro := % prefix before URL + "http://arxiv.org/abs/" 'eprinturl := % prefix to make URL from eprint ref + "arXiv:" 'eprintprefix := % text prefix printed before eprint ref + "https://doi.org/" 'doiurl := % prefix to make URL from DOI + "doi:" 'doiprefix := % text prefix printed before DOI ref + #1 'addeprints := % 0=no eprints; 1=include eprints + #1 'adddoiresolver := % 0=no DOI resolver; 1=include it + #2 'hrefform := % 0=no crossrefs; 1=hypertex xrefs; 2=hyperref refs + #1 'inlinelinks := % 0=URLs explicit; 1=URLs attached to titles + % the following are internal state variables, not config constants + #0 'makeinlinelink := % state variable managed by setup.inlinelink + "" 'openinlinelink := % ditto + "" 'closeinlinelink := % ditto +} +INTEGERS { + bracket.state + outside.brackets + open.brackets + within.brackets + close.brackets +} +FUNCTION {init.state.consts} +{ #0 'outside.brackets := % urlbst + #1 'open.brackets := + #2 'within.brackets := + #3 'close.brackets := + + #0 'before.all := + #1 'mid.sentence := + #2 'after.sentence := + #3 'after.block := +} + +STRINGS { s t } + +FUNCTION {output.nonnull.original} +{ 's := + output.state mid.sentence = + { ", " * write$ } + { output.state after.block = + { add.period$ write$ + newline$ + "\newblock " write$ + } + { output.state before.all = + 'write$ + { add.period$ " " * write$ } + if$ + } + if$ + mid.sentence 'output.state := + } + if$ + s +} + +FUNCTION {setup.inlinelink} +{ makeinlinelink + { hrefform #1 = % hypertex + { "\special {html: }{" * 'openinlinelink := + "\special {html:}" 'closeinlinelink := + } + { hrefform #2 = % hyperref + { "\href{" url * "}{" * 'openinlinelink := + "}" 'closeinlinelink := + } + 'skip$ + if$ % hrefform #2 = + } + if$ % hrefform #1 = + #0 'makeinlinelink := + } + 'skip$ + if$ % makeinlinelink +} +FUNCTION {add.inlinelink} +{ openinlinelink empty$ + 'skip$ + { openinlinelink swap$ * closeinlinelink * + "" 'openinlinelink := + } + if$ +} +FUNCTION {output.nonnull} +{ % Save the thing we've been asked to output + 's := + % If the bracket-state is close.brackets, then add a close-bracket to + % what is currently at the top of the stack, and set bracket.state + % to outside.brackets + bracket.state close.brackets = + { "]" * + outside.brackets 'bracket.state := + } + 'skip$ + if$ + bracket.state outside.brackets = + { % We're outside all brackets -- this is the normal situation. + % Write out what's currently at the top of the stack, using the + % original output.nonnull function. + s + add.inlinelink + output.nonnull.original % invoke the original output.nonnull + } + { % Still in brackets. Add open-bracket or (continuation) comma, add the + % new text (in s) to the top of the stack, and move to the close-brackets + % state, ready for next time (unless inbrackets resets it). If we come + % into this branch, then output.state is carefully undisturbed. + bracket.state open.brackets = + { " [" * } + { ", " * } % bracket.state will be within.brackets + if$ + s * + close.brackets 'bracket.state := + } + if$ +} + +FUNCTION {inbrackets} +{ bracket.state close.brackets = + { within.brackets 'bracket.state := } % reset the state: not open nor closed + { open.brackets 'bracket.state := } + if$ +} + +FUNCTION {format.lastchecked} +{ lastchecked empty$ + { "" } + { inbrackets "cited " lastchecked * } + if$ +} + +FUNCTION {output} +{ duplicate$ empty$ + 'pop$ + 'output.nonnull + if$ +} + +FUNCTION {output.check} +{ 't := + duplicate$ empty$ + { pop$ "empty " t * " in " * cite$ * warning$ } + 'output.nonnull + if$ +} + +FUNCTION {fin.entry.original} +{ add.period$ + write$ + newline$ +} + +FUNCTION {new.block} +{ output.state before.all = + 'skip$ + { after.block 'output.state := } + if$ +} + +FUNCTION {new.sentence} +{ output.state after.block = + 'skip$ + { output.state before.all = + 'skip$ + { after.sentence 'output.state := } + if$ + } + if$ +} + +FUNCTION {add.blank} +{ " " * before.all 'output.state := +} + +FUNCTION {date.block} +{ + add.blank +} + +FUNCTION {not} +{ { #0 } + { #1 } + if$ +} + +FUNCTION {and} +{ 'skip$ + { pop$ #0 } + if$ +} + +FUNCTION {or} +{ { pop$ #1 } + 'skip$ + if$ +} + +FUNCTION {new.block.checka} +{ empty$ + 'skip$ + 'new.block + if$ +} + +FUNCTION {new.block.checkb} +{ empty$ + swap$ empty$ + and + 'skip$ + 'new.block + if$ +} + +FUNCTION {new.sentence.checka} +{ empty$ + 'skip$ + 'new.sentence + if$ +} + +FUNCTION {new.sentence.checkb} +{ empty$ + swap$ empty$ + and + 'skip$ + 'new.sentence + if$ +} + +FUNCTION {field.or.null} +{ duplicate$ empty$ + { pop$ "" } + 'skip$ + if$ +} + +FUNCTION {emphasize} +{ skip$ } + +FUNCTION {capitalize} +{ "u" change.case$ "t" change.case$ } + +FUNCTION {space.word} +{ " " swap$ * " " * } + + % Here are the language-specific definitions for explicit words. + % Each function has a name bbl.xxx where xxx is the English word. + % The language selected here is ENGLISH +FUNCTION {bbl.and} +{ "and"} + +FUNCTION {bbl.etal} +{ "et~al." } + +FUNCTION {bbl.editors} +{ "Eds." } + +FUNCTION {bbl.editor} +{ "Ed." } + +FUNCTION {bbl.edby} +{ "edited by" } + +FUNCTION {bbl.edition} +{ "Edition" } + +FUNCTION {bbl.volume} +{ "Vol." } + +FUNCTION {bbl.of} +{ "of" } + +FUNCTION {bbl.number} +{ "no." } + +FUNCTION {bbl.nr} +{ "no." } + +FUNCTION {bbl.in} +{ "in" } + +FUNCTION {bbl.pages} +{ "pp." } + +FUNCTION {bbl.page} +{ "p." } + +FUNCTION {bbl.chapter} +{ "Ch." } + +FUNCTION {bbl.techrep} +{ "Tech. Rep." } + +FUNCTION {bbl.mthesis} +{ "Master's thesis" } + +FUNCTION {bbl.phdthesis} +{ "Ph.D. thesis" } + +FUNCTION {bbl.first} +{ "1st" } + +FUNCTION {bbl.second} +{ "2nd" } + +FUNCTION {bbl.third} +{ "3rd" } + +FUNCTION {bbl.fourth} +{ "4th" } + +FUNCTION {bbl.fifth} +{ "5th" } + +FUNCTION {bbl.st} +{ "st" } + +FUNCTION {bbl.nd} +{ "nd" } + +FUNCTION {bbl.rd} +{ "rd" } + +FUNCTION {bbl.th} +{ "th" } + +MACRO {jan} {"Jan."} + +MACRO {feb} {"Feb."} + +MACRO {mar} {"Mar."} + +MACRO {apr} {"Apr."} + +MACRO {may} {"May"} + +MACRO {jun} {"Jun."} + +MACRO {jul} {"Jul."} + +MACRO {aug} {"Aug."} + +MACRO {sep} {"Sep."} + +MACRO {oct} {"Oct."} + +MACRO {nov} {"Nov."} + +MACRO {dec} {"Dec."} + +FUNCTION {eng.ord} +{ duplicate$ "1" swap$ * + #-2 #1 substring$ "1" = + { bbl.th * } + { duplicate$ #-1 #1 substring$ + duplicate$ "1" = + { pop$ bbl.st * } + { duplicate$ "2" = + { pop$ bbl.nd * } + { "3" = + { bbl.rd * } + { bbl.th * } + if$ + } + if$ + } + if$ + } + if$ +} + +MACRO {acmcs} {"ACM Comput. Surv."} + +MACRO {acta} {"Acta Inf."} + +MACRO {cacm} {"Commun. ACM"} + +MACRO {ibmjrd} {"IBM J. Res. Dev."} + +MACRO {ibmsj} {"IBM Syst.~J."} + +MACRO {ieeese} {"IEEE Trans. Softw. Eng."} + +MACRO {ieeetc} {"IEEE Trans. Comput."} + +MACRO {ieeetcad} + {"IEEE Trans. Comput.-Aided Design Integrated Circuits"} + +MACRO {ipl} {"Inf. Process. Lett."} + +MACRO {jacm} {"J.~ACM"} + +MACRO {jcss} {"J.~Comput. Syst. Sci."} + +MACRO {scp} {"Sci. Comput. Programming"} + +MACRO {sicomp} {"SIAM J. Comput."} + +MACRO {tocs} {"ACM Trans. Comput. Syst."} + +MACRO {tods} {"ACM Trans. Database Syst."} + +MACRO {tog} {"ACM Trans. Gr."} + +MACRO {toms} {"ACM Trans. Math. Softw."} + +MACRO {toois} {"ACM Trans. Office Inf. Syst."} + +MACRO {toplas} {"ACM Trans. Prog. Lang. Syst."} + +MACRO {tcs} {"Theoretical Comput. Sci."} + +FUNCTION {write.url} +{ url empty$ + { skip$ } + { "\newline\urlprefix\url{" url * "}" * write$ newline$ } + if$ +} + +INTEGERS { nameptr namesleft numnames } + +FUNCTION {format.names} +{ 's := + #1 'nameptr := + s num.names$ 'numnames := + numnames 'namesleft := + { namesleft #0 > } + { s nameptr + "{f.~}{vv~}{ll}{, jj}" format.name$ + 't := + nameptr #1 > + { + namesleft #1 > + { ", " * t * } + { + "," * + s nameptr "{ll}" format.name$ duplicate$ "others" = + { 't := } + { pop$ } + if$ + t "others" = + { + " " * bbl.etal * + } + { " " * t * } + if$ + } + if$ + } + 't + if$ + nameptr #1 + 'nameptr := + namesleft #1 - 'namesleft := + } + while$ +} +FUNCTION {format.names.ed} +{ format.names } +FUNCTION {format.authors} +{ author empty$ + { "" } + { author format.names } + if$ +} + +FUNCTION {format.editors} +{ editor empty$ + { "" } + { editor format.names + editor num.names$ #1 > + { " (" * bbl.editors * ")" * } + { " (" * bbl.editor * ")" * } + if$ + } + if$ +} + +FUNCTION {format.in.editors} +{ editor empty$ + { "" } + { editor format.names.ed + editor num.names$ #1 > + { " (" * bbl.editors * ")" * } + { " (" * bbl.editor * ")" * } + if$ + } + if$ +} + +FUNCTION {format.note} +{ + note empty$ + { "" } + { note #1 #1 substring$ + duplicate$ "{" = + 'skip$ + { output.state mid.sentence = + { "l" } + { "u" } + if$ + change.case$ + } + if$ + note #2 global.max$ substring$ * + } + if$ +} + +FUNCTION {format.title} +{ title empty$ + { "" } + { title "t" change.case$ + } + if$ +} + +FUNCTION {output.bibitem.original} +{ newline$ + "\bibitem{" write$ + cite$ write$ + "}" write$ + newline$ + "" + before.all 'output.state := +} + +FUNCTION {n.dashify} +{ + 't := + "" + { t empty$ not } + { t #1 #1 substring$ "-" = + { t #1 #2 substring$ "--" = not + { "--" * + t #2 global.max$ substring$ 't := + } + { { t #1 #1 substring$ "-" = } + { "-" * + t #2 global.max$ substring$ 't := + } + while$ + } + if$ + } + { t #1 #1 substring$ * + t #2 global.max$ substring$ 't := + } + if$ + } + while$ +} + +FUNCTION {word.in} +{ bbl.in + ":" * + " " * } + +FUNCTION {format.date} +{ year empty$ + { month empty$ + { "" } + { "there's a month but no year in " cite$ * warning$ + month + } + if$ + } + { month empty$ + 'year + { month " " * year * } + if$ + } + if$ + duplicate$ empty$ + 'skip$ + { + before.all 'output.state := + " (" swap$ * ")" * + } + if$ +} + +FUNCTION{format.year} +{ year duplicate$ empty$ + { "empty year in " cite$ * warning$ pop$ "" } + { "(" swap$ * ")" * } + if$ +} + +FUNCTION {format.btitle} +{ title +} + +FUNCTION {tie.or.space.connect} +{ duplicate$ text.length$ #3 < + { "~" } + { " " } + if$ + swap$ * * +} + +FUNCTION {either.or.check} +{ empty$ + 'pop$ + { "can't use both " swap$ * " fields in " * cite$ * warning$ } + if$ +} + +FUNCTION {format.bvolume} +{ volume empty$ + { "" } + { bbl.volume volume tie.or.space.connect + series empty$ + 'skip$ + { bbl.of space.word * series emphasize * } + if$ + "volume and number" number either.or.check + } + if$ +} + +FUNCTION {format.number.series} +{ volume empty$ + { number empty$ + { series field.or.null } + { output.state mid.sentence = + { bbl.number } + { bbl.number capitalize } + if$ + number tie.or.space.connect + series empty$ + { "there's a number but no series in " cite$ * warning$ } + { bbl.in space.word * series * } + if$ + } + if$ + } + { "" } + if$ +} + +FUNCTION {is.num} +{ chr.to.int$ + duplicate$ "0" chr.to.int$ < not + swap$ "9" chr.to.int$ > not and +} + +FUNCTION {extract.num} +{ duplicate$ 't := + "" 's := + { t empty$ not } + { t #1 #1 substring$ + t #2 global.max$ substring$ 't := + duplicate$ is.num + { s swap$ * 's := } + { pop$ "" 't := } + if$ + } + while$ + s empty$ + 'skip$ + { pop$ s } + if$ +} + +FUNCTION {convert.edition} +{ edition extract.num "l" change.case$ 's := + s "first" = s "1" = or + { bbl.first 't := } + { s "second" = s "2" = or + { bbl.second 't := } + { s "third" = s "3" = or + { bbl.third 't := } + { s "fourth" = s "4" = or + { bbl.fourth 't := } + { s "fifth" = s "5" = or + { bbl.fifth 't := } + { s #1 #1 substring$ is.num + { s eng.ord 't := } + { edition 't := } + if$ + } + if$ + } + if$ + } + if$ + } + if$ + } + if$ + t +} + +FUNCTION {format.edition} +{ edition empty$ + { "" } + { output.state mid.sentence = + { convert.edition "l" change.case$ " " * bbl.edition * } + { convert.edition "t" change.case$ " " * bbl.edition * } + if$ + } + if$ +} + +INTEGERS { multiresult } + +FUNCTION {multi.page.check} +{ 't := + #0 'multiresult := + { multiresult not + t empty$ not + and + } + { t #1 #1 substring$ + duplicate$ "-" = + swap$ duplicate$ "," = + swap$ "+" = + or or + { #1 'multiresult := } + { t #2 global.max$ substring$ 't := } + if$ + } + while$ + multiresult +} + +FUNCTION {format.pages} +{ pages empty$ + { "" } + { pages multi.page.check + { bbl.pages pages n.dashify tie.or.space.connect } + { bbl.page pages tie.or.space.connect } + if$ + } + if$ +} + +FUNCTION {format.journal.pages} +{ pages empty$ + 'skip$ + { duplicate$ empty$ + { pop$ format.pages } + { + " " * + format.year * " " * + pages n.dashify * + } + if$ + } + if$ +} + +FUNCTION {format.vol.num.pages} +{ + % volume field.or.null + " " + volume empty$ + { pop$ "" } + { volume * } + if$ + number empty$ + 'skip$ + { + "~(" number * ")" * * + volume empty$ + { "there's a number but no volume in " cite$ * warning$ } + 'skip$ + if$ + } + if$ +} + +FUNCTION {format.chapter.pages} +{ chapter empty$ + { "" } + { type empty$ + { bbl.chapter } + { type "l" change.case$ } + if$ + chapter tie.or.space.connect + } + if$ +} + +FUNCTION {format.in.ed.booktitle} +{ booktitle empty$ + { "" } + { editor empty$ + { word.in booktitle * } + { word.in format.in.editors * ", " * + booktitle * } + if$ + } + if$ +} + +FUNCTION {empty.misc.check} +{ author empty$ title empty$ howpublished empty$ + month empty$ year empty$ note empty$ + and and and and and + { "all relevant fields are empty in " cite$ * warning$ } + 'skip$ + if$ +} + +FUNCTION {format.thesis.type} +{ type empty$ + 'skip$ + { pop$ + type "t" change.case$ + } + if$ +} + +FUNCTION {format.tr.number} +{ type empty$ + { bbl.techrep } + 'type + if$ + number empty$ + { "t" change.case$ } + { number tie.or.space.connect } + if$ +} + +FUNCTION {format.article.crossref} +{ + key empty$ + { journal empty$ + { "need key or journal for " cite$ * " to crossref " * crossref * + warning$ + "" + } + { word.in journal emphasize * } + if$ + } + { word.in key * " " *} + if$ + " \cite{" * crossref * "}" * +} + +FUNCTION {format.crossref.editor} +{ editor #1 "{vv~}{ll}" format.name$ + editor num.names$ duplicate$ + #2 > + { pop$ + " " * bbl.etal * + } + { #2 < + 'skip$ + { editor #2 "{ff }{vv }{ll}{ jj}" format.name$ "others" = + { + " " * bbl.etal * + } + { bbl.and space.word * editor #2 "{vv~}{ll}" format.name$ + * } + if$ + } + if$ + } + if$ +} + +FUNCTION {format.book.crossref} +{ volume empty$ + { "empty volume in " cite$ * "'s crossref of " * crossref * warning$ + word.in + } + { bbl.volume volume tie.or.space.connect + bbl.of space.word * + } + if$ + editor empty$ + editor field.or.null author field.or.null = + or + { key empty$ + { series empty$ + { "need editor, key, or series for " cite$ * " to crossref " * + crossref * warning$ + "" * + } + { series emphasize * } + if$ + } + { key * } + if$ + } + { format.crossref.editor * } + if$ + " \cite{" * crossref * "}" * +} + +FUNCTION {format.incoll.inproc.crossref} +{ + editor empty$ + editor field.or.null author field.or.null = + or + { key empty$ + { booktitle empty$ + { "need editor, key, or booktitle for " cite$ * " to crossref " * + crossref * warning$ + "" + } + { word.in booktitle * } + if$ + } + { word.in key * " " *} + if$ + } + { word.in format.crossref.editor * " " *} + if$ + " \cite{" * crossref * "}" * +} + +FUNCTION {format.org.or.pub} +{ 't := + "" + year empty$ + { "empty year in " cite$ * warning$ } + 'skip$ + if$ + address empty$ t empty$ and + year empty$ and + 'skip$ + { + t empty$ + { address empty$ + 'skip$ + { address * } + if$ + } + { t * + address empty$ + 'skip$ + { ", " * address * } + if$ + } + if$ + year empty$ + 'skip$ + { t empty$ address empty$ and + 'skip$ + { ", " * } + if$ + year * + } + if$ + } + if$ +} + +FUNCTION {format.publisher.address} +{ publisher empty$ + { "empty publisher in " cite$ * warning$ + "" + } + { publisher } + if$ + format.org.or.pub +} + +FUNCTION {format.organization.address} +{ organization empty$ + { "" } + { organization } + if$ + format.org.or.pub +} + +FUNCTION {make.href.null} +{ + pop$ +} +FUNCTION {make.href.hypertex} +{ + "\special {html: }" * swap$ * + "\special {html:}" * +} +FUNCTION {make.href.hyperref} +{ + "\href {" swap$ * "} {\path{" * swap$ * "}}" * +} +FUNCTION {make.href} +{ hrefform #2 = + 'make.href.hyperref % hrefform = 2 + { hrefform #1 = + 'make.href.hypertex % hrefform = 1 + 'make.href.null % hrefform = 0 (or anything else) + if$ + } + if$ +} + +FUNCTION {format.url} +{ inlinelinks #1 = url empty$ or + { "" } + { hrefform #1 = + { % special case -- add HyperTeX specials + urlintro "\url{" url * "}" * url make.href.hypertex * } + { urlintro "\url{" * url * "}" * } + if$ + } + if$ +} + +FUNCTION {format.eprint} +{ eprint empty$ + { "" } + { eprintprefix eprint * eprinturl eprint * make.href } + if$ +} + +FUNCTION {format.doi} +{ doi empty$ + { "" } + { doiprefix doi * doiurl doi * make.href } + if$ +} + +FUNCTION {output.url} +{ url empty$ + 'skip$ + { new.block + format.url output + format.lastchecked output + } + if$ +} + +FUNCTION {output.web.refs} +{ + new.block + output.url + addeprints eprint empty$ not and + { format.eprint output.nonnull } + 'skip$ + if$ + adddoiresolver doi empty$ not and + { format.doi output.nonnull } + 'skip$ + if$ +} + +FUNCTION {output.bibitem} +{ outside.brackets 'bracket.state := + output.bibitem.original + inlinelinks url empty$ not and + { #1 'makeinlinelink := } + { #0 'makeinlinelink := } + if$ +} + +FUNCTION {fin.entry} +{ output.web.refs % urlbst + makeinlinelink % ooops, it appears we didn't have a title for inlinelink + { setup.inlinelink % add some artificial link text here, as a fallback + "[link]" output.nonnull } + 'skip$ + if$ + bracket.state close.brackets = % urlbst + { "]" * } + 'skip$ + if$ + fin.entry.original +} + +FUNCTION {webpage} +{ output.bibitem + author empty$ + { editor empty$ + 'skip$ % author and editor both optional + { format.editors output.nonnull } + if$ + } + { editor empty$ + { format.authors output.nonnull } + { "can't use both author and editor fields in " cite$ * warning$ } + if$ + } + if$ + new.block + title empty$ 'skip$ 'setup.inlinelink if$ + format.title "title" output.check + inbrackets "online" output + new.block + year empty$ + 'skip$ + { format.date "year" output.check } + if$ + % We don't need to output the URL details ('lastchecked' and 'url'), + % because fin.entry does that for us, using output.web.refs. The only + % reason we would want to put them here is if we were to decide that + % they should go in front of the rather miscellaneous information in 'note'. + new.block + note output + fin.entry +} + +FUNCTION {article} +{ output.bibitem + format.authors "author" output.check + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.title "title" output.check + crossref missing$ + { journal + "journal" output.check + % add.blank + before.all 'output.state := + format.vol.num.pages output + } + { format.article.crossref output.nonnull + format.pages output + } + if$ + format.journal.pages + format.note output + pages empty$ + { format.date "year" output.check } + 'skip$ + if$ + fin.entry + write.url +} + +FUNCTION {book} +{ output.bibitem + author empty$ + { format.editors "author and editor" output.check + } + { format.authors output.nonnull + crossref missing$ + { "author and editor" editor either.or.check } + 'skip$ + if$ + } + if$ + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.btitle "title" output.check + crossref missing$ + { format.edition output + format.bvolume output + format.number.series output + format.publisher.address output + } + { + format.book.crossref output.nonnull + } + if$ + format.note output + fin.entry + write.url +} + +FUNCTION {booklet} +{ output.bibitem + format.authors output + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.title "title" output.check + howpublished output + address output + format.note output + format.date "year" output.check + fin.entry + write.url +} + +FUNCTION {inbook} +{ output.bibitem + author empty$ + { format.editors "author and editor" output.check + } + { format.authors output.nonnull + crossref missing$ + { "author and editor" editor either.or.check } + 'skip$ + if$ + } + if$ + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.btitle "title" output.check + crossref missing$ + { + format.edition output + format.bvolume output + format.number.series output + format.publisher.address output + format.chapter.pages "chapter and pages" output.check + } + { + format.chapter.pages "chapter and pages" output.check + format.book.crossref output.nonnull + } + if$ + format.pages "pages" output.check + format.note output + fin.entry + write.url +} + +FUNCTION {incollection} +{ output.bibitem + format.authors "author" output.check + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.title "title" output.check + crossref missing$ + { format.in.ed.booktitle "booktitle" output.check + format.edition output + format.bvolume output + format.number.series output + format.publisher.address output + format.chapter.pages output + } + { format.incoll.inproc.crossref output.nonnull + format.chapter.pages output + } + if$ + format.pages "pages" output.check + format.note output + fin.entry + write.url +} + +FUNCTION {inproceedings} +{ output.bibitem + format.authors "author" output.check + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.title "title" output.check + crossref missing$ + { format.in.ed.booktitle "booktitle" output.check + format.edition output + format.bvolume output + format.number.series output + publisher empty$ + { format.organization.address output } + { organization output + format.publisher.address output + } + if$ + } + { format.incoll.inproc.crossref output.nonnull + } + if$ + format.pages "pages" output.check + format.note output + fin.entry + write.url +} + +FUNCTION {conference} { inproceedings } + +FUNCTION {manual} +{ output.bibitem + author empty$ + { organization empty$ + 'skip$ + { organization output.nonnull + address output + } + if$ + } + { format.authors output.nonnull } + if$ + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.btitle "title" output.check + author empty$ + { organization empty$ + { + address output + } + 'skip$ + if$ + } + { + organization output + address output + } + if$ + format.edition output + format.note output + format.date "year" output.check + fin.entry + write.url +} + +FUNCTION {mastersthesis} +{ output.bibitem + format.authors "author" output.check + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.title "title" output.check + bbl.mthesis format.thesis.type output.nonnull + school "school" output.check + address output + format.note output + format.date "year" output.check + fin.entry + write.url +} + +FUNCTION {misc} +{ output.bibitem + format.authors output + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.title output + howpublished output + format.note output + format.date "year" output.check + fin.entry + write.url + empty.misc.check +} + +FUNCTION {phdthesis} +{ output.bibitem + format.authors "author" output.check + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.title "title" output.check + bbl.phdthesis format.thesis.type output.nonnull + school "school" output.check + address output + format.note output + format.date "year" output.check + fin.entry + write.url +} + +FUNCTION {proceedings} +{ output.bibitem + editor empty$ + { organization output } + { format.editors output.nonnull } + if$ + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.btitle "title" output.check + format.bvolume output + format.number.series output + editor empty$ + { publisher empty$ + 'skip$ + { + format.publisher.address output + } + if$ + } + { publisher empty$ + { + format.organization.address output } + { + organization output + format.publisher.address output + } + if$ + } + if$ + format.note output + fin.entry + write.url +} + +FUNCTION {techreport} +{ output.bibitem + format.authors "author" output.check + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.title "title" output.check + format.tr.number output.nonnull + institution "institution" output.check + address output + format.note output + format.date "year" output.check + fin.entry + write.url +} + +FUNCTION {unpublished} +{ output.bibitem + format.authors "author" output.check + title empty$ 'skip$ 'setup.inlinelink if$ % urlbst + format.title "title" output.check + format.note "note" output.check + format.date "year" output.check + fin.entry + write.url +} + +FUNCTION {default.type} { misc } + +READ + +STRINGS { longest.label } + +INTEGERS { number.label longest.label.width } + +FUNCTION {initialize.longest.label} +{ "" 'longest.label := + #1 'number.label := + #0 'longest.label.width := +} + +FUNCTION {longest.label.pass} +{ number.label int.to.str$ 'label := + number.label #1 + 'number.label := + label width$ longest.label.width > + { label 'longest.label := + label width$ 'longest.label.width := + } + 'skip$ + if$ +} + +EXECUTE {initialize.longest.label} + +ITERATE {longest.label.pass} + +FUNCTION {begin.bib} +{ preamble$ empty$ + 'skip$ + { preamble$ write$ newline$ } + if$ + "\begin{thebibliography}{" longest.label * "}" * + write$ newline$ + "\expandafter\ifx\csname url\endcsname\relax" + write$ newline$ + " \def\url#1{\texttt{#1}}\fi" + write$ newline$ + "\expandafter\ifx\csname urlprefix\endcsname\relax\def\urlprefix{URL }\fi" + write$ newline$ + "\expandafter\ifx\csname href\endcsname\relax" + write$ newline$ + " \def\href#1#2{#2} \def\path#1{#1}\fi" + write$ newline$ +} + +EXECUTE {begin.bib} + +EXECUTE {init.urlbst.variables} +EXECUTE {init.state.consts} + +ITERATE {call.type$} + +FUNCTION {end.bib} +{ newline$ + "\end{thebibliography}" write$ newline$ +} + +EXECUTE {end.bib} +%% End of customized bst file +%% +%% End of file `elsarticle-num.bst'. + + diff --git a/docs/paper/the-karl-code/paper.tex b/docs/paper/the-karl-code/paper.tex index 3bf2adc..c8d8a38 100755 --- a/docs/paper/the-karl-code/paper.tex +++ b/docs/paper/the-karl-code/paper.tex @@ -16,16 +16,47 @@ \usepackage{siunitx} % for proper units \usepackage{upgreek} % for upbeta \usepackage{mathtools} % for abs +\usepackage{booktabs} % for nicer tables % additional CGS units \DeclareSIUnit\statcoulomb{statC} \DeclareSIUnit\statvolt{statV} \DeclareSIUnit\erg{erg} -% setup syntax highlighting for JSON +% setup for JSON \colorlet{punct}{red!60!black} +\definecolor{background}{HTML}{EEEEEE} \definecolor{delim}{RGB}{20,105,176} -\colorlet{digit}{magenta!60!black} +\colorlet{numb}{magenta!60!black} + +\lstdefinelanguage{json}{ + basicstyle=\footnotesize\ttfamily, + numbers=left, + numberstyle=\scriptsize, + stepnumber=1, + numbersep=8pt, + showstringspaces=false, + breaklines=true, + frame=lines, + backgroundcolor=\color{background}, + literate= + *{0}{{{\color{numb}0}}}{1} + {1}{{{\color{numb}1}}}{1} + {2}{{{\color{numb}2}}}{1} + {3}{{{\color{numb}3}}}{1} + {4}{{{\color{numb}4}}}{1} + {5}{{{\color{numb}5}}}{1} + {6}{{{\color{numb}6}}}{1} + {7}{{{\color{numb}7}}}{1} + {8}{{{\color{numb}8}}}{1} + {9}{{{\color{numb}9}}}{1} + {:}{{{\color{punct}{:}}}}{1} + {,}{{{\color{punct}{,}}}}{1} + {\{}{{{\color{delim}{\{}}}}{1} + {\}}{{{\color{delim}{\}}}}}{1} + {[}{{{\color{delim}{[}}}}{1} + {]}{{{\color{delim}{]}}}}{1}, +} % short cuts \newcommand{\fullstop}{\text{\,.}} % in equations @@ -56,61 +87,63 @@ \begin{frontmatter} - %% Title, authors and addresses + %% Title, authors and addresses - \title{KARL - A Monte Carlo model for atomic and molecular processes in the tritium atmosphere of the KATRIN experiment} + \title{KARL - A Monte Carlo model for atomic and molecular processes in the tritium atmosphere of the KATRIN experiment} - \author[a]{Jonas Kellerer} - \author[b,c]{Felix Spanier \corref{author}} % Todo: aktualisieren + \author[a]{Jonas Kellerer} + \author[b]{Felix Spanier \corref{author}} - \cortext[author] {Corresponding author.\\\textit{E-mail address:} felix@fspanier.de} - \address[a]{Institut f\"ur Astroteilchenphysik, KIT, Hermann-von-Helmholtz-Platz 1, - 76344 Eggenstein-Leopoldshafen, Germany} - \address[b]{Institut f\"ur Theoretische Astrophysik, Universit\"at Heidelberg, Albert-Ueberle-Str. 2 und Philosophenweg 12, - 69120 Heidelberg, Germany} - \address[c]{Centre for Space Research, North-West University, South Africa} % Todo: aktualisieren + \cortext[author] {Corresponding author.\\\textit{E-mail address:} felix@fspanier.de} + \address[a]{Institut f\"ur Astroteilchenphysik, KIT, Hermann-von-Helmholtz-Platz 1, + 76344 Eggenstein-Leopoldshafen, Germany} + \address[b]{Institut f\"ur Theoretische Astrophysik, Universit\"at Heidelberg, Albert-Ueberle-Str. 2 und Philosophenweg 12, + 69120 Heidelberg, Germany} - \begin{abstract} + \begin{abstract} - The karl code is awesome. + %At the KATRIN experiment, the electron antineutrino mass is inferred from the shape of the $\upbeta$-decay spectrum of tritium. Important systematic effects in the Windowless Gaseous Tritium Source (WGTS) of the experiment include the energy loss by electron scattering, and the extended starting potential. In the WGTS, primary high-energy electrons from $\upbeta$-decay produce an extended secondary spectrum of electrons through various atomic and molecular processes including ionization, recombination, cluster formation and scattering. In addition to providing data essential to the simulation of energy loss processes, the electron spectrum also provides information important in the simulation of plasma processes. These simulations will then provide an insight on the starting potential.\\ - \end{abstract} + A new parallelized simulation code is presented, which uses a semi classical Monte Carlo method to determine the particle spectra in the KATRIN source by tracking single particles from interaction to interaction. The moved distance is determined from the mean free path and subsequently from cross sections and particle densities. The particle densities can be provided by the user, or are calculated during simulation from the movement of the simulated particles. This enables also the inclusion of recombination effects in the calculation. The implemented interaction types include elastic scattering, ionization, clustering and excitation (electric, vibrational, rotational) and recombination. Initial particles are created using the neutral gas density and known $\upbeta$-decay spectrum. The code is optimized for the conditions in the KATRIN source, being able to cope with a large density gradient, neutral gas flow and many different particle species in a Tritium environment. + The code is parallelized using MPI and writes output using HDF5. Input to the simulation is read from a JSON description that provides general information on the simulation (resolution of the simulation domain) and the various optional features of the code, namely user defined species with their own terminator, interaction types, movers and initialization. - % submit to http://www.ees.elsevier.com/cpc. + \end{abstract} - % In addition to the manuscript you must supply: the program source code; job control scripts, where applicable; a README file giving the names and a brief description of all the files that make up the package and clear instructions on the installation and execution of the program; sample input and output data for at least one comprehensive test run; and, where appropriate, a user manual. These should be sent, via email as a compressed archive file, to the CPC Program Librarian at cpc@qub.ac.uk. + % submit to http://www.ees.elsevier.com/cpc. + + % In addition to the manuscript you must supply: the program source code; job control scripts, where applicable; a README file giving the names and a brief description of all the files that make up the package and clear instructions on the installation and execution of the program; sample input and output data for at least one comprehensive test run; and, where appropriate, a user manual. These should be sent, via email as a compressed archive file, to the CPC Program Librarian at cpc@qub.ac.uk. - \begin{keyword} - %% keywords here, in the form: keyword \sep keyword - Monte Carlo \sep Tritium decay \sep Ionization \sep Scattering - \end{keyword} + \begin{keyword} + %% keywords here, in the form: keyword \sep keyword + Monte Carlo \sep Tritium decay \sep Ionization \sep Scattering + \end{keyword} \end{frontmatter} {\bf PROGRAM SUMMARY} \begin{small} - \noindent - {\em Manuscript Title:} KARL - A Monte Carlo model for atomic and molecular processes in the tritium atmosphere of the KATRIN experiment \\ - {\em Authors:} Christian Reiling, Jonas Kellerer, Felix Spanier \\ - {\em Program Title:} KARL - \textbf{KA}trin WGTS elect\textbf{R}on and ion spectrum Monte Car\textbf{L}o \\ - {\em Journal Reference:} \\ %Leave blank, supplied by Elsevier. - {\em Catalogue identifier:} \\ %Leave blank, supplied by Elsevier. - {\em Licensing provisions:} GNU Public Licence \\ %muss so sein wegen blitz - {\em Programming language:} C++ \\ - {\em Computer:} any workstation or cluster that has a modern C++ compiler (e.g. g++ 8.2 or later) an MPI implementation and the required external libraries \\ - {\em Operating system:} Linux / Unix \\ - {\em RAM:} depending on problem size and number of resolved species between 100 MB and 2 GB; some scratch space \\ %%TODO: Prüfen - {\em Number of processors used:} depending on problem size between one and a few hundred processors \\ - {\em Keywords:} semi-classical Monte Carlo \\ - {\em Classification:} 19.1 Atomic and Molecular Processes \\ %Classify using CPC Program Library Subject Index, see ( % http://cpc.cs.qub.ac.uk/subjectIndex/SUBJECT_index.html) - {\em External routines/libraries:} C++ compiler (tested with g++ 8.2 and 9.4.0), MPI 1.1 (tested with OpenMPI 3.1), HDF5 with support for parallel I/O (tested with version 1.10.0), Blitz++ (tested with version 1.0.2), Jansson (tested with version 2.12 and 2.13)\\ - {\em Nature of problem:} In the KATRIN experiment (and other experiments alike that feature large vessels filled with tritium) electrons from beta decay. These electrons interact with the ambient gas to produce secondary electrons through ionization. Subsequent processes including excitation, secondary ionization and collisions. The resulting electron and ion differential energy spectrum at various positions is relevant for further plasma analysis and the current of charged particles to the ends of the experiments is an observable. \\ - {\em Solution method:} Semi-classical Monte Carlo \\ - {\em Restrictions:} The geometry of the experiment is currently limited to the KATRIN experiment, but this may easily be changed. Secondary ions are currently assumed as thermal.\\ - {\em Unusual features:} The configuration is stored in JSON files. \\ - {\em Running time:} minutes to hours; Depending on number of simulated decays \\ + \noindent + {\em Manuscript Title:} KARL - A Monte Carlo model for atomic and molecular processes in the tritium atmosphere of the KATRIN experiment \\ + {\em Authors:} Jonas Kellerer, Christian Reiling, Felix Spanier \\ + {\em Program Title:} KARL - \textbf{KA}trin WGTS elect\textbf{R}on and ion spectrum Monte Car\textbf{L}o \\ + {\em Journal Reference:} \\ %Leave blank, supplied by Elsevier. + {\em Catalogue identifier:} \\ %Leave blank, supplied by Elsevier. + {\em Licensing provisions:} GNU Public Licence \\ %muss so sein wegen blitz + {\em Programming language:} C++ \\ + {\em Computer:} any workstation or cluster that has a modern C++ compiler (e.g. g++ 8.2 or later) an MPI implementation and the required external libraries \\ + {\em Operating system:} Linux / Unix \\ + {\em RAM:} depending on problem size and number of resolved species between 100 MB and 2 GB; some scratch space + {\em Number of processors used:} depending on problem size between one and a few hundred processors \\ + {\em Keywords:} semi-classical Monte Carlo \\ + {\em Classification:} 19.1 Atomic and Molecular Processes \\ %Classify using CPC Program Library Subject Index, see ( % http://cpc.cs.qub.ac.uk/subjectIndex/SUBJECT_index.html) + {\em External routines/libraries:} C++ compiler (tested with g++ 8.2 and 9.4.0), MPI 1.1 (tested with OpenMPI 3.1), HDF5 with support for parallel I/O (tested with version 1.10.0), Blitz++ (tested with version 1.0.2), Jansson (tested with version 2.12 and 2.13)\\ + {\em Nature of problem:} In the KATRIN experiment (and other experiments alike that feature large vessels filled with tritium) electrons from beta decay. These electrons interact with the ambient gas to produce secondary electrons through ionization. Subsequent processes including excitation, secondary ionization and collisions. The resulting electron and ion differential energy spectrum at various positions is relevant for further plasma analysis and the current of charged particles to the ends of the experiments is an observable. \\ + {\em Solution method:} Semi-classical Monte Carlo \\ + {\em Restrictions:} The geometry of the experiment is currently limited to the KATRIN experiment, but this may easily be changed.\\ + {\em Unusual features:} The configuration is stored in JSON files. \\ + {\em Running time:} minutes to hours; Depending on number of simulated decays \\ \end{small} @@ -118,13 +151,17 @@ \section{Introduction} \label{sec:intro} -The KATRIN experiment is designed to measure the electron neutrino mass to unprecedented sensitivity down to \SI{0.2}{eV} \citep{KATRIN2005}. At the experiment, the mass is inferred from the shape of the $\upbeta$-decay spectrum of tritium. The contribution of the mass on the shape is most dominant in the endpoint region. The experiment can be divided into two parts: the source section and the detector section. In the source section, tritium gas is circulated which provides a high luminous stream of beta electrons. These electrons are magnetically guided to the detector section. There they are separated by their kinetic energy: one stream being recorded by the detector, the other reflected back to the source. +The KATRIN experiment is designed to measure the electron neutrino mass to unprecedented sensitivity down to \SI{0.2}{eV} \citep{KATRIN2005}. At the experiment, the mass is inferred from the shape of the $\upbeta$-decay spectrum of tritium. The contribution of the mass on the shape is most dominant in the endpoint region. The experiment can be divided into two parts: the source section and the detector section. In the source section, tritium gas is circulated which provides a high luminous stream of beta electrons. These electrons are magnetically guided to the detector section. There they are separated by their kinetic energy: one small stream being recorded by the detector, the other larger one reflected back to the source. -The final neutrino mass sensitivity can only be reached through a precise examination of all systematic effects \citep{Aker.1132021}. One of these effects is the plasma inside the source. It is generated through $\upbeta$-decay and subsequent impact ionization of neutral tritium gas. The resulting charged particle density is sufficient to assume a plasma inside the WGTS \citep{Kuckert.2016}. The effects of this plasma can influence the motion of the electrons. +Both the initial and reflected stream of electrons interact with the gas in the source. For high energy electrons these interactions include mostly elastic scattering, but also ionization. Hence, much more electrons, and therefore also ions, are created in the source than from beta decay alone. The charged particle density is high enough, that a plasma forms in the source \citep{Kuckert.2016}. This plasma influences the high energy spectrum through its self generated, ab initio inhomogeneous potential. A precise knowledge of the electron and ion spectrum and density is necessary for any plasma analysis. -The plasma, in conjunction with boundaries, exerts a potential throughout the source, also called starting potential, which can show a non-homogeneous structure. The final energy of the $\upbeta$-electrons selected by the spectrometer can therefore be dependent on the original position of $\upbeta$-decay inside the source. Hence, the plasma potential can distort the integral spectrum measured at the detector, and has to be accounted for in the analysis by a quantitative understanding of the plasma. Only the inhomogeneous part of the potential is of special interest, as the homogeneous part shifts the entire $\upbeta$-spectrum and can be easily taken into account. +The electron spectrum for high energy electrons is comparably simple to describe, as it follows the Fermi statistics of beta decay \citep{Fermi:1934aa}. However, it is much more complicated for secondary electrons, leading to a Markov chain of events, with further branching event chains. First, new particles are created through ionization on the whole energy range. This creates a multitude of new possible branches with their own characteristics. Also other interactions become more dominant at lower energies, namely elastic scattering and excitation processes of the tritium molecules through electronic, rotational and vibrational excitation. All of these interactions create new branches with feedback to the initial branches. Additionally, electrons can also recombine the existing ions in the source. This is not only dependent on the electron spectrum, but the ion spectrum as well. There are many different types of ions, which are created by clustering processes with the neutral gas. The neutral gas density, which is the dominant interaction partner for both electrons and ions, is not constant in the source, but ranges over more than three orders of magnitude over \SI{16}{m} \citep{Kuckert.2018}. Additionally, it has a position dependent mean drift velocity, also covering two orders of magnitude \citep{Kuckert.2018}. -In the past, the diffusion ansatz was used by L. Kuckert \citep{Kuckert.2016} to provide a quantitative model of the plasma. Recent studies \citep{Kellerer_2022} indicate, that this ansatz may not include all significant plasma effects, such as the high energy tail of the spectrum, the transition between a collisional and non-collisional plasma, as well as all time dependent effects. Therefore, a new kinetic simulation was developed within the KATRIN collaboration \citep{Kellerer2022_1000143868}. A precondition for any theoretical plasma study is the knowledge of electron and ion distributions (and velocities) at any point within the tritium source. Thus, a simulation tool was developed to determine the distributions, named KARL. First physical results of KARL were presented in \citep{Kellerer_2022}. This paper however focuses on the technical realization and provides the code itself. +Two different methods of descriptions seem obvious: a description through the temporal evolution of phasespace elements and a description through the Monte Carlo method by tracking of single particles. The first method impresses with a high resolution but is very computational intensive, especially with many different interaction types and species. Thus, it was rejected for the simulation of the problem at hand. The Monte Carlo method seems preferable, but in a classical Monte Carlo scheme each of the simulated events is independent on the others. This is not the case for events for electron and ions tracks because of recombination. This problem is addressed in the KARL code, which is presented in the following paper. + +In the KARL code, single particles are tracked through the source from one interaction to another. The moved distance between interactions is determined from the mean free path. The performed interactions is rolled from a list of available interactions. During movement it is recorded how long a particle stays within a predefined segment of the source. The density of the particle specie in this segment is then proportional to the cumulated time in that segment. Thus, the density can be determined during simulation. It can therefore also be used to evaluated the likeliness of recombination. + +The KARL code is customized to the special conditions in the KATRIN source. Hence, special care is taken to ensure correct movement of particles through the large density gradient. Additionally, all relevant interactions in a tritium gas atmosphere are included for both electrons and ions. \section{Description of the method} \label{sec:method} @@ -136,37 +173,31 @@ In the simulation, decays are successively processed. Meaning that each decay pa \subsection{General diagram} \label{ssec:general_diagram} -After initialization (see section~\ref{ssec:initialization}), the simulation starts its iterative cycle, which contains three subcycles, see figure~\ref{fig:simulation_flow}. The first adresses how many primary particles/events are processed, which is predefined by the user. It adds primary particles to the particle queue, if it is empty. In the second subcycle a particle is selected at random from the particle queue. This particle is processed until its termination and a new particle is selected from the queue. Within the third subcycle, the actual particle treatment is performed, which includes alternating between the movement step and interaction step. +After initialization (see section~\ref{ssec:initialization}), the simulation starts its iterative cycle, which contains three subcycles, see figure~\ref{fig:simulation_flow}. The first addresses how many primary particles/events are processed, which is predefined by the user. It adds primary particles to the particle queue, if it is empty. In the second subcycle a particle is selected at random from the particle queue. This particle is processed until its termination and a new particle is selected from the queue. Within the third subcycle, the actual particle treatment is performed, which includes alternating between the movement step and interaction step. For each movement step, the mean free path (MFP) $\lambda_\text{mfp}$ of the corresponding particle is calculated through %todo: citation \begin{equation} - \lambda_\text{mfp} = \frac{1}{\sum_i \sigma_i(E) n_i} \commaeq + \lambda_\text{mfp} = \frac{1}{\sum_i \sigma_i(E) n_i} \commaeq \end{equation} where $E$ is the kinetic energy of the particle in the lab frame, $\sigma_i$ is the cross section of a specific interaction, and $n_i$ the particle number density of the interaction partner. The cross sections are evaluated from predefined functions. The particle number density of the interaction partner is calculated either from a predefined function for background species, or from the density field for tracked species, see section~\ref{ssec:denstiy_fields} and \ref{sec:implementation} for more information. The actual moved distance $d$ is a statistical quantity, which can be derived from the MFP through %todo: citation \begin{equation} - d = \lambda_\text{mfp} \cdot \log \frac{1}{\eta} \commaeq - \label{eq:distance_from_mfp} + d = \lambda_\text{mfp} \cdot \log \frac{1}{\eta} \commaeq + \label{eq:distance_from_mfp} \end{equation} where $\eta \in (0, 1]$ is a random number. The particle is then moved by this distance $d$ in dependence on the electromagnetic fields inside the source, see section~\ref{ssec:movement}. During this step the density fields of the corresponding specie are updated. After the movement step it is evaluated if the particle needs to be terminated, which is mainly a check if the particle has left the simulation domain, or has hit a wall, see~\ref{ssec:termination}. If the particle is still alive, a random interaction is selected from the list of available interactions, weighted by its probability to occur. The probability scales with the cross section of that interaction and the interaction partner particle density. The corresponding interaction is performed and the interaction products, which are not the current particle are added to the particle queue. If the particle does no longer exist after the interaction (through recombination or clustering) it is terminated, otherwise the next movement step is performed. \begin{figure}[tbp] - \centering - \includegraphics[height=0.8\textheight]{figures/simulation_flow.pdf} - \caption{Simulation diagram. Shows diagram of simulation.} - \label{fig:simulation_flow} + \centering + \includegraphics[height=0.8\textheight]{figures/simulation_flow.pdf} + \caption{Simulation diagram. Shows diagram of simulation.} + \label{fig:simulation_flow} \end{figure} -\subsection{Monte Carlo method} -? -- mean free path, random for change of field\\ -- choice of interaction\\ -- interaction partner\\ - \subsection{Density fields} \label{ssec:denstiy_fields} @@ -174,20 +205,20 @@ In a general Monte Carlo simulation, each event is assumed to be independent of In the simulation, the source is segmented into evenly spaced segments in longitudinal, radial and azimuthal direction, predefined by the user, see figure~\ref{fig:segmentation} for a schematic representation. In each iteration step of the particle queue, it is recorded how long a particle with index $i$ stays in one of the predefined segments, labeled by the time $t_i$. The number density $n_\alpha$ of a species $\alpha$ is then proportional to the total time of all particles of the corresponding species spent in the segment $\sum_i t_i$ and the volume $V$ of the segment. In case of recombination, an additional term has to be added corresponding to the number of recombination $N_\gamma$ of the recombination partner $\gamma$ in the segment, resulting in \begin{equation} - n_\alpha = \frac{\sum_i t_i}{t_\text{sim} V} - \frac{N_\gamma}{V} \commaeq - \label{eq:target_field_density} + n_\alpha = \frac{\sum_i t_i}{t_\text{sim} V} - \frac{N_\gamma}{V} \commaeq + \label{eq:target_field_density} \end{equation} where $t_\text{sim}$ is called the simulated time \citep{Kellerer_2022}. It describes the simulated physical time that is past after simulating a fixed number of primary events $N_\text{prim.}$. In the case of radioactive beta decay at KATRIN, it can be directly determined by the activity $a$ through \begin{equation} - t_\text{sim} = \frac{N_\text{prim.}}{a}\, . \label{eq:simulated_time} + t_\text{sim} = \frac{N_\text{prim.}}{a}\, . \label{eq:simulated_time} \end{equation} The activity of the source is not dependent on the interaction of the charged particles in the source, and can therefore be evaluated from the predefined amount of neutral gas in the source. \begin{figure}[tbp] - \centering - \includegraphics[width=0.8\textwidth]{figures/segmentation_for_density_fields.pdf} - \caption{Segmentation. Shows segmentation of simulation.} - \label{fig:segmentation} + \centering + \includegraphics[width=0.8\textwidth]{figures/segmentation_for_density_fields.pdf} + \caption{Segmentation. Shows segmentation of simulation.} + \label{fig:segmentation} \end{figure} \subsection{Current collection} @@ -195,7 +226,7 @@ The activity of the source is not dependent on the interaction of the charged pa The second main objective of the code is to determine the particle currents in the source. This task is performed through so-called virtual barriers: predefined planes within the source, where each particle is registered, when it crosses from one side to another. The total current through the segment faces is then given by \begin{equation} - j = \frac{N^+ - N^-}{A \, t_\text{sim}} \commaeq + j = \frac{N^+ - N^-}{A \, t_\text{sim}} \commaeq \end{equation} (\citep{Kellerer_2022}) where $N^+$ and $N^-$ is the number of particles crossing the faces in positive and negative direction, $A$ is the area of the face and $t_\text{sim}$ the simulated time, see~Eq.~\ref{eq:simulated_time}. For convenience, the location of the virtual barriers are chosen to coincide with the segment boundaries, see figure~\ref{fig:segmentation}, of the density field calculation, see section~\ref{ssec:denstiy_fields}. @@ -206,14 +237,14 @@ For the simulation, we decided to use c++ as a programming language for several There are three basic building blocks of the simulation. First, the simulation itself is treated as a class, which is responsible for initialization of the simulation environment, see section~\ref{ssec:initialization} and guiding through the flow of the simulation, see figure~\ref{fig:simulation_flow}. Second, the particle class, which represents the simulated physical particles through their physical position, velocity and type of specie. Third, the specie class, which encapsulates the general behavior of each particle type (like electrons) in the simulation. -The main feature of the specie class is provide access to the density, velocity distribution and drift velocity of a specific type of particle. All three quantities are used for the calculation of the MFP and the choice of the interaction partner. However, we decided to distingquish between two types of species, those particles who are tracked throughout the simulation (electrons and ions) and those who act as background (tritium gas). This way, it is more clear which specie fulfills which function, especially in the initialization process. Additionally, the particle class only accepts the tracked specie class as input, reducing programming errors in the development of new injectors or interactions. +The main feature of the specie class is provide access to the density, velocity distribution and drift velocity of a specific type of particle. All three quantities are used for the calculation of the MFP and the choice of the interaction partner. However, we decided to distinguish between two types of species, those particles who are tracked throughout the simulation (electrons and ions) and those who act as background (tritium gas). This way, it is more clear which specie fulfils which function, especially in the initialization process. Additionally, the particle class only accepts the tracked specie class as input, reducing programming errors in the development of new injectors or interactions. -The tracked specie class is composed of different classes, providing access to the behavior of each particle type. Hence, each tracked specie can be tailored to the requirements of the user, either for testing, but also for the inclusion of further particles types. Along these lines, the code can be adapted to other experimental environments, provided the knowledge of the interaction and their cross sections. Each of the class members fulfills a special task, which will be described in detail in the following sections. +The tracked specie class is composed of different classes, providing access to the behavior of each particle type. Hence, each tracked specie can be tailored to the requirements of the user, either for testing, but also for the inclusion of further particles types. Along these lines, the code can be adapted to other experimental environments, provided the knowledge of the interaction and their cross sections. Each of the class members fulfils a special task, which will be described in detail in the following sections. \subsection{Movement} \label{ssec:movement} -The movement of particles is outsourced to the mover class. It moves the particle dependent on the E/B fields at the position of the particle, given the integrated distance a particle will move, see section~\ref{ssec:general_diagram}. The movement itself is subdivided into in smaller steps. This way, it can be evaluated if the particle has left the simulation domain between the steps, which stops the movement. Apart from the simulation boundary, the movement is stopped if the particle leaves a segment or energy bin of the density fields, see section~\ref{ssec:denstiy_fields}. No interaction will be performed afterwards, but a new distance will be rolled from the MFP at the new position of the particle, see equation~\ref{eq:distance_from_mfp}. This procedurce does not increase the mean distance a paritcle travels, if the traversted density stays the same. However, large gradients will be taken into account in the calculation. Hence, the distance a particle moves is not over- or underrated when moving into higher or lower density regions respectivly. However, the density fields need a higher resolution than the density difference, which increases the simulation time. Thus, the user needs to evaluate the tradeoff between simulation time and accuracy. +The movement of particles is outsourced to the mover class. It moves the particle dependent on the E/B fields at the position of the particle, given the integrated distance a particle will move, see section~\ref{ssec:general_diagram}. The movement itself is subdivided into in smaller steps. This way, it can be evaluated if the particle has left the simulation domain between the steps, which stops the movement. Apart from the simulation boundary, the movement is stopped if the particle leaves a segment or energy bin of the density fields, see section~\ref{ssec:denstiy_fields}. No interaction will be performed afterwards, but a new distance will be rolled from the MFP at the new position of the particle, see equation~\ref{eq:distance_from_mfp}. This procedure does not increase the mean distance a particle travels, if the traversed density stays the same. However, large gradients will be taken into account in the calculation. Hence, the distance a particle moves is not over- or underrated when moving into higher or lower density regions respectively. However, the density fields need a higher resolution than the density difference, which increases the simulation time. Thus, the user needs to evaluate the trade off between simulation time and accuracy. The stop of the movement if a particle has left a density field segment has an additional benefit: it can be easily evaluated how long a particle has stayed in the segment. Each movement step the particle is alive, a counter variable is increased by the time the movement step took. If the movement is stopped this counter variable can be added to the corresponding density field segment. @@ -223,11 +254,11 @@ Two different kinds of movers are implemented (Boris, Drift), which differ in th The boris mover uses the boris push algorithm \citep{Penn.2003} for the movement step described in the previous paragraph (see \citep{Kellerer2022_1000143868} for a in depth description of the boris push algorithm). However, the steps are not chosen by a given length but a given timestep $\Delta t$, which is needed as an input for the boris push algorithm. The moved distance is calculated after the movement algorithm. This moved distance is then substracted from the total distance the particle has still to move. When this distance is smaller than zero the movement will be ended. -The timestep has to be provided by the user. It should be oriented on the highest gyro frequency possible in the simulation domain $\Omega_{g,\text{max}}$ and fulfill +The timestep has to be provided by the user. It should be oriented on the highest gyro frequency possible in the simulation domain $\Omega_{g,\text{max}}$ and fulfil \begin{equation} - \Delta t < \frac{1}{\Omega_{g,\text{max}}} \fullstop + \Delta t < \frac{1}{\Omega_{g,\text{max}}} \fullstop \end{equation} -This timestep is also used for the determination of the time a paritcle spends in a density field segment, see previous section. +This timestep is also used for the determination of the time a particle spends in a density field segment, see previous section. The boris push algorithm was chosen, because it is numerically stable with high precision and efficiency \citep{Kilian.2015}. The method can be used for low relativistic particles, up to a gamma factor of $\gamma \approx 1000$ \citep{Vay.2008}. At the KATRIN experiment, only electrons of energies up to \SI{32}{keV} (Krypton conversion electrons) are created. This results in a gamma factor of $\gamma = 1.06$, which is well below the limit of the Boris push. @@ -241,51 +272,51 @@ The position change is described by the movement around the gyro centrum $\Delta The drift movement of the gyro centrum is calculated from the $E \times B$ drift velocity \begin{equation} - \vec{v}_\text{D} = \frac{\vec{E}\times \vec{B}}{\abs{\vec{B}}} + \vec{v}_\text{D} = \frac{\vec{E}\times \vec{B}}{\abs{\vec{B}}} \end{equation} and the timestep length $\Delta t$ \begin{equation} - \Delta t = \frac{\Delta x}{\abs{\vec{v}_\parallel} + \abs{\vec{v}_\perp} + \abs{\vec{v}_\text{D}}} \commaeq + \Delta t = \frac{\Delta x}{\abs{\vec{v}_\parallel} + \abs{\vec{v}_\perp} + \abs{\vec{v}_\text{D}}} \commaeq \end{equation} where $\Delta x$ is the step length of the movement step and $\vec{v}_\parallel$ and $\vec{v}_\perp$ the velocity parallel and perpendicular to the magnetic field. The moved distance through the drift motion evaluates the to \begin{equation} - \Delta \vec{x}_\text{D} = \Delta t \cdot \vec{v}_\text{D} \fullstop + \Delta \vec{x}_\text{D} = \Delta t \cdot \vec{v}_\text{D} \fullstop \end{equation} The movement of the gyro centrum parallel to the magnetic field is calculated from \begin{equation} - \Delta \vec{x}_\parallel = \Delta t \cdot \vec{v}_\parallel \fullstop + \Delta \vec{x}_\parallel = \Delta t \cdot \vec{v}_\parallel \fullstop \end{equation} The position change around the gyro centrum is calculated in three steps. First, the gyro radius is determined \begin{equation} - r_\text{g} = \frac{m \abs{\vec{v}_\perp}}{q \abs{\vec{B}}} \commaeq + r_\text{g} = \frac{m \abs{\vec{v}_\perp}}{q \abs{\vec{B}}} \commaeq \end{equation} from the perpendicular velocity, the particle mass $m$ and charge $q$, which in turn is then used to determine the vector from the particle to the gyro centrum $\vec{x}_\text{pc}$ \begin{equation} - \vec{x}_\text{pc} = - r_\text{g} \frac{\vec{v}_\parallel \times \vec{v}_\perp}{\abs{\vec{v}_\parallel \times \vec{v}_\perp}} \fullstop + \vec{x}_\text{pc} = - r_\text{g} \frac{\vec{v}_\parallel \times \vec{v}_\perp}{\abs{\vec{v}_\parallel \times \vec{v}_\perp}} \fullstop \end{equation} Second, the gyro frequency is calculated through \begin{equation} - \omega_\text{g} = \frac{q \cdot \abs{\vec{B}}}{m} \fullstop + \omega_\text{g} = \frac{q \cdot \abs{\vec{B}}}{m} \fullstop \end{equation} The gyro frequency is then used to calculate the relative angle change towards the gyro centrum \begin{equation} - \Delta \theta = \Delta t \cdot \omega_\text{g} \fullstop + \Delta \theta = \Delta t \cdot \omega_\text{g} \fullstop \end{equation} Third, the movement of the gyro centrum is calculated by the rotation of $\vec{x}_\text{pc}$ around $\vec{v}_\parallel$ with the angle of rotation $\Delta \theta$ through Rodriges' rotation formula. In total, the position changes calculates to \begin{equation} - \Delta \vec{x} = \Delta \vec{x}_\text{c} + \Delta \vec{x}_\parallel + \Delta \vec{x}_\text{D} \fullstop + \Delta \vec{x} = \Delta \vec{x}_\text{c} + \Delta \vec{x}_\parallel + \Delta \vec{x}_\text{D} \fullstop \end{equation} The velocity after movement is determined by the acceleration of the particle through the electric field $\Delta \vec{v}_\text{E}$, through the rotation of the perpendicular velocity around the gyro center $\vec{v}_\perp^\text{rot}$ and the initial parallel velocity \begin{equation} - \Delta \vec{v} = \vec{v}_\parallel + \Delta \vec{v}_\text{E} + \vec{v}_\perp^\text{rot} \fullstop + \Delta \vec{v} = \vec{v}_\parallel + \Delta \vec{v}_\text{E} + \vec{v}_\perp^\text{rot} \fullstop \end{equation} The acceleration through the electric fields calculates to \begin{equation} - \Delta \vec{v}_\text{E} = \Delta t \frac{q \vec{E}_\parallel}{m} \commaeq + \Delta \vec{v}_\text{E} = \Delta t \frac{q \vec{E}_\parallel}{m} \commaeq \end{equation} where $\vec{E}_\parallel$ is the electric field parallel to the magnetic field. @@ -294,219 +325,171 @@ The rotation of the perpendicular velocity is again calculated using Rodriges' r \subsection{Termination} \label{ssec:termination} -- class to determine if particle needs to be terminated \\ -- three types currently: \\ -- left simulation domain given by geometry (currently only cylinder geometry) \\ -- reached max interactions \\ --> stored particle are neglected but makes simulations more controllable \\ -- reached max time alive\\ --> stored particles are neglected, but plasma mostly on short timescales -> large timescales are not as relevant\\ - -- Deletion logger:\\ -- additional output for debugging\\ -- used when particle is deleted and saves information\\ -- currently: wall, max it, max time, rec, cluster formation\\ -- rec, cluster next section\\ +The termination of particles is addressed by the terminator class. It checks for three different conditions. First, if the particle has left the simulation geometry. For the KATRIN experiment the geometry can be approximated by a cylinder. However, the radius and height can provided by the user for special analysis. Second, the terminator class checks if the particle has exceeded the user defined number of maximal interactions. This counter was added, to ensure that no trapped particles are tracked by the simulation. Otherwise the simulation would not end. This trap can occur for example through opposite neutral gas flow and reflection. Third, the terminator class checks if the particle has exceeded the user defined lifetime. This counter ensures, that particles are not stored indefinitely. This could occur through special configuration of magnetic and electric fields. +In addition to the terminator class, the user can choose to add a deletion logger to the specie class. This class is evoked if the particle is deleted. It stores information on the type of deletion, namely if the particle has hit a wall, recombined, formed a cluster, or exceeded the maximum time alive or maximum number of interactions. These values are also added to the output of the simulation. So, the can either be used for debugging, but they can also be used for physical results. For example, the number of recombinations provides an insight if recombination is a dominant process. \subsection{Interactions} \label{ssec:interactions} -- class which includes everything relevant for interaction of particles: cross section (used in mfp and interaction selection), interaction itself\\ -- creates interaction output, namely all particles, which result of the interaction (new particles, and also recombination)\\ -- base class is interface, derived implement details\\ --> easily extendable\\ --> use same interactions for different species (elastic scattering)\\ -- always cross section and target specie necessary (background or tracked)\\ -- cross section only dependent on energy\\ --> 1d functional\\ -- can be easily extended, and own custom function without limitation\\ -- predefined functions from literature\\ -- selectable by user\\ --> useful for tests of implementation, but also different models\\ +Interactions of particles are processed in the interaction class. Additionally, it is used to provide access to the cross section of the interaction and the macroscopic cross section, which can be used in the calculation of the MFP and in the selection of the interaction, see section~\ref{ssec:general_diagram}. The interaction class itself is an interface class. The details of the interaction are implemented in the derived classes. This way it is easy to add more types of interactions in the future. All interactions are initiated using a given cross section and target specie. For the cross section, we decided to use a one dimensional functional. This way the user can either specify an implemented cross section to be used, or can also provide an own function in the configuration file, see section~\ref{ssec:initialization}. The target specie can either be a tracked or background specie. This allows for a high flexibility of the interaction class. + +Currently there are seven types of interactions implemented: elastic scattering, clustering, recombination, free movement, charge exchange, excitation, ionization. In general, all types can the added to all species. However, the user has to decide if the specific use is sensible. In the following, the implementation of each interaction will be described. For the physical explanation, please refer to \citep{Kellerer_2022}. -- types of interaction:\\ -- elastic scattering\\ -- clustering\\ -- recombination\\ -- free movement\\ -- charge exchange\\ -- excitation\\ -- ionization\\ +\paragraph{Elastic scattering} +The elastic scattering class is initiated using the cross section, the target specie and a scattering angle distribution. This distribution can be used to roll a scattering angle, given the energy of the incoming particle. It can be set to an isotropic distribution, to a distribution provided by a file and a composite of distributions. For the distribution from a file, the angle distribution has to be provided given an energy binning. During evaluation of the scattering angle, the corresponding energy bin is determined and the corresponding angle distribution selected. The composite of distributions is used in cases, where there is data for a certain energy range, but not in the other. This is the case for the scattering of electrons of tritium molecules. At high energies, the scattering angle distribution is determined from external simulation \citep{Kellerer_2022}, at lower energies isotropic scattering is assumed. -- all types applicable to electrons but also ions (no restrictions)\\ +The interaction itself is performed in multiple steps. First, the velocity of a target particle is determined. It is compound of the drift velocity of the species and a velocity, which is rolled from the underlying velocity distribution. For the tritium gas, the drift velocity is determined in external simulation and the velocity distribution is given by a Maxwell-Boltzmann distribution \citep{Kellerer_2022}. For tracked particles the drift velocity is assumed to be zero and the velocity distribution is given by the density field. The velocity of the target particle is used to determine the impact energy in the laboratory frame. This energy is then used for the evaluation of the azimuthal scattering angle $\theta$. A second scattering angle is rolled in the interval $[0, 2\pi)$, responsible for the change of momentum in polar direction. Both angles and the target velocity are then used to rotate the velocity vector of the impact particle in the center of mass frame, see \citep{Kellerer_2022} for the full calculation. This rotated velocity is then used as the new velocity of the impact particle. -- elastic scattering\\ -- cross section, target, and scattering angle\\ -- roll interaction partner\\ -- transformation to laboratory frame -> energy\\ -- rotation of vector along scattering angle (energy), 2 pi in cm frame\\ +\paragraph{Clustering} +The clustering class is initiated using the cross section, the target specie and the specie, which is the result of the clustering process. In the interaction itself it is assumed that the new particle follows the direction of movement of the target particle, but with different absolute velocity. The new absolute velocity is calculated from the velocity of a target particle and the new particles mass. The velocity of a target particle is determined analogue to its calculation in elastic scattering. -- clustering\\ -- cross section, target, product\\ -- get velocity of target\\ -- calculate energy of target\\ -- use same direction, but scale velocity to mass of product\\ -- get new particle at same position, but with new velocity\\ +\paragraph{Recombination} +The recombination class is initiated using the cross section and the target specie. The interaction itself has only two steps. First, the target density field logs one deletion at the corresponding position, see section~\ref{ssec:denstiy_fields}. Second, the impact particle is marked for deletion. -- recombination\\ -- only delete particle, and count deletion in density field (see sec ...)\\ +\paragraph{Free movement} +The free movement interaction is only a helper class, which is necessary to be used if no other interaction should be used. It provides the simulation with a very small cross section, which results in a very large mean free path. This large mean free path guarantees a free movement through the simulation domain. If the interaction step is evoked for a particle nothing is done. -- free movement\\ -- do nothing (but necessary, if no other interaction given -> very large mfp provided)\\ -- cross section at numerical limits\\ +\paragraph{Charge exchange} +The charge exchange class is initiated using the cross section and the target specie. No product specie is necessary, because product and impact specie are the same. In the interaction, only the velocity of a target particle is determined, analogue its calculation in elastic scattering. This velocity is then used as the new velocity of the impact particle. -- charge exchange\\ -- cross section and target\\ -- no product, because product is same specie as particle\\ -- only determine velocity of target (from distribution of specie)\\ -- use velocity of target for new particle\\ +\paragraph{Excitation} +The excitation class is initiated using the cross section, the target specie and the excitation energy. In the interaction itself, first the velocity and direction of movement of the impact particle is determined. Second the kinetic energy of the particle calculated and reduced by the excitation energy. Lastly, the new velocity is determined from the reduced energy and direction of movement. This is a simple but effective method for excitation processes. However, no scattering is considered here. This is justifiable, because excitation processes are often much more unlikely than elastic scattering processes und therefore scattering angle effects do not play a significant role. -- excitation\\ -- cross section, target, excitation energy\\ -- determine vel dir of particle\\ -- reduce energy by excitation energy\\ -- simple but effective\\ -- no scattering angle etc.\\ +\paragraph{Ionization} +The ionization class is initiated using the cross section, the target specie, the new electron specie, the new ion specie, the ionization energy and distribution and the scattering angle distribution. It is developed for ionization of the target specie by impact of a particle, which is much lighter than the target. However, the code does not check for this condition. -- ionization\\ -- cross section, target, (new) electron, new(ion), ionization energy distribution, angle distribution\\ -- roll target particle\\ -- transform into laboratory frame\\ -- energy could be below ionization energy\\ -- roll new target particle until energy above ionization\\ -- could take long time, but cross section decreases significantly before ionization energy\\ -- roll new impact energy from distribution\\ -- ejected particle (electron) energy rel to total energy and ionization energy\\ -- ejected vel from angle distribution (rotation)\\ -- backtransformation of lab frame\\ -- ejected ion uses target velocity\\ --ignores recoil, but large mass difference\\ -- might be different for ion ionization (but not used in code)\\ +In the interaction, first the velocity of a target particle is determined analogue to its calculation in elastic scattering. Then, the impact energy in the laboratory frame $E_\text{i}$ is calculated. If the impact energy is below the ionization energy $E_\text{ion}$, no ionization could occur and a new target particle velocity is rolled. This procedure can take a long time. However, the cross section of ionization decreases significantly before the ionization energy. Thus, very few particles with energies close to the ionization energy will undergo ionization, which will therefore not increase the simulation time significantly. When a suitable target particle velocity is determined, the impact energy is used in the ionization energy distribution to roll the impact energy after collision $E_\text{i}^\text{new}$. The energy of the new electron $E_\text{e}$, also called ejected electron in the following, then follows through +\begin{equation} + E_\text{e} = E_\text{i} - E_\text{ion} - E_\text{i}^\text{new} \fullstop +\end{equation} +Next, the direction of movement has to be determined. For both the impact particle and the ejected electron, the direction of movement is calculated as a rotation of the impact velocity in the laboratory frame by the polar and azimuthal angle, with scaling of their kinetic energy respectively. The polar angle of the impact particle $\phi_\text{i}$ is rolled in the interval $[0,2\pi)$. The ejection direction of the new electron is set to the opposite direction. Thus, the polar angle of the ejected electron $\phi_\text{e}$ is calculated from +\begin{equation} + \phi_\text{e} = \phi_\text{i} - \pi \fullstop +\end{equation} +The azimuth angle of both particles is calculated, using the derivation of \citet{Grosswendt:1978aa}. Lastly, the velocity of the ejected ion is set to the velocity of the target particles, assuming no recoil of the target particle in the interaction. As described before, this assumes a large mass difference of the impact particle and the target particle, which is the case for the dominant process in the source: ionization of tritium gas by electron impact. -\subsection{Cross sections} -\label{ssec:cross_sections} - -- dunno what here? \\ - +%\subsection{Cross sections} +%\label{ssec:cross_sections} +% +%- dunno what here? Leave it out for now \\ \subsection{Calculation of fields} \label{ssec:field_calculation} -- density fields for each specie as its own class\\ -- time spend in bin, deletions, density as calculated in eq (above) in 4d arrays\\ -- fast axis: 3 (energy), easy to evaluate density at position (mfp)\\ -- next axis: 2 (z), longitudinal problem\\ -- next axis: 1 (phi), magnetron drift\\ -- last: radial: most likely slowest movement change\\ -- updated after movement (only in bin)\\ +The density fields are implemented as a class. Each specie holds its own member of this class, which simplifies the evaluation of the fields during the simulation, for example for the calculation of the MFP. The class holds its information in member variables, which are the time particles of the species have spend in a segment of the source, the number of recombination in this segment and the derived density itself. They are represented as four dimensional arrays. The fastest axis (third axis) is used for the different energy bins. This reduces the calculation time of the determination of the density in a segment, which is mainly a sum over all energy bins. It is evoked multiple times during the particle update, which requires a fast calculation. The use of the other axis follows the consideration of how often the bin changes in longitudinal, azimuthal and radial direction. The magnetic field is most commonly aligned in longitudinal direction. Thus, the particles mostly travel in longitudinal direction. Therefore, the second fastest axis is used for the longitudinal direction. The other two directions are similar in their usage. Because of the magnetron drift in radial inhomogeneous magnetic fields, it was decided to use the azimuthal direction next, followed by the radial direction. -- size of array predefined, with overflow\\ -- for debugging\\ -- own Binning and energy Binning\\ -- can be different for each specie -> resolution of important effects\\ -- needs simulation timer\\ -- from number of injections\\ +The size of the arrays is derived from the user input. It is calculated from the desired number of segments and a build in under- and overflow. This way, if a particle can not be classified into one of the segments, the information is still recorded in the simulation. The energy bins are created in logarithmic scale with one bin each for under- and overflow. It can be set differently for each specie. Thus, important effects for each specie can be resolved more easily. In longitudinal direction, the bins are divided evenly with one bin each for under- and overflow. In general, these under- and overflow bins should not be filled during the simulation, because this would mean that a particle has left the simulation domain and is still alive. Hence, they can be used for debugging purposes. In radial direction, there is only an overflow bin, because the radius is lower bound to zero. In azimuthal direction no over- and underflow bins are used, due to the circular nature of the problem. -- easy and fast to evaluate\\ -- during simulation for mfp calculation\\ +The calculation of the density needs also the physical time, see equation~\ref{eq:target_field_density}. This time is provided by a pointer to a timer class. This class is called, when new particles are injected in the simulation domain, see section~\ref{ssec:injection}, and thus the physical time increases. + +The current collector is structured similar to the density field class. The difference being, that it holds instead the crossings in positive and negative direction through the predefined faces in three dimensional arrays for crossings in longitudinal, azimuthal and radial direction. The faces can be aligned to the segmentation of the density fields, but can in general be set to its own segmentation. However, the mover uses both the density fields and current collectors to evaluate possible endpoints of movement, see section~\ref{ssec:movement}. Thus, a different segmentation will lead to a longer simulation time. -- similar with current collection\\ -- positive and negative crossings (not energy resolved) -> 3d array\\ -- but for radial, longitudinal, azimuthal\\ -- size dependable on density field resolution\\ -- not specific for calculation, but easy in mover (end of movement)\\ -- needs also simulation timer\\ \subsection{Injection} \label{ssec:injection} -- used for initial particles in simulation\\ -- from given energy and angular distribution\\ -- position distribution\\ -- eg. beta particles:\\ -- isotropic\\ -- fermi distribution\\ -- eg. T2+\\ -- isotropic\\ -- thermal distribution\\ -- but also directed\\ -- for test purposes\\ -- electron gun\\ -- currently many particles created at same position (particle decay) -> same time passed\\ -- extension possible through multiple injections at same time, but relative factor of activity\\ +The injection of new particles to the particle queue is managed by the injector class. It is initiated by providing the event position distribution, the mother drift velocity and a list of species, with their energy and injection angle distribution. The event position distribution is used to determine the position, at which the new particles are to be injected. For each injected specie, the kinetic energy is rolled through the energy distribution. The corresponding velocity vector is rolled from the injection angle distribution and scaled by the kinetic energy. This velocity is then boosted by the mother drift velocity, which represents the movement of the decaying gas. + +In the case of the KATRIN source, the injected species are electrons, with an isotropic injection angle distribution and a Fermi energy distribution \citep{Fermi:1934aa} and T2+ ions, also with an isotropic injection angle distribution, but with a Maxwell-Boltzmann energy distribution. The mother drift velocity is provided by the drift velocity of the neutral tritium gas. + +However, the injector class can also be used for the injection of a stream of directed particles. This is necessary, either for the evaluation of the influence of a electron gun in the experiment, or for test purposes. + +After the injection of particles, the timer class is provided with a time, which has passed between injections. This time is based on the user defined activity. It can be calculated from the integrated density in the source and the decay constant. + + +\subsection{Parallelization} +\label{ssec:parallelization} + +In order to obtain reasonable and robust results of the simulation, high statistics is necessary. This is especially the case, if also improbable effects like the excitation by rotation, should be visible in the results. The goal of high statistics can be reached by parallel computation. For the code, a simple parallelization strategy was used. The desired number of decays are distributed evenly on the cores, and each cpu follows the simulation loop (see section~\ref{ssec:general_diagram}) independent from the other. The general setup of the simulation stays the same between cpu. However, a asset of the code is, that the Monte Carlo events of each particle track can be dependent on the other, for example in the case of recombination. In order to obtain this strong point, the number of desired events per cpu are further subdivided into cycles with a fixed length. After each cycle, a synchronization step between the cpus is initiated. During the synchronization step, the data on the density fields is shared among all cpus. Since the simulation is set up the same for all cpus, this step only needs an additive operation on the array of cumulated times, see section~\ref{ssec:denstiy_fields}, and an additive step, to share the passed time. Additionally to the density field synchronization, also the data of the current borders and deletion loggers are synchronized, which is not strictly necessary, but keeps the data congruent on all cpus and makes the output step easier, see section~\ref{ssec:output}. + +The benefit of this parallelization scheme lies in its simplicity. It is easy to include more cpus for the calculation. Only the synchronization step takes slightly longer. However, the main simulation effort lies in the movement and interaction step. Thus, the synchronization does not play a significant role. Further more, there is no need of a cpu, which directs tasks to the other cpu. Hence, little communication and data exchange is necessary between cpu, which saves calculation time. + +The simplicity of the method also produces some drawbacks. First, the load on the cpus can be different even though the number of events was set to the same value because of the creation of new particles through ionization. However, if the cycle length is chosen large enough, the load can balance out. The specific choice of cycle length depends on the simulated problem and has to be chosen by the user. + +%- scaling graph?\\ +%- simulation time per decay vs cpu number\\ +%- sim with cpu * n decyas\\ + +\subsection{Output} +\label{ssec:output} + +The output of the simulation is written to a single HDF5 file %todo citation +, which allows for extendable, structured data storage. Output is performed in two different modes. First, it is enacted after the initialization phase of the simulation to write non-changing data to file for each of the tracked specie. This includes for example, the mass and charge of the species, the volumes and surface areas of the segmentation and the number of bins. Second, the output is performed to write the simulated data (from density fields, current collector, deletion logger) to file. This step is performed after each cpu synchronization, see section~\ref{ssec:parallelization}. In general, only the last output is of interest for the user. However, the steps in between can be used for debugging. Additionally, if the user has not set the correct wall time at the programming cluster an intermediate result is available. Thus, the user can decide for each specie and output type (density field, current collector, deletion logger) the output interval and if the new data of the step should be saved separately or if the data of the old step should be overwritten. The latter saves disk space. Nevertheless, the size of the output file is comparably small, since it holds only derived properties. Depending of course on the number of segments chosen by the user. \subsection{Initialization} \label{ssec:initialization} -- from json file\\ -- each class uses own generator from input\\ -- easy to test\\ -- easy to modify\\ -- extensible\\ -- composite classes\\ -- call corresponding generator\\ -- all constructed in simulation class constructer\\ +The initialization of the simulation it administered by the simulation class using generators which are available for classes, which need special user input. The specific build instructions have to be provided in a JavaScript Object Notation (JSON) file. Due to its hierarchical structure, it is easy to read, test and extend by the user, even with little programming experience. We use the jansson library %todo citation +to read the file into the code. -- scalar field for density\\ -- different types\\ +The JSON file is structured, such that each of the sections corresponds to one main idea of the code or class. Subsections are used, when the class is a composite of other classes. This way the parameter file stays extensible in the face of new methods and classes, which will be added in the future. A collection of JSON files for each generator is provided together with the code for easy usage. A selections of generators will be discussed in the following. -- vector field for drift velocity, E/B-field\\ -- different types\\ +If energy or length values are to be input by the user, the corresponding value has to be provided by its value and its unit. An automatic unit conversion will be taken care of by the program. Currently there are conversions available for \SI{}{cm}, \SI{}{mm} and \SI{}{m}, and for \SI{}{J} and \SI{}{eV}. + +\paragraph{Functions} +Functions are an integral part of the code, used for example to express cross sections. There are two types of functions implemented: a mapping of $\mathbb{R} \to \mathbb{R}$, called later on 1D-function or a mapping of $\mathbb{R}^3 \to \mathbb{R}$, called later on 3D-function. + +\paragraph{Scalar field} +Scalar fields represent the idea, that for every point in space a certain value can be assigned. The scalar field can currently only be initiated through one option, namely the \textit{ScalarFieldFunctionInZ}. As the name suggests, it returns values, which are provided through a 3D-function. The general input of coordinates are transformed to cylinder coordinates $(r, \phi, z)$ and the corresponding function value is returned. + +\paragraph{Vector field} +Vector fields represent the idea, that for every point in space a certain three dimensional vector can be assigned. The vector field can be initiated through three different options: \textit{VectorFieldConstant}, \textit{VectorFieldFunctionInZ} and \textit{VectorFieldFromArray}. For all three types, the general input of coordinates are transformed in the class to cylinder coordinates $(r, \phi, z)$ and the corresponding vector is calculated and returned. + +\begin{itemize} + \item \textit{VectorFieldConstant}:The return value of the vector field does not depend on its input and a constant vector is returned. + \item \textit{VectorFieldFunctionInZ}: The returned vector only points in z direction. The norm of the vector is provided by a 3D-function. + \item \textit{VectorFieldFromArray}: The returned vector is provided by precalculated values in arrays. The option \textit{radius} and \textit{height} is used together with the array size to define a cylindrical binning. The input coordinate is transformed to a bin coordinate, which provides the index in the array. If the given coordinates is outside of the defined binning, a zero vector is returned. +\end{itemize} + +\paragraph{Velocity distribution} +The velocity distribution represents the idea, that a velocity vector can be sampled for each point in space. Currently there is only one type of distribution implemented, the \textit{VelocityDistributionFromFunction}. However, in cases, where a velocity distribution is needed for a constructor but it will never be used a 'null' option is also available. For the \textit{VelocityDistributionFromFunction}, the velocity is sampled from a predefined function, the \textit{VelocityDistributionFunction}. Here, two options are available, the \textit{IsotropicDistribution} and the \textit{DirectedDistribution}. Both have in common, that first an energy is sampled from an given energy distribution. However, for the \textit{DirectedDistribution} this energy is used to scale a predefined direction vector using a predefined mass. For the \textit{IsotropicDistribution} the direction of movement is sampled from an isotropic distribution and then scaled to represent the correct energy. The mass can either be derived from a given particle type, or directly given as a value. + +There are three different energy distributions available in the code, the electron energy distribution of tritium decay (\textit{TritiumBetaDecay}), the Maxwell Boltzmann distribution (\textit{MaxwellBoltzmann}) and a constant distribution (\textit{Constant}). +\begin{itemize} + \item \textit{TritiumBetaDecay}: The energy is rolled using the known Fermi distribution \citep{Fermi:1934aa} and the rejection method. + \item \textit{MaxwellBoltzmann}: The energy is rolled using the built in gamma distribution and an user defined temperature. + \item \textit{Constant}: A single energy is returned for all calls to the class. +\end{itemize} + +% \paragraph{Drift velocity} +% The drift velocity represents the idea, that a particle species travels at this speed on average. It is mostly used for the background species, but a 'null' option is also available for the construction of tracked species. The drift velocity has to be provided by a vector field. + +% \paragraph{Terminator} +% A terminator class member each, see section~\ref{ssec:termination}, is created for all tracked species. The number of maximum interactions has to be provided, alongside the maximum time alive. Additionally, a geometry has to be provided, which defines if the particle has left the simulation domain. Currently there is only one geometry available, the cylinder. It is defined by its radius and its height. + +% \pararaph{Reflector} +% The reflector represents the idea, that a particle is reflected by process, which is outside of the simulation domain. It is provided to each of the tracked species. Therefore, there is also the option of \textit{NoReflector} if no reflection is necessary. Currently there is only one other option implemented: the \textit{ReflectorDPS}. It provides the means to reflect particles, which have crossed a maximum z value, given by the user. + + +\paragraph{Simulation} + +In the simulation section, one can set the number of simulated events over all cpus (\textit{SimulatedEvents}). For KATRIN these events symbolize tritium decays. The events are distributed evenly on all cpus. The parameter \textit{EventStride} is used to define the number of events after which the density field data is synchronized between the cpus. Also, output could be performed here. + +\paragraph{Output} +In the output section, it is defined, where the output file is stored and with which filename. The folder is given relative to the home folder of the user or can be given as an absolute path. Additionally, the output specifics are defined in this section for each of the simulation data, density fields, current borders and deletion logger. + +\begin{itemize} + \item \textit{Intervall}: defines how often an output should occur. This can either be set to \textit{EachSync}, so each time the cpus are synced the output is performed, or to a positive integer value. This value specifies the rate of output. So the number two would correspond to an output every second cpu synchronization step. + \item \textit{OverwriteLast}: defines if each output should be stored on disk, or if each new output overwrites the last + \item \textit{Species}: defines for which specie the output should be performed. It can either set to \textit{all}, or to a list of species given their specie name in the parameter file, eg. $[\text{electron}, \text{T2+}]$ +\end{itemize} + +\paragraph{RandomNumbers} +In the random numbers section, the seed for the pseudo random numbers is set. It is used for the initialization of the random numbers of the first cpu. All following cpus gain a seed given by the sum of the seed of the first cpu and its cpu rank. + +\paragraph{Species} + +In the species section, all relevant information on the species used in the simulation is provided. It is subdivided into a section for the background species and tracked species. A specie is added to the simulation provided a unique key name and the necessary data, which is different for background species and tracked species. However, both sections need to specify the \textit{ParticleType}, which can either be 'electron', 'T2+', 'T3+', 'T+' or 'T2'. This defines the mass and charge of the specie. Futhermore, background species need three sections to be initialized (\textit{ConstantDensityField}, \textit{VelocityDistribution} and \textit{DriftVelocity}), while tracked species need nine (\textit{Mover}, \textit{Terminator}, \textit{Reflector}, \textit{DensityField}, \textit{VelocityDistribution}, \textit{DriftVelocity}, \textit{Loggers}, \textit{CurrentCollector}, \textit{Interactions}). \subsection{Particle queue} \label{ssec:particle_queue} -nothing special here, so maybe out\\ - -- particles are added one after the other\\ -- could have been done all at once\\ -- but paritcles can interact with each other\\ -- thus primary particles would be less likely to interact with secondary paritcles -> one after the other\\ - -\subsection{Output} -\label{ssec:output} - -- simulation subdivided into cycles\\ -- each cycle performs simulation loop\\ -- followed by cpu sync and output\\ -- output to hdf5 file\\ -- extendable\\ -- ordered\\ -- selectable output for Density fields, current borders and deletion logger\\ -- for each entry\\ -- which specie (reduce output time)\\ -- output interval (after how many cycles, reduce output time)\\ -- overwrite\\ -- entry for each output process, or one overwriting\\ -- debugging\\ -- save space\\ - -\subsection{Parallelization} -\label{ssec:parallelization} - -- Monte carlo method based on high statistics\\ -- simple parallelization scheme\\ -- devide number of decays evenly per cpu\\ -- each cpu works on these decays\\ -- cpu sync after simulation cycle (see output)\\ -- sync currents borders, fields and deletion loggers\\ -- simple additive operation for all (see eq.. ), Allreduce\\ -- same load for all cpus\\ -- also passed time additive\\ -- might have different loads for cpus, because of creation of new particles (ionization)\\ -- but with high enough decays in cycle balances out\\ -- no need for directing cpu\\ -- in principle extendable to as many cpus as needed for statistics\\ -- only bound by rec effects if too few decays per cycle\\ -- otherwise no limitations\\ - -- scaling graph?\\ -- simulation time per decay vs cpu number\\ -- sim with cpu * n decyas\\ +The queue used in the simulation to keep track of the simulated particles is no queue in the classical sense. Similar to a classical queue, particles are added to the end of the queue, when they are created through injection or by interactions like ionization. However, the next particle to simulate after the old one was deleted is not drawn from the bottom of the queue but at random from all particles in the queue. This decision was made, because the single events can be dependent on each other through the density fields and a bias towards injected particles should be avoided, especially because the injected particles have mostly higher energies than the others. Hence, it was decided to store the particles in a standard library vector. % todo: citation +To save computation time, the vector is initialized with a size of 100 elements, which marks a rough estimate of an upper limit on new particle per particle loop at standard KATRIN conditions. \section{Physical processes} \label{sec:physics} @@ -521,7 +504,102 @@ nothing special here, so maybe out\\ \section{Parameter file} + +\begin{lstlisting}[language=json,firstnumber=1,caption={Linear 1D-function between given x and y pairs, scaled by the prefactor. If a x value below/above the first/last xValue is ordered the first/last yValue is returned.}] + "PiecewiseLinear": { + "xValues": [0, 1.43, 3], # sorted values only + "yValues": [5E-4, 0.002, 0.02], + "prefactor": 1 + } + \end{lstlisting} + +\begin{lstlisting}[language=json,firstnumber=1,caption={1D-function, which returns a constant value.}] + "Constant": { + "constant": 1 + } + \end{lstlisting} + +\begin{lstlisting}[language=json,firstnumber=1,caption={1D-function, which returns the product of the provided functions.}] + "Product": [ + {"Constant": { "constant": 2 }}, + {"Constant": { "constant": 3}} + ] + \end{lstlisting} + +\begin{lstlisting}[language=json,firstnumber=1,caption={1D-function, which loads x and y data from a hdf5 file and uses it, same as a PiecewiseLinear function.}] + "PiecewiseLinearFromFile": { + "PathToH5": { + "Type": "RelativeToHomebase", # HOMEBASE defined before in build process + "RelativePath": "path/relative", # without leading or trailing / + "Filename": "data.h5" + }, + "xValuesKey": "/xvalues", # key in file + "yValuesKey": "/yvalues", # key in file + "prefactor": 1 + }, + "PiecewiseLinearFromFile": { + "PathToH5": { + "Type": "AbsolutPath", + "RelativePath": "/some/absolut/path", # without trailing / + "Filename": "data.h5" + }, + "xValuesKey": "/xvalues", # key in file + "yValuesKey": "/yvalues", # key in file + "prefactor": 1 + } + \end{lstlisting} + +\begin{lstlisting}[language=json,firstnumber=1,caption={3D-function, which returns a constant value}] + "Constant3D": { + "constant": 2 + } + \end{lstlisting} + +\begin{lstlisting}[language=json,firstnumber=1,caption={3D-function, which returns the product of three 1D-functions: \\$f(x,y,z) = f_i(x)\cdot f_j(y) \cdot f_k(z)$}] + "Product": { + "fi": { "Constant": {"constant": 2 }}, + "fj": { "Constant": {"constant": 2 }}, + "fk": { "PiecewiseLinear": { + "xValues": [0, 1.43, 3], + "yValues": [5E-4, 0.002, 0.02], + "prefactor": 1 } + } + } + \end{lstlisting} + +\begin{lstlisting}[language=json,firstnumber=1] + "VectorFieldConstant": { + "Constant": { "vector": [1, 2, 3]} + } + \end{lstlisting} + +\begin{lstlisting}[language=json,firstnumber=1] + "VectorFieldFunctionInZ": { + "zFunction": { + "Constant3D": {"constant": 2} + } + } + \end{lstlisting} + +\begin{lstlisting}[language=json,firstnumber=1] + "VectorFieldFromArray": { + "ReadArrayFromFile": { + "PathToH5": { + "Type": "RelativeToHomebase", + "RelativePath": "path/relative", + "Filename": "filename.h5" + }, + "Keys": ["/vr", "/vphi", "/vz"] # keys in file + }, + "Radius": 0.045, + "Length": 16 + } + \end{lstlisting} + \section{Acknowledgments} +Nemo + + % % %MPI 1.1 support was provided by the Open MPI implementation under the BSD-new