Commit d9f75ef3 authored by Kendrick, Coleman's avatar Kendrick, Coleman
Browse files

Updating validate inputs for packing fraction

parent b03547e5
......@@ -45,15 +45,64 @@ ReadMaterial::validateInputs(const MaterialParameters &params) {
"no ChemicalFormula or AtomicNumber is "
"given.";
}
if (isEmpty(params.numberDensity)) {
if (isEmpty(params.numberDensity) &&
isEmpty(params.numberDensityEffective) &&
isEmpty(params.packingFraction)) {
result["NumberDensity"] =
"The number density must be specified with a use-defined material.";
"The number density or effective number density must "
" be specified with a user-defined material";
}
} else if (chemicalSymbol && atomicNumber) {
result["AtomicNumber"] =
"Cannot specify both ChemicalFormula and AtomicNumber";
}
if (!isEmpty(params.numberDensity) &&
!isEmpty(params.numberDensityEffective) &&
!isEmpty(params.packingFraction)) {
result["NumberDensity"] = "Number Density cannot be determined when "
"both the effective number density and "
"packing fraction are set. Only two can "
"be specified at most.";
}
if (isEmpty(params.massDensity) && isEmpty(params.zParameter) &&
isEmpty(params.unitCellVolume)) {
// Checks if only the packing fraction has been specified with no other
// way of computing the number density or eff. number density
if (isEmpty(params.numberDensity) &&
isEmpty(params.numberDensityEffective) &&
!isEmpty(params.packingFraction)) {
result["PackingFraction"] =
"Cannot determine number density from only "
" the packing fraction. The number density "
" or effective number density is also needed.";
}
}
// If these are all set, then number density and eff. number density can be
// calculated. In this case, make sure the packing frac isn't set
if (!isEmpty(params.massDensity) && !isEmpty(params.zParameter) &&
!isEmpty(params.unitCellVolume)) {
if (!isEmpty(params.packingFraction)) {
result["PackingFraction"] =
"Cannot set packing fraction when both the number density "
"and effective number density are determined from "
"the mass density and cell volume + zParameter.";
}
}
// Bounds check the packing fraction number [0, 2)
if (!isEmpty(params.packingFraction)) {
if (params.packingFraction >= 2.0) {
result["PackingFraction"] =
"Cannot have a packing fraction larger than 2";
} else if (params.packingFraction < 0.0) {
result["PackingFraction"] = "Cannot have a packing fraction less than 0";
}
}
if (params.massNumber > 0 && params.atomicNumber <= 0)
result["AtomicNumber"] = "Specified MassNumber without AtomicNumber";
......
......@@ -233,12 +233,9 @@ public:
const ReadMaterial::MaterialParameters params = []() -> auto {
ReadMaterial::MaterialParameters setMaterial;
setMaterial.atomicNumber = 1;
setMaterial.massNumber = 1;
setMaterial.numberDensity = 1;
setMaterial.numberDensityEffective = 1;
setMaterial.packingFraction = 1;
setMaterial.zParameter = 1;
setMaterial.unitCellVolume = 1;
return setMaterial;
}
();
......@@ -270,11 +267,29 @@ public:
"Cannot have a packing fraction larger than 2")
}
void testFailureValidateInputsNegativePackingFrac() {
const ReadMaterial::MaterialParameters params = []() -> auto {
ReadMaterial::MaterialParameters setMaterial;
setMaterial.atomicNumber = 1;
setMaterial.massNumber = 1;
setMaterial.packingFraction = -1;
setMaterial.zParameter = 1;
setMaterial.unitCellVolume = 1;
return setMaterial;
}
();
auto result = ReadMaterial::validateInputs(params);
TS_ASSERT_EQUALS(result["PackingFraction"],
"Cannot have a packing fraction less than 0")
}
void testFailureValidateInputsPackingFracOnly() {
const ReadMaterial::MaterialParameters params = []() -> auto {
ReadMaterial::MaterialParameters setMaterial;
setMaterial.atomicNumber = 1;
setMaterial.packingFraction = 2.1;
setMaterial.packingFraction = 1;
return setMaterial;
}
();
......@@ -287,6 +302,44 @@ public:
" or effective number density is also needed.")
}
void testFailureValidateInputsPackingWithAll() {
const ReadMaterial::MaterialParameters params = []() -> auto {
ReadMaterial::MaterialParameters setMaterial;
setMaterial.atomicNumber = 1;
setMaterial.zParameter = 1;
setMaterial.unitCellVolume = 1;
setMaterial.massDensity = 1;
setMaterial.packingFraction = 1;
return setMaterial;
}
();
auto result = ReadMaterial::validateInputs(params);
TS_ASSERT_EQUALS(result["PackingFraction"],
"Cannot set packing fraction when both the number density "
"and effective number density are determined from "
"the mass density and cell volume + zParameter.")
}
void testSuccessfulValidateInputsPackingFracOnly() {
const ReadMaterial::MaterialParameters params = []() -> auto {
ReadMaterial::MaterialParameters setMaterial;
setMaterial.atomicNumber = 1;
setMaterial.packingFraction = 1;
setMaterial.zParameter = 1;
setMaterial.unitCellVolume = 1;
return setMaterial;
}
();
auto result = ReadMaterial::validateInputs(params);
// Should succeed because number density can be determined from
// the zParameter and unitCellVolume
TS_ASSERT(result.empty());
}
void testFailureValidateInputsZParamWithMass() {
const ReadMaterial::MaterialParameters params = []() -> auto {
ReadMaterial::MaterialParameters setMaterial;
......@@ -343,6 +396,7 @@ public:
ReadMaterial::MaterialParameters setMaterial;
setMaterial.chemicalSymbol = FORMULA;
setMaterial.numberDensity = 1;
setMaterial.numberDensityEffective = 1;
setMaterial.coherentXSection = 1;
setMaterial.incoherentXSection = 2;
setMaterial.attenuationXSection = 3;
......
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