Commit 4b4321da authored by Kendrick, Coleman's avatar Kendrick, Coleman
Browse files

Updating effective density in SetSample

Also added effective density to MaterialBuilder and a test
in ReadMaterial to make sure effective density and mass density
cannot be set at the same time.
parent ca504086
......@@ -98,7 +98,8 @@ private:
const int massNumber);
void
setNumberDensity(const double rho_m, const double rho, const double pFrac,
setNumberDensity(const double rho_m, const double rho, const double rho_eff,
const double pFrac,
const Kernel::MaterialBuilder::NumberDensityUnit rhoUnit,
const double zParameter, const double unitCellVolume);
void setScatteringInfo(double coherentXSection, double incoherentXSection,
......
......@@ -93,6 +93,17 @@ ReadMaterial::validateInputs(const MaterialParameters &params) {
}
}
// Effective num density will be overwritten in MaterialBuilder if mass
// density is set
if (!isEmpty(params.massDensity)) {
if (!isEmpty(params.numberDensityEffective)) {
result["EffectiveNumberDensity"] =
"Cannot set effective number density when the mass density "
"is specified. The value specified will be overwritten "
"because it will be computed from the mass density.";
}
}
// Bounds check the packing fraction number [0, 2)
if (!isEmpty(params.packingFraction)) {
if (params.packingFraction >= 2.0) {
......@@ -131,7 +142,8 @@ void ReadMaterial::setMaterialParameters(const MaterialParameters &params) {
massDensity = params.mass / params.volume;
}
setNumberDensity(massDensity, params.numberDensity, params.packingFraction,
setNumberDensity(massDensity, params.numberDensity,
params.numberDensityEffective, params.packingFraction,
params.numberDensityUnit, params.zParameter,
params.unitCellVolume);
setScatteringInfo(params.coherentXSection, params.incoherentXSection,
......@@ -159,9 +171,9 @@ void ReadMaterial::setMaterial(const std::string &chemicalSymbol,
}
void ReadMaterial::setNumberDensity(
const double rho_m, const double rho, const double pFrac,
Kernel::MaterialBuilder::NumberDensityUnit rhoUnit, const double zParameter,
const double unitCellVolume) {
const double rho_m, const double rho, const double rho_eff,
const double pFrac, Kernel::MaterialBuilder::NumberDensityUnit rhoUnit,
const double zParameter, const double unitCellVolume) {
if (!isEmpty(rho_m))
builder.setMassDensity(rho_m);
......@@ -174,6 +186,9 @@ void ReadMaterial::setNumberDensity(
builder.setNumberDensity(rho);
builder.setNumberDensityUnit(rhoUnit);
}
if (!isEmpty(rho_eff)) {
builder.setEffectiveNumberDensity(rho_eff);
}
if (!isEmpty(pFrac)) {
builder.setPackingFraction(pFrac);
}
......
......@@ -724,7 +724,7 @@ void SetSample::setMaterial(ReadMaterial::MaterialParameters &materialParams,
if (materialArgs.existsProperty("MassDensity")) {
materialParams.massDensity = materialArgs.getProperty("MassDensity");
}
if (materialArgs.existsProperty("NumberDensityEffective")) {
if (materialArgs.existsProperty("EffectiveNumberDensity")) {
materialParams.numberDensityEffective =
materialArgs.getProperty("numberDensityEffective");
}
......@@ -1126,6 +1126,24 @@ PropertyManager SetSample::materialSettingsEnsureLegacyCompatibility(
compatible.setProperty("NumberDesnity", numberDensity);
}
}
if (materialArgs.existsProperty("SampleEffectiveNumberDensity")) {
const double numberDensityEff =
materialArgs.getProperty("SampleEffectiveNumberDensity");
if (!compatible.existsProperty("EffectiveNumberDensity")) {
compatible.declareProperty("EffectiveNumberDensity", numberDensityEff);
} else {
compatible.setProperty("EffectiveNumberDesnity", numberDensityEff);
}
}
if (materialArgs.existsProperty("SamplePackingFraction")) {
const double packingFraction =
materialArgs.getProperty("SamplePackingFraction");
if (!compatible.existsProperty("PackingFraction")) {
compatible.declareProperty("PackingFraction", packingFraction);
} else {
compatible.setProperty("PackingFraction", packingFraction);
}
}
if (materialArgs.existsProperty("SampleMassDensity")) {
const double massDensity = materialArgs.getProperty("SampleMassDensity");
if (!compatible.existsProperty("MassDensity")) {
......
......@@ -95,7 +95,7 @@ void SetSampleMaterial::init() {
"The path name of the file containing the attenuation profile");
declareProperty("SampleMassDensity", EMPTY_DBL(), mustBePositive,
"Measured mass density in g/cubic cm of the sample "
"to be used to calculate the number density.");
"to be used to calculate the effective number density.");
declareProperty(
"SampleMass", EMPTY_DBL(), mustBePositive,
"Measured mass in g of the sample. This is used with the SampleVolume "
......
......@@ -247,6 +247,25 @@ public:
"be specified at most.")
}
void testFailureValidateInputsEffectiveWithMass() {
const ReadMaterial::MaterialParameters params = []() -> auto {
ReadMaterial::MaterialParameters setMaterial;
setMaterial.atomicNumber = 1;
setMaterial.massDensity = 1;
setMaterial.numberDensityEffective = 1;
return setMaterial;
}
();
auto result = ReadMaterial::validateInputs(params);
TS_ASSERT_EQUALS(
result["EffectiveNumberDensity"],
"Cannot set effective number density when the mass density "
"is specified. The value specified will be overwritten "
"because it will be computed from the mass density.");
}
void testFailureValidateInputsLargePackingFrac() {
const ReadMaterial::MaterialParameters params = []() -> auto {
ReadMaterial::MaterialParameters setMaterial;
......
......@@ -34,6 +34,7 @@ public:
MaterialBuilder &setNumberDensity(double rho);
MaterialBuilder &setNumberDensityUnit(NumberDensityUnit unit);
MaterialBuilder &setEffectiveNumberDensity(double rho_eff);
MaterialBuilder &setPackingFraction(double fraction);
MaterialBuilder &setZParameter(double zparam);
MaterialBuilder &setUnitCellVolume(double cellVolume);
......@@ -72,6 +73,7 @@ private:
boost::optional<int> m_atomicNo;
int m_massNo;
boost::optional<double> m_numberDensity, m_packingFraction;
boost::optional<double> m_numberDensityEff;
boost::optional<double> m_zParam, m_cellVol, m_massDensity;
boost::optional<double> m_totalXSection, m_cohXSection, m_incXSection,
m_absSection;
......
......@@ -121,6 +121,18 @@ MaterialBuilder &MaterialBuilder::setNumberDensityUnit(NumberDensityUnit unit) {
return *this;
}
/**
* Set the effective number density of the sample in atoms or formula units /
* Angstrom^3
* @param rho_eff effective density of the sample in atoms or formula units /
* Angstrom^3
* @return A reference to the this object to allow chaining
*/
MaterialBuilder &MaterialBuilder::setEffectiveNumberDensity(double rho_eff) {
m_numberDensityEff = rho_eff;
return *this;
}
/**
* Set the packing fraction of the material (default is 1). This is used to
* infer the effective number density
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment