-
Hi Everyone, my name is Shuqi Xu, I am currently participating in the HighNESS project and implementing the neutron magnetic scattering model in a plugin in NCrystal. I would like to call the mean-squared displacement (MSD) calculated by NCrystal in my function. After checking the source files of NCrystal, it seems that it can be called by: double msd = 0.; But I got the error message: -- Configuring done It seems that the issue is related to the data type but I cannot solve it. I would like to ask for your help if anyone knows how to fix this, thx 🙏. Best regards, To be clearer, the whole function is put here: NCP::ParamagneticScatter NCP::ParamagneticScatter::createFromInfo( const NC::Info& info ) //Get the relevant custom section data (and verify that there are not multiple // data is here a vector of lines, and each line is a vector of words. In our //Verify we have exactly one line and four words: //Parse and validate values: int mag_scat; //Getting the temperature //Getting the mean-squared displacement (MSD) //Parsing done! Create and return our model: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @XuShuqi7 , As you can see on NCInfoTypes.hh the Long story short, instead of: double msd = 0;
if ( info.hasAtomMSD() )
msd = info.getAtomInfos().front().msd(); //Wrong, won't compile! you can write: double msd = 0;
if ( info.hasAtomMSD() )
msd = info.getAtomInfos().front().msd().value(); Of course, it looks like your code is assuming mono-atomic materials, but that is another issue :-) Cheers, ps. If you add three backticks around your code blocks in github messages, it becomes much more readable :-). See more on https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks |
Beta Was this translation helpful? Give feedback.
Hi @XuShuqi7 ,
As you can see on NCInfoTypes.hh the
msd()
method returns anOptional<double>
rather than a rawdouble
. The Optional class is our C++11 compatible version of std::optional which is defined in NCDefs.hh. This is a simple container class which may or may not contain an actual value. One can use the.has_value()
method to check if there is a value (although in your case the check forhasAtomMSD()
already did the.has_value()
check internally. If there is a value, the.value()
method can be used to access it.Long story short, instead of:
you can write: