Skip to content

Commit

Permalink
Re #9466. Changed Atom to forward declare.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed May 15, 2014
1 parent 0482d2d commit 55dc2c2
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 70 deletions.
Expand Up @@ -62,7 +62,7 @@ class DLLExport SetSampleMaterial : public Mantid::API::Algorithm
///Execution code
void exec();
/// Print out the list of information for the material
void fixNeutron(Kernel::NeutronAtom &neutron,
void fixNeutron(PhysicalConstants::NeutronAtom &neutron,
double coh_xs, double inc_xs,
double abs_xs, double tot_xs);
};
Expand Down
9 changes: 3 additions & 6 deletions Code/Mantid/Framework/DataHandling/src/SetSampleMaterial.cpp
Expand Up @@ -275,19 +275,16 @@ namespace Mantid
NeutronAtom neutron(0, 0., 0., 0., 0., 0., 0.); // starting thing for neutronic information
if (CF.atoms.size() == 1 && isEmpty(zParameter) && isEmpty(rho))
{

Atom myAtom = getAtom(chemicalSymbol, CF.aNumbers[0]);
mat.reset(new Material(chemicalSymbol, myAtom.neutron, myAtom.number_density));
mat.reset(new Material(chemicalSymbol, CF.atoms[0]->neutron, CF.atoms[0]->number_density));
}
else
{
double numAtoms = 0.; // number of atoms in formula
for (size_t i=0; i<CF.atoms.size(); i++)
{
Atom myAtom = getAtom(CF.atoms[i], CF.aNumbers[i]);
neutron = neutron + CF.numberAtoms[i] * myAtom.neutron;
neutron = neutron + CF.numberAtoms[i] * CF.atoms[i]->neutron;

g_log.information() << myAtom << ": " << myAtom.neutron << "\n";
g_log.information() << CF.atoms[i] << ": " << CF.atoms[i]->neutron << "\n";
numAtoms += static_cast<double>(CF.numberAtoms[i]);
}
// normalize the accumulated number by the number of atoms
Expand Down
25 changes: 14 additions & 11 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/Material.h
Expand Up @@ -6,17 +6,18 @@
//------------------------------------------------------------------------------
#include "MantidKernel/NeutronAtom.h"
#include "MantidKernel/PhysicalConstants.h"
#ifndef Q_MOC_RUN
# include <boost/shared_ptr.hpp>
#endif
#include <boost/shared_ptr.hpp>
#include <nexus/NeXusFile.hpp>


namespace Mantid
{

namespace PhysicalConstants{ class Atom; }

namespace Kernel
{
using PhysicalConstants::NeutronAtom;

/**
A material is defined as being composed of a given element, defined as a
PhysicalConstants::NeutronAtom, with the following properties:
Expand Down Expand Up @@ -78,22 +79,24 @@ namespace Mantid
/// Get the pressure
double pressure() const;
/// Get the coherent scattering cross section for a given wavelength
double cohScatterXSection(const double lambda = NeutronAtom::ReferenceLambda) const;
double cohScatterXSection(const double lambda = PhysicalConstants::NeutronAtom::ReferenceLambda) const;
/// Get the incoherent cross section for a given wavelength
double incohScatterXSection(const double lambda = NeutronAtom::ReferenceLambda) const;
double incohScatterXSection(const double lambda = PhysicalConstants::NeutronAtom::ReferenceLambda) const;
/// Return the total scattering cross section for a given wavelength
double totalScatterXSection(const double lambda = NeutronAtom::ReferenceLambda) const;
double totalScatterXSection(const double lambda = PhysicalConstants::NeutronAtom::ReferenceLambda) const;
/// Get the absorption cross section at a given wavelength
double absorbXSection(const double lambda = NeutronAtom::ReferenceLambda) const;
double absorbXSection(const double lambda = PhysicalConstants::NeutronAtom::ReferenceLambda) const;
//@}

void saveNexus(::NeXus::File * file, const std::string & group) const;
void loadNexus(::NeXus::File * file, const std::string & group);

/// Structure to hold the information for a parsed chemical formula
struct ChemicalFormula
{
std::vector<std::string> atoms; // Chemical symbol of each atom
std::vector<float> numberAtoms; // Number of each atom
std::vector<uint16_t> aNumbers; // Atomic number of each atom
/// Atoms for the formula. Caller responsible to delete.
std::vector<boost::shared_ptr<PhysicalConstants::Atom> > atoms;
std::vector<float> numberAtoms; ///< Number of each atom
};
static ChemicalFormula parseChemicalFormula(const std::string chemicalSymbol);

Expand Down
13 changes: 6 additions & 7 deletions Code/Mantid/Framework/Kernel/src/Material.cpp
Expand Up @@ -2,7 +2,9 @@
// Includes
//------------------------------------------------------------------------------
#include "MantidKernel/Material.h"
#include "MantidKernel/Atom.h"
#include <boost/lexical_cast.hpp>
#include <boost/make_shared.hpp>
#include <boost/regex.hpp>
#include <boost/tokenizer.hpp>
#include <sstream>
Expand All @@ -17,6 +19,8 @@ namespace Mantid
typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
typedef std::pair<std::string, std::string> str_pair;

using PhysicalConstants::Atom;
using PhysicalConstants::getAtom;
using PhysicalConstants::NeutronAtom;

/**
Expand Down Expand Up @@ -238,13 +242,8 @@ namespace Mantid
if (!temp.second.empty())
numberAtoms = boost::lexical_cast<float>(temp.second);
}
if (name == "D")
{
name = "H";
aNumber = 2;
}
CF.atoms.push_back(name);
CF.aNumbers.push_back(aNumber);

CF.atoms.push_back(boost::make_shared<Atom>(getAtom(name, aNumber)));
CF.numberAtoms.push_back(numberAtoms);
}
catch (boost::bad_lexical_cast &e)
Expand Down
89 changes: 45 additions & 44 deletions Code/Mantid/Framework/Kernel/test/MaterialTest.h
Expand Up @@ -6,6 +6,7 @@
#include <stdexcept>

#include "MantidKernel/Material.h"
#include "MantidKernel/Atom.h"
#include "MantidKernel/NeutronAtom.h"
#include "MantidTestHelpers/NexusTestHelper.h"

Expand Down Expand Up @@ -84,99 +85,99 @@ class MaterialTest: public CxxTest::TestSuite
{
Material::ChemicalFormula cf;

cf = Material::parseChemicalFormula("F60");
cf = Material::parseChemicalFormula("F14");
TS_ASSERT_EQUALS(cf.atoms.size(), 1);
TS_ASSERT_EQUALS(cf.atoms[0], "F");
TS_ASSERT_EQUALS(cf.aNumbers[0], 0);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 60);
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "F");
TS_ASSERT_EQUALS(cf.atoms[0]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 14);

cf = Material::parseChemicalFormula("(F60)");
cf = Material::parseChemicalFormula("(F14)");
TS_ASSERT_EQUALS(cf.atoms.size(), 1);
TS_ASSERT_EQUALS(cf.atoms[0], "F");
TS_ASSERT_EQUALS(cf.aNumbers[0], 60);
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "F");
TS_ASSERT_EQUALS(cf.atoms[0]->a_number, 14);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 1);

cf = Material::parseChemicalFormula("C60");
cf = Material::parseChemicalFormula("C15");
TS_ASSERT_EQUALS(cf.atoms.size(), 1);
TS_ASSERT_EQUALS(cf.atoms[0], "C");
TS_ASSERT_EQUALS(cf.aNumbers[0], 0);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 60);
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "C");
TS_ASSERT_EQUALS(cf.atoms[0]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 15);

cf = Material::parseChemicalFormula("(C60)");
cf = Material::parseChemicalFormula("(C15)");
TS_ASSERT_EQUALS(cf.atoms.size(), 1);
TS_ASSERT_EQUALS(cf.atoms[0], "C");
TS_ASSERT_EQUALS(cf.aNumbers[0], 60);
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "C");
TS_ASSERT_EQUALS(cf.atoms[0]->a_number, 15);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 1);

cf = Material::parseChemicalFormula("H2 O");
TS_ASSERT_EQUALS(cf.atoms.size(), 2);
TS_ASSERT_EQUALS(cf.atoms[0], "H");
TS_ASSERT_EQUALS(cf.aNumbers[0], 0);
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "H");
TS_ASSERT_EQUALS(cf.atoms[0]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 2);
TS_ASSERT_EQUALS(cf.atoms[1], "O");
TS_ASSERT_EQUALS(cf.aNumbers[1], 0);
TS_ASSERT_EQUALS(cf.atoms[1]->symbol, "O");
TS_ASSERT_EQUALS(cf.atoms[1]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[1], 1);

cf = Material::parseChemicalFormula("(H1)2 O");
TS_ASSERT_EQUALS(cf.atoms.size(), 2);
TS_ASSERT_EQUALS(cf.atoms[0], "H");
TS_ASSERT_EQUALS(cf.aNumbers[0], 1);
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "H");
TS_ASSERT_EQUALS(cf.atoms[0]->a_number, 1);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 2);
TS_ASSERT_EQUALS(cf.atoms[1], "O");
TS_ASSERT_EQUALS(cf.aNumbers[1], 0);
TS_ASSERT_EQUALS(cf.atoms[1]->symbol, "O");
TS_ASSERT_EQUALS(cf.atoms[1]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[1], 1);

cf = Material::parseChemicalFormula("D2 O");
TS_ASSERT_EQUALS(cf.atoms.size(), 2);
TS_ASSERT_EQUALS(cf.atoms[0], "H");
TS_ASSERT_EQUALS(cf.aNumbers[0], 2);
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "H");
TS_ASSERT_EQUALS(cf.atoms[0]->a_number, 2);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 2);
TS_ASSERT_EQUALS(cf.atoms[1], "O");
TS_ASSERT_EQUALS(cf.aNumbers[1], 0);
TS_ASSERT_EQUALS(cf.atoms[1]->symbol, "O");
TS_ASSERT_EQUALS(cf.atoms[1]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[1], 1);

cf = Material::parseChemicalFormula("H2 O");
TS_ASSERT_EQUALS(cf.atoms.size(), 2);
TS_ASSERT_EQUALS(cf.atoms[0], "H");
TS_ASSERT_EQUALS(cf.aNumbers[0], 0);
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "H");
TS_ASSERT_EQUALS(cf.atoms[0]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 2);
TS_ASSERT_EQUALS(cf.atoms[1], "O");
TS_ASSERT_EQUALS(cf.aNumbers[1], 0);
TS_ASSERT_EQUALS(cf.atoms[1]->symbol, "O");
TS_ASSERT_EQUALS(cf.atoms[1]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[1], 1);

cf = Material::parseChemicalFormula("H2-O");
TS_ASSERT_EQUALS(cf.atoms.size(), 2);
TS_ASSERT_EQUALS(cf.atoms[0], "H");
TS_ASSERT_EQUALS(cf.aNumbers[0], 0);
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "H");
TS_ASSERT_EQUALS(cf.atoms[0]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 2);
TS_ASSERT_EQUALS(cf.atoms[1], "O");
TS_ASSERT_EQUALS(cf.aNumbers[1], 0);
TS_ASSERT_EQUALS(cf.atoms[1]->symbol, "O");
TS_ASSERT_EQUALS(cf.atoms[1]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[1], 1);

TS_ASSERT_THROWS(cf = Material::parseChemicalFormula("H2*O"), std::runtime_error);
TS_ASSERT_EQUALS(cf.atoms.size(), 2);
TS_ASSERT_EQUALS(cf.atoms[0], "H");
TS_ASSERT_EQUALS(cf.aNumbers[0], 0);
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "H");
TS_ASSERT_EQUALS(cf.atoms[0]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[0], 2);
TS_ASSERT_EQUALS(cf.atoms[1], "O");
TS_ASSERT_EQUALS(cf.aNumbers[1], 0);
TS_ASSERT_EQUALS(cf.atoms[1]->symbol, "O");
TS_ASSERT_EQUALS(cf.atoms[1]->a_number, 0);
TS_ASSERT_EQUALS(cf.numberAtoms[1], 1);

cf = Material::parseChemicalFormula("(Li7)2");

cf = Material::parseChemicalFormula("Y-Ba2-Cu3-O6.56");
TS_ASSERT_EQUALS(cf.atoms.size(), 4);
for (auto it = cf.aNumbers.begin(); it != cf.aNumbers.end(); ++it)
for (auto it = cf.atoms.begin(); it != cf.atoms.end(); ++it)
{
TS_ASSERT_EQUALS(*it, 0);
TS_ASSERT_EQUALS((*it)->a_number, 0);
}
TS_ASSERT_EQUALS(cf.atoms[0], "Y");
TS_ASSERT_EQUALS(cf.atoms[0]->symbol, "Y");
TS_ASSERT_EQUALS(cf.numberAtoms[0], 1);
TS_ASSERT_EQUALS(cf.atoms[1], "Ba");
TS_ASSERT_EQUALS(cf.atoms[1]->symbol, "Ba");
TS_ASSERT_EQUALS(cf.numberAtoms[1], 2);
TS_ASSERT_EQUALS(cf.atoms[2], "Cu");
TS_ASSERT_EQUALS(cf.atoms[2]->symbol, "Cu");
TS_ASSERT_EQUALS(cf.numberAtoms[2], 3);
TS_ASSERT_EQUALS(cf.atoms[3], "O");
TS_ASSERT_EQUALS(cf.atoms[3]->symbol, "O");
TS_ASSERT_DELTA(cf.numberAtoms[3], 6.56, .01);
}

Expand Down
Expand Up @@ -6,7 +6,7 @@
#include <boost/python/register_ptr_to_python.hpp>

using Mantid::Kernel::Material;
using Mantid::Kernel::NeutronAtom;
using Mantid::PhysicalConstants::NeutronAtom;
using namespace boost::python;

void export_Material()
Expand Down

0 comments on commit 55dc2c2

Please sign in to comment.