Skip to content

Commit

Permalink
Refs #6828 parser in Material; use ReferenceLambda constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Vickie Lynch committed Apr 23, 2013
1 parent 4e1be6f commit 61b3a2b
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 126 deletions.
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/Algorithms/src/AbsorptionCorrection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ void AbsorptionCorrection::retrieveBaseProperties()
double sigma_s = getProperty("ScatteringXSection"); // in barns
double rho = getProperty("SampleNumberDensity"); // in Angstroms-3
const Kernel::Material *m_sampleMaterial = &(m_inputWS->sample().getMaterial());
if( m_sampleMaterial->totalScatterXSection(1.7982) != 0.0)
if( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) != 0.0)
{
if(rho == EMPTY_DBL()) rho = m_sampleMaterial->numberDensity();
if(sigma_s == EMPTY_DBL()) sigma_s = m_sampleMaterial->totalScatterXSection(1.7982);
if(sigma_atten == EMPTY_DBL()) sigma_atten = m_sampleMaterial->absorbXSection(1.7982);
if(sigma_s == EMPTY_DBL()) sigma_s = m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda);
if(sigma_atten == EMPTY_DBL()) sigma_atten = m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda);
}
else //Save input in Sample with wrong atomic number and name
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,11 @@ API::MatrixWorkspace_sptr HRPDSlabCanAbsorption::runFlatPlateAbsorption()
double sigma_s = getProperty("SampleScatteringXSection"); // in barns
double rho = getProperty("SampleNumberDensity"); // in Angstroms-3
const Material *m_sampleMaterial = &(m_inputWS->sample().getMaterial());
if( m_sampleMaterial->totalScatterXSection(1.7982) != 0.0)
if( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) != 0.0)
{
if(rho == EMPTY_DBL()) rho = m_sampleMaterial->numberDensity();
if(sigma_s == EMPTY_DBL()) sigma_s = m_sampleMaterial->totalScatterXSection(1.7982);
if(sigma_atten == EMPTY_DBL()) sigma_atten = m_sampleMaterial->absorbXSection(1.7982);
if(sigma_s == EMPTY_DBL()) sigma_s = m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda);
if(sigma_atten == EMPTY_DBL()) sigma_atten = m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda);
}
else //Save input in Sample with wrong atomic number and name
{
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/Algorithms/src/SphericalAbsorption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ void SphericalAbsorption::retrieveBaseProperties()
double sigma_s = getProperty("ScatteringXSection"); // in barns
double rho = getProperty("SampleNumberDensity"); // in Angstroms-3
const Material *m_sampleMaterial = &(m_inputWS->sample().getMaterial());
if( m_sampleMaterial->totalScatterXSection(1.7982) != 0.0)
if( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) != 0.0)
{
if(rho == EMPTY_DBL()) rho = m_sampleMaterial->numberDensity();
if(sigma_s == EMPTY_DBL()) sigma_s = m_sampleMaterial->totalScatterXSection(1.7982);
if(sigma_atten == EMPTY_DBL()) sigma_atten = m_sampleMaterial->absorbXSection(1.7982);
if(sigma_s == EMPTY_DBL()) sigma_s = m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda);
if(sigma_atten == EMPTY_DBL()) sigma_atten = m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda);
}
else //Save input in Sample with wrong atomic number and name
{
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/Crystal/src/AnvredCorrection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@ void AnvredCorrection::retrieveBaseProperties()
radius = getProperty("Radius"); // in cm
power_th = getProperty("PowerLambda"); // in cm
const Material *m_sampleMaterial = &(m_inputWS->sample().getMaterial());
if( m_sampleMaterial->totalScatterXSection(1.7982) != 0.0)
if( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) != 0.0)
{
double rho = m_sampleMaterial->numberDensity();
if(smu == EMPTY_DBL()) smu = m_sampleMaterial->totalScatterXSection(1.7982) * rho;
if(amu == EMPTY_DBL()) amu = m_sampleMaterial->absorbXSection(1.7982) * rho;
if(smu == EMPTY_DBL()) smu = m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) * rho;
if(amu == EMPTY_DBL()) amu = m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda) * rho;
}
else //Save input in Sample with wrong atomic number and name
{
Expand Down
7 changes: 4 additions & 3 deletions Code/Mantid/Framework/Crystal/src/SaveHKL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ using namespace Mantid::Geometry;
using namespace Mantid::DataObjects;
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::PhysicalConstants;

namespace Mantid
{
Expand Down Expand Up @@ -119,11 +120,11 @@ namespace Crystal
PeaksWorkspace_sptr ws = getProperty("InputWorkspace");

const Kernel::Material *m_sampleMaterial = &(ws->sample().getMaterial());
if( m_sampleMaterial->totalScatterXSection(1.7982) != 0.0)
if( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) != 0.0)
{
double rho = m_sampleMaterial->numberDensity();
smu = m_sampleMaterial->totalScatterXSection(1.7982) * rho;
amu = m_sampleMaterial->absorbXSection(1.7982) * rho;
smu = m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) * rho;
amu = m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda) * rho;
}
else
{
Expand Down
7 changes: 4 additions & 3 deletions Code/Mantid/Framework/Crystal/src/TOFExtinction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ using namespace Mantid::Geometry;
using namespace Mantid::DataObjects;
using namespace Mantid::Kernel;
using namespace Mantid::API;
using namespace Mantid::PhysicalConstants;

namespace Mantid
{
Expand Down Expand Up @@ -118,11 +119,11 @@ namespace Crystal
peaksW = inPeaksW->clone();

const Kernel::Material *m_sampleMaterial = &(inPeaksW->sample().getMaterial());
if( m_sampleMaterial->totalScatterXSection(1.7982) != 0.0)
if( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) != 0.0)
{
double rho = m_sampleMaterial->numberDensity();
smu = m_sampleMaterial->totalScatterXSection(1.7982) * rho;
amu = m_sampleMaterial->absorbXSection(1.7982) * rho;
smu = m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) * rho;
amu = m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda) * rho;
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/Crystal/test/LoadHKLTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ class LoadHKLTest : public CxxTest::TestSuite
TS_ASSERT_DELTA(p.getDSpacing(),3.5933, 1e-4 );
double radius;
const Kernel::Material *m_sampleMaterial = &(wsout->sample().getMaterial());
if( m_sampleMaterial->totalScatterXSection(1.7982) != 0.0)
if( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) != 0.0)
{
double rho = m_sampleMaterial->numberDensity();
smu = m_sampleMaterial->totalScatterXSection(1.7982) * rho;
amu = m_sampleMaterial->absorbXSection(1.7982) * rho;
smu = m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) * rho;
amu = m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda) * rho;
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions Code/Mantid/Framework/Crystal/test/SortHKLTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ class SortHKLTest : public CxxTest::TestSuite
TS_ASSERT_EQUALS(p.getRunNumber(),1000. );
TS_ASSERT_DELTA(p.getDSpacing(),3.5933, 1e-4 );
const Kernel::Material *m_sampleMaterial = &(wsout->sample().getMaterial());
if( m_sampleMaterial->totalScatterXSection(1.7982) != 0.0)
if( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) != 0.0)
{
double rho = m_sampleMaterial->numberDensity();
smu = m_sampleMaterial->totalScatterXSection(1.7982) * rho;
amu = m_sampleMaterial->absorbXSection(1.7982) * rho;
smu = m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda) * rho;
amu = m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda) * rho;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class DLLExport SetSampleMaterial : public Mantid::API::Algorithm
void init();
///Execution code
void exec();
void parseChemicalFormula(const std::string chemicalSymbol, std::vector<std::string>& atoms, std::vector<uint16_t>& numberAtoms,
std::vector<uint16_t>& aNumbers);

};

}
Expand Down
107 changes: 13 additions & 94 deletions Code/Mantid/Framework/DataHandling/src/SetSampleMaterial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ namespace DataHandling
Material *mat = new Material(chemicalSymbol, *neutron, rho);
workspace->mutableSample().setMaterial(*mat);
g_log.notice() << "Sample number density = "<< mat->numberDensity() << "\n";
g_log.notice() << "Scattering X Section = " << mat->totalScatterXSection(1.7982) << "\n";
g_log.notice() << "Attenuation X Section = " << mat->absorbXSection(1.7982)<< "\n";
g_log.notice() << "Scattering X Section = " << mat->totalScatterXSection(NeutronAtom::ReferenceLambda) << "\n";
g_log.notice() << "Attenuation X Section = " << mat->absorbXSection(NeutronAtom::ReferenceLambda)<< "\n";
return;
}

Expand All @@ -124,8 +124,8 @@ namespace DataHandling
Material *mat = new Material(chemicalSymbol, myAtom.neutron, myAtom.number_density);
workspace->mutableSample().setMaterial(*mat);
g_log.notice() << "Sample number density = "<< mat->numberDensity() << "\n";
g_log.notice() << "Scattering X Section = " << mat->totalScatterXSection(1.7982) << "\n";
g_log.notice() << "Attenuation X Section = " << mat->absorbXSection(1.7982)<< "\n";
g_log.notice() << "Scattering X Section = " << mat->totalScatterXSection(NeutronAtom::ReferenceLambda) << "\n";
g_log.notice() << "Attenuation X Section = " << mat->absorbXSection(NeutronAtom::ReferenceLambda)<< "\n";
}
catch (...)
{
Expand All @@ -134,25 +134,25 @@ namespace DataHandling
{
std::vector<std::string> atoms;
std::vector<uint16_t> numberAtoms, aNumbers;
this->parseChemicalFormula(chemicalSymbol, atoms, numberAtoms, aNumbers);
Material::parseChemicalFormula(chemicalSymbol, atoms, numberAtoms, aNumbers);
sigma_s = 0.0;
sigma_atten = 0.0;
for (size_t i=0; i<atoms.size(); i++)
{
Atom myAtom = getAtom(atoms[i], aNumbers[i]);
Material *atom = new Material(atoms[i], myAtom.neutron, myAtom.number_density);
g_log.notice() << myAtom << " sigma_s = "<< atom->totalScatterXSection(1.7982) << "\n";
g_log.notice() << myAtom << " sigma_atten = "<< atom->absorbXSection(1.7982) << "\n";
sigma_s += static_cast<double>(numberAtoms[i]) * atom->totalScatterXSection(1.7982);
sigma_atten += static_cast<double>(numberAtoms[i]) * atom->absorbXSection(1.7982);
g_log.notice() << myAtom << " sigma_s = "<< atom->totalScatterXSection(NeutronAtom::ReferenceLambda) << "\n";
g_log.notice() << myAtom << " sigma_atten = "<< atom->absorbXSection(NeutronAtom::ReferenceLambda) << "\n";
sigma_s += static_cast<double>(numberAtoms[i]) * atom->totalScatterXSection(NeutronAtom::ReferenceLambda);
sigma_atten += static_cast<double>(numberAtoms[i]) * atom->absorbXSection(NeutronAtom::ReferenceLambda);
}
rho = zParameter / unitCellVolume;
NeutronAtom *neutron = new NeutronAtom(static_cast<uint16_t>(z_number), static_cast<uint16_t>(a_number),
0.0, 0.0, sigma_s, 0.0, sigma_s, sigma_atten);
Material *mat = new Material(chemicalSymbol, *neutron, rho);
g_log.notice() << "Sample number density = "<< mat->numberDensity() << "\n";
g_log.notice() << "Scattering X Section = " << mat->totalScatterXSection(1.7982) << "\n";
g_log.notice() << "Attenuation X Section = " << mat->absorbXSection(1.7982)<< "\n";
g_log.notice() << "Scattering X Section = " << mat->totalScatterXSection(NeutronAtom::ReferenceLambda) << "\n";
g_log.notice() << "Attenuation X Section = " << mat->absorbXSection(NeutronAtom::ReferenceLambda)<< "\n";
workspace->mutableSample().setMaterial(*mat);
}
catch (...)
Expand All @@ -164,8 +164,8 @@ namespace DataHandling
Material *mat = new Material(chemicalSymbol, myAtom.neutron, myAtom.number_density);
workspace->mutableSample().setMaterial(*mat);
g_log.notice() << "Sample number density = "<< mat->numberDensity() << "\n";
g_log.notice() << "Scattering X Section = " << mat->totalScatterXSection(1.7982) << "\n";
g_log.notice() << "Attenuation X Section = " << mat->absorbXSection(1.7982)<< "\n";
g_log.notice() << "Scattering X Section = " << mat->totalScatterXSection(NeutronAtom::ReferenceLambda) << "\n";
g_log.notice() << "Attenuation X Section = " << mat->absorbXSection(NeutronAtom::ReferenceLambda)<< "\n";
}
catch(std::invalid_argument&)
{
Expand All @@ -177,87 +177,6 @@ namespace DataHandling
// Done!
progress(1);
}
void SetSampleMaterial::parseChemicalFormula(const std::string chemicalSymbol, std::vector<std::string>& atoms,
std::vector<uint16_t>& numberAtoms, std::vector<uint16_t>& aNumbers)
{
const char *s;
s = chemicalSymbol.c_str();
size_t i = 0;
size_t ia = 0;
size_t numberParen = 0;
size_t sizeParen = 0;
bool isotope = false;
while (i < chemicalSymbol.length())
{
if (s[i] >= 'A' && s[i]<='Z')
{
std::string buf(s+i, s+i+1);
atoms.push_back(buf);
numberAtoms.push_back(0);
aNumbers.push_back(0);
ia ++;
}
else if (s[i] >= 'a' && s[i]<='z')
{
std::string buf(s+i, s+i+1);
atoms[ia-1].append(buf);
}
else if (s[i] >= '0' && s[i]<='9')
{
if (isotope)
{
size_t ilast = i;
// Number of digits in aNumber
if (aNumbers[ia-1] != 0) ilast -= (int) std::log10 ((double) aNumbers[ia-1]) + 1;
std::string buf(s+ilast, s+i+1);
aNumbers[ia-1] = static_cast<uint16_t>(std::atoi(buf.c_str()));
}
else
{
size_t ilast = i;
// Number of digits in aNumber
if (numberAtoms[ia-1] != 0) ilast -= (int) std::log10 ((double) numberAtoms[ia-1]) + 1;
std::string buf(s+ilast, s+i+1);
numberAtoms[ia-1] = static_cast<uint16_t>(std::atoi(buf.c_str()));
}

}
else if (s[i] == '(' || s[i] ==')')
{
isotope = !isotope;
if (s[i] == '(')
{
// next atom
sizeParen = 0;
numberParen = ia + 1;
}
else
{
sizeParen = ia - numberParen + 1;
if (ia > numberParen)for (size_t i0 = numberParen - 1; i0 < ia; i0++)
{
// if more than one atom in parenthesis, it is compound
numberAtoms[i0] = aNumbers[i0];
aNumbers[i0] = 0;
}
}
}
else
{
}
i++;
}
if (ia == 1 && s[0] != '(')
{
// isotopes in molecular expressions must have parentheses
// single isotopes can omit parentheses
aNumbers[0] = numberAtoms[0];
numberAtoms[0] = 1;
}
for (size_t i0=0; i0<ia; i0++)
{
if (numberAtoms[i0] == 0)numberAtoms[i0] = 1;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ using namespace Mantid::API;
using namespace Mantid::Kernel;
using namespace Mantid::DataHandling;
using namespace Mantid::Geometry;
using namespace Mantid::PhysicalConstants;

using Mantid::API::MatrixWorkspace_sptr;

Expand Down Expand Up @@ -57,8 +58,8 @@ class SetSampleMaterialTest : public CxxTest::TestSuite

const Material *m_sampleMaterial = &(testWS->sample().getMaterial());
TS_ASSERT_DELTA( m_sampleMaterial->numberDensity(), 0.0236649, 0.0001 );
TS_ASSERT_DELTA( m_sampleMaterial->totalScatterXSection(1.7982), 15.7048, 0.0001);
TS_ASSERT_DELTA( m_sampleMaterial->absorbXSection(1.7982), 0.46257, 0.0001);
TS_ASSERT_DELTA( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda), 15.7048, 0.0001);
TS_ASSERT_DELTA( m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda), 0.46257, 0.0001);

}
void testExecMat_Formula()
Expand All @@ -80,8 +81,8 @@ class SetSampleMaterialTest : public CxxTest::TestSuite

const Material *m_sampleMaterial = &(testWS->sample().getMaterial());
TS_ASSERT_DELTA( m_sampleMaterial->numberDensity(), 0.0236649, 0.0001 );
TS_ASSERT_DELTA( m_sampleMaterial->totalScatterXSection(1.7982), 15.7048, 0.0001);
TS_ASSERT_DELTA( m_sampleMaterial->absorbXSection(1.7982), 0.46257, 0.0001);
TS_ASSERT_DELTA( m_sampleMaterial->totalScatterXSection(NeutronAtom::ReferenceLambda), 15.7048, 0.0001);
TS_ASSERT_DELTA( m_sampleMaterial->absorbXSection(NeutronAtom::ReferenceLambda), 0.46257, 0.0001);

}

Expand Down
2 changes: 2 additions & 0 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ namespace Mantid

void saveNexus(::NeXus::File * file, const std::string & group) const;
void loadNexus(::NeXus::File * file, const std::string & group);
static void parseChemicalFormula(const std::string chemicalSymbol, std::vector<std::string>& atoms, std::vector<uint16_t>& numberAtoms,
std::vector<uint16_t>& aNumbers);


private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace PhysicalConstants
*/
static const double BoltzmannConstant = 8.6173324e-02;


} // namespace PhysicalConstants
} // namespace Mantid

Expand Down

0 comments on commit 61b3a2b

Please sign in to comment.