Skip to content

Instantly share code, notes, and snippets.

@marquezj
Created September 19, 2017 15:31
Show Gist options
  • Save marquezj/625407e8ff60fb4b41f1bf8f8db6a6c3 to your computer and use it in GitHub Desktop.
Save marquezj/625407e8ff60fb4b41f1bf8f8db6a6c3 to your computer and use it in GitHub Desktop.
This is a tutorial on how to install and run NJOY2016 with NCrystal
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:056c3f0c4133555b5b1c7707e4eb05b27c745124de38c29d96a877311615b862"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## NJOY-NCrystal Tutorial"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This is a tutorial on how to install and run NJOY2016 [1] with NCrystal [2]\n",
"\n",
"[1] <https://njoy.github.io/about/index.html>\n",
"\n",
"[2] X. X. Cai and T. Kittelmann, NCrystal, <https://doi.org/10.5281/zenodo.853186>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### We will first install NCrystal"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Create a directory for the instalation:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"mkdir install-njoy-ncrystal\n",
"cd install-njoy-ncrystal\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Clone the source code from the Github repositories"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"git clone -b ncrystal-leapr https://github.com/marquezj/ncrystal.git\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(we are cloning the \"ncrystal-leapr\" branch, which has the modifications to run with NJOY)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Create a build directory for NCrystal:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"mkdir ncrystal-build\n",
"cd ncrystal-build\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Run cmake for NCrystal:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"cmake . -DCMAKE_INSTALL_PREFIX=../ncrystal-install ../ncrystal\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Run make and make install"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"make && make install\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Source the script setup.sh to configure the environment variables necessary to run NCrystal and compile NJOY."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"cd ../ncrystal-install\n",
"source setup.sh\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"At this point you should have a working NCrystal installation. This can be tested the standalone ncrystal_inspectfile on one of the NCrystal data files, e.g. Be_sg194.ncmat:\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"bin/ncrystal_inspectfile data/Be_sg194.ncmat \n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The result will be a plot of the cross sections and a plot of the sampling of the scattering kernel:\n",
"\n",
"![inspect file plot window 1](https://i.imgur.com/P3xScz8.png)\n",
"![inspect file plot window 1](https://i.imgur.com/H7cO3XD.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"More information can be found in the documentation of NCrystal:\n",
"\n",
"<https://github.com/mctools/ncrystal/wiki>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### We will now build NJOY:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* First, we return to the installation directory and clone the source code from the Github repository:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"cd ../\n",
"git clone -b ncrystal-leapr https://github.com/marquezj/NJOY2016.git\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Now we make a directory to build NJOY"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"mkdir njoy-build\n",
"cd njoy-build\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Run cmake for NJOY:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"cmake ../NJOY2016/\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"(NJOY can be configured to be linked statically, but will still depend on libNCrystal.so to run)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* and finally run make:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"make\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### We will now test NJOY-NCrystal:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* As an example, we will work with the input for Beryllium metal from ENDF/B-VIII.0. We can get it from NNDC:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"cd ../\n",
"mkdir test\n",
"cd test\n",
"svn export https://ndclx4.bnl.gov/svn/endf/trunk/endf7/thermal_scatt/tsl-Be-metal.leapr\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This input file only includes the inelastic part of the evaluation (iel=0). If we set iel to 2 we will use the Beryllium structure hard coded into the subroutine coher() of LEAPR; if we set it to 99, we will call NCrystal. The commands for NCrystal are input as a string in card 20."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```\n",
"leapr\n",
"24\n",
"'Be-metal'/\n",
"8 2 100/\n",
"26 126 0 0/\n",
"8.93478000 6.153875 1 99 0/ <--- iel changed from 0 to 99\n",
"0/\n",
"150 200 1/\n",
"3.052968E-03 3.270915E-03 3.504421E-03 3.754597E-03 4.022632E-03\n",
"\n",
"[...]\n",
"\n",
"-1000.0/\n",
"-1200.0/\n",
"Be_sg194.ncmat;braggonly=1 <--- NCrystal commands added here\n",
"\n",
"[...]\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The ```diff``` between the files is:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```\n",
"6c6\n",
"< 8.93478000 6.153875 1 0 0/\n",
"---\n",
"> 8.93478000 6.153875 1 99 0/\n",
"121a122\n",
"> Be_sg194.ncmat;braggonly=1\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The first part of the command is the NCrystal input file. NCrystal automatically searches for input files in ```$NCRYSTALDIR/data```. The second part of the command tells NCrystal to only generate the elastic part (the inelastic component will be computed by LEAPR)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can modify the input file in a test editor, or just run:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"cat tsl-Be-metal.leapr | \\\n",
"sed s/\"8.93478000 6.153875 1 0 0\"/\"8.93478000 6.153875 1 99 0\"/g | \\\n",
"sed '122i Be_sg194.ncmat;braggonly=1' > be.inp\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"and now we run the modified input file with NJOY-NCrystal:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"```bash\n",
"../njoy-build/njoy < be.inp\n",
"```"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
@tkittel
Copy link

tkittel commented Sep 5, 2018

Nice tutorial 👍

FYI the NCrystal syntax changed a bit in recent releases so instead of braggonly=1, one should now use bkgd=0.

@vedantkm
Copy link

Great tutorial - works great for the given example. I am trying to approach this for deuterium, but it breaks since this NCrystal is still v1. Will this 'hack' get upgraded with latest NCrystal version? - Thank you!

@marquezj
Copy link
Author

@vedantkm The short answer is no. We plan to call NCrystal directly from MCNP/OpenMC/PHITS and avoid this.

But if you do it, post a link here. Perhaps somebody finds it useful.

@vedantkm
Copy link

@marquezj - perhaps this is my misunderstanding of the NCrystal code - but how can NCrystal with MCNP/OpenMC generate TSLs/XS without using NJOY?

@marquezj
Copy link
Author

@vedantkm NCrystal creates an scattering object in memory. Three years ago, when I wrote this, NCrystal did not support inelastic scattering, but we used it to compute the structure factor.

Now, in NCrystal version 2, it computes everything that LEAPR supports (and a lot of more), and you could call it from NJOY to put it in ENDF format. But you can also call it directly from Monte Carlo to get the scattering cross section at a given energy and to sample the scattering events. This feature is already implemented for McStas and Geant4.

@vedantkm
Copy link

@marquezj - thank you - I see now!

Going through the NCrystal tutorial I cannot find how to couple NJOY with NCrystal v2 (other than this tutorial). I prefer calling NCrystal with NJOY as I need to create TSL files in ENDF/ACE format. Or does NCrystal secretly also create ENDF files? I have a .ncmat file that I wrote. Perhaps there is a ncmat2endf command?

Since I have VDOS (Phonon DOS), I would like to use NCrystal to construct Bragg edges and then feed it back into the NJOY to create ENDF+ACE files. Other than the route provided in this tutorial, I cannot see if it's possible directly with NCrystal.

@marquezj
Copy link
Author

@vedantkm NCrystal does not do anything secretly. It is free software, everything is there to see in the source. If you need to do something that has not been yet implemented (such as producing ENDF files), get the code and modify it. What I said is you could call it from NJOY, but you have to do it yourself.

@vedantkm
Copy link

@marquezj Thank you for the clarification! I will attempt to implement NJOY with newer version of NCrystal!

@marquezj
Copy link
Author

FYI, the "hack" presented in this gist has been superseded by a new release called NJOY+NCrystal:

https://github.com/highness-eu/NJOY-NCrystal-Library

@vedantkm
Copy link

vedantkm commented Aug 11, 2021

Thank you @marquezj. I finally got to utilize it. Unfortunately, the generated results from NJOY+Ncrystal are deviating significantly when compared to the FLASSH code. Perhaps, we should take the conversation private and discuss?

@marquezj
Copy link
Author

Well, I am not sure what that code does, but I would always compare with experimental data first.
Anyway, if you want to ask about NJOY+NCrystal just send me an email.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment