Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
453 changes: 453 additions & 0 deletions Data/CROMER/AC.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/AG.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/AL.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/AR.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/AS.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/AT.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/AU.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/B.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/BA.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/BE.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/BI.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/BR.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/C.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/CA.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/CD.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/CE.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/CL.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/CO.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/CR.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/CS.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/CU.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/F.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/FE.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/FR.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/GA.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/GE.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/HG.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/I.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/IN.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/IR.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/K.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/KR.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/LA.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/LI.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/MG.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/MN.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/MO.f12

Large diffs are not rendered by default.

282 changes: 282 additions & 0 deletions Data/CROMER/NA.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/NB.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/NE.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/NI.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/NP.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/O.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/OS.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/P.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/PA.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/PB.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/PD.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/PO.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/PT.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/PU.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/RA.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/RB.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/RE.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/RH.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/RN.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/RU.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/S.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/SB.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/SC.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/SE.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/SI.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/SN.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/SR.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/TC.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/TE.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/TH.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/TI.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/TL.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/U.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/V.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/W.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/XE.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/Y.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/ZN.f12

Large diffs are not rendered by default.

453 changes: 453 additions & 0 deletions Data/CROMER/ZR.f12

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions Intern/rayx-core/src/Material/CromerTable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "CromerTable.h"

#include <algorithm>
#include <fstream>

#include "Debug/Debug.h"
#include "Rml/Locate.h"

namespace RAYX {

bool CromerTable::load(const char* element, CromerTable* out) {
std::string elementString = element;
std::transform(elementString.begin(), elementString.end(), elementString.begin(), [](unsigned char c) { return std::toupper(c); });

std::filesystem::path f = ResourceHandler::getInstance().getResourcePath(std::filesystem::path("Data") / "CROMER" / (elementString + ".f12"));
RAYX_VERB << "Loading CromerTable from " << f;
std::ifstream s(f);

if (s.fail()) {
return false;
}

std::string line;

// ignore first three lines
for (int i = 0; i < 3; i++) {
std::getline(s, line);
}

// line 4..EOF
for (uint32_t lineidx = 4; std::getline(s, line); lineidx++) {
if (line.empty()) {
continue;
}

CromerEntry e{};
#if defined(WIN32)
if (sscanf_s(line.c_str(), "%le %le %le", &e.m_energy, &e.m_n, &e.m_k) != 3) {
#else
if (sscanf(line.c_str(), "%le %le %le", &e.m_energy, &e.m_n, &e.m_k) != 3) {
#endif
RAYX_WARN << "Failed to parse CromerTable \"" << element << "\", at line " << lineidx << ": \"" << line << "\"";
return false;
}
out->m_Lines.push_back(e);
}

out->m_element = element;

return true;
}

} // namespace RAYX
29 changes: 29 additions & 0 deletions Intern/rayx-core/src/Material/CromerTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include <string>
#include <vector>

// This file defines the CromerEntry.
#include "../Shader/RefractiveIndex.h"

namespace RAYX {
/** This struct represents the contents of a .f12 file.
*
* Example usage:
*
* CromerTable cu;
* bool success = CromerTable::load("CU", &cu); // the cromer table for copper!
*
*/
struct CromerTable {
std::string m_element;
std::vector<CromerEntry> m_Lines;

/** loads the .NKP file of the element `element` and writes it's contents to
* `out` */
static bool load(const char* element, CromerTable* out);

// double interpolate(double x) const;
};

} // namespace RAYX
19 changes: 19 additions & 0 deletions Intern/rayx-core/src/Material/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Debug/Debug.h"
#include "NffTable.h"
#include "PalikTable.h"
#include "CromerTable.h"

namespace RAYX {

Expand Down Expand Up @@ -98,6 +99,24 @@ MaterialTables loadMaterialTables(std::array<bool, 92> relevantMaterials) {
}
}

// add cromer table content
for (size_t i = 0; i < mats.size(); i++) {
out.indices.push_back(out.materials.size());
if (relevantMaterials[i]) {
CromerTable t;

if (!CromerTable::load(getMaterialName(mats[i]), &t)) {
RAYX_EXIT << "could not load CromerTable!";
}

for (auto x : t.m_Lines) {
out.materials.push_back(x.m_energy);
out.materials.push_back(x.m_n);
out.materials.push_back(x.m_k);
}
}
}

// this extra index simplifies computation on the GPU, as then the table
// within indices[i]..indices[i+1] can be used without checks.
out.indices.push_back(out.materials.size());
Expand Down
2 changes: 1 addition & 1 deletion Intern/rayx-core/src/Material/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct RAYX_API MaterialTables {
std::vector<int> indices;
};

// the following function loads the Palik & Nff tables.
// the following function loads the Palik, Nff, and Cromer tables.
// the tables will later be written to the mat and matIdx buffers of shader.comp
MaterialTables RAYX_API loadMaterialTables(std::array<bool, 92> relevantMaterials);

Expand Down
76 changes: 61 additions & 15 deletions Intern/rayx-core/src/Shader/RefractiveIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ int RAYX_API getNffEntryCount(const int material, const int* materialIndices) {
// the offset of 92 (== number of materials), skips the palik table and
// reaches into the nff table. the rest of the logic is as above.
return (materialIndices[92 + m + 1] - materialIndices[92 + m]) / 3;

}

/// The number of cromer entries we currently store for this material.
RAYX_FN_ACC
int RAYX_API getCromerEntryCount(const int material, const int* materialIndices) {
int m = material - 1; // in [0, 91]
// the offset of 184 (== number of materials * 2), skips the palik table and
// reaches into the cromer table. the rest of the logic is as above.
return (materialIndices[184 + m + 1] - materialIndices[184 + m]) / 3;
}

// Indexes into the palik table of a particular material at a given index.
Expand Down Expand Up @@ -74,6 +84,21 @@ NffEntry RAYX_API getNffEntry(int index, int material, const int* __restrict mat
return e;
}

RAYX_FN_ACC
CromerEntry RAYX_API getCromerEntry(int index, int material, const int* __restrict materialIndices, const double* __restrict materialTable) {
int m = material - 1; // in [0, 91]
// materialIndices[184+m] is the start of the Cromer table of material m.
// 3*index skips 'index'-many entries.
int i = materialIndices[184 + m] + 3 * index;

CromerEntry e;
e.m_energy = materialTable[i];
e.m_n = materialTable[i + 1];
e.m_k = materialTable[i + 2];

return e;
}

// returns dvec2 to represent a complex number
RAYX_FN_ACC
complex::Complex RAYX_API getRefractiveIndex(double energy, int material, const int* __restrict materialIndices,
Expand All @@ -88,6 +113,35 @@ complex::Complex RAYX_API getRefractiveIndex(double energy, int material, const
return complex::Complex(-1.0, -1.0);
}

// get refractive index with Nff table
if (getNffEntryCount(material, materialIndices) > 0) { // don't try binary search if there are 0 entries!
int low = 0; // <= energy
int high = getNffEntryCount(material, materialIndices) - 1; // >= energy

// binary search
while (high - low > 1) {
int center = (low + high) / 2;
NffEntry center_entry = getNffEntry(center, material, materialIndices, materialTable);
if (energy < center_entry.m_energy) {
high = center;
} else {
low = center;
}
}

// compute n, k from the Nff data.
glm::dvec2 massAndRho = getAtomicMassAndRho(material);
double mass = massAndRho.x;
double rho = massAndRho.y;

NffEntry entry = getNffEntry(low, material, materialIndices, materialTable);
double e = entry.m_energy;
double n = 1 - (415.252 * rho * entry.m_f1) / (e * e * mass);
double k = (415.252 * rho * entry.m_f2) / (e * e * mass);

return complex::Complex(n, k);
}

// try to get refractive index using Palik table
if (getPalikEntryCount(material, materialIndices) > 0) { // don't try binary search if there are 0 entries!
int low = 0; // <= energy
Expand All @@ -113,33 +167,25 @@ complex::Complex RAYX_API getRefractiveIndex(double energy, int material, const
}
}

// get refractive index with Nff table
if (getNffEntryCount(material, materialIndices) > 0) { // don't try binary search if there are 0 entries!

// get refractive index with Cromer table
if (getCromerEntryCount(material, materialIndices) > 0) { // don't try binary search if there are 0 entries!
int low = 0; // <= energy
int high = getNffEntryCount(material, materialIndices) - 1; // >= energy
int high = getCromerEntryCount(material, materialIndices) - 1; // >= energy

// binary search
while (high - low > 1) {
int center = (low + high) / 2;
NffEntry center_entry = getNffEntry(center, material, materialIndices, materialTable);
CromerEntry center_entry = getCromerEntry(center, material, materialIndices, materialTable);
if (energy < center_entry.m_energy) {
high = center;
} else {
low = center;
}
}

// compute n, k from the Nff data.
glm::dvec2 massAndRho = getAtomicMassAndRho(material);
double mass = massAndRho.x;
double rho = massAndRho.y;

NffEntry entry = getNffEntry(low, material, materialIndices, materialTable);
double e = entry.m_energy;
double n = 1 - (415.252 * rho * entry.m_f1) / (e * e * mass);
double k = (415.252 * rho * entry.m_f2) / (e * e * mass);

return complex::Complex(n, k);
CromerEntry entry = getCromerEntry(low, material, materialIndices, materialTable);
return complex::Complex(entry.m_n, entry.m_k);
}

_throw("getRefractiveIndex: no matching entry found!");
Expand Down
11 changes: 11 additions & 0 deletions Intern/rayx-core/src/Shader/RefractiveIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,25 @@ struct NffEntry {
double m_f2;
};

/// This struct represents one line of a .f12 file from the cromer materialtables.
struct CromerEntry {
double m_energy;
double m_n;
double m_k;
};

RAYX_FN_ACC int RAYX_API getPalikEntryCount(int material, const int* materialIndices);

RAYX_FN_ACC int RAYX_API getNffEntryCount(int material, const int* materialIndices);

RAYX_FN_ACC int RAYX_API getCromerEntryCount(int material, const int* materialIndices);

RAYX_FN_ACC PalikEntry RAYX_API getPalikEntry(int index, int material, const int* materialIndices, const double* materialTable);

RAYX_FN_ACC NffEntry RAYX_API getNffEntry(int index, int material, const int* materialIndices, const double* materialTable);

RAYX_FN_ACC CromerEntry RAYX_API getCromerEntry(int index, int material, const int* materialIndices, const double* materialTable);

// returns dvec2 to represent a complex number
RAYX_FN_ACC complex::Complex RAYX_API getRefractiveIndex(double energy, int material, const int* materialIndices, const double* materialTable);

Expand Down
27 changes: 27 additions & 0 deletions Intern/rayx-core/tests/testShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,33 @@ TEST_F(TestSuite, testNff) {
CHECK_EQ(Au10.m_f2, 2.67227);
}

// test cromer tables
TEST_F(TestSuite, testCromer) {
auto mat = createMaterialTables({Material::Cu, Material::Au});

int Cu = static_cast<int>(Material::Cu);
CHECK_EQ(getCromerEntryCount(Cu, mat.indices.data()), 450);

auto Cu0 = getCromerEntry(0, Cu, mat.indices.data(), mat.materials.data());
CHECK_EQ(Cu0.m_n, 28.455647403258698);
CHECK_EQ(Cu0.m_k, 1.3255343263698971);

auto Cu10 = getCromerEntry(10, Cu, mat.indices.data(), mat.materials.data());
CHECK_EQ(Cu10.m_n, 28.125870077993461);
CHECK_EQ(Cu10.m_k, 0.96636626222754107);

int Au = static_cast<int>(Material::Au);
CHECK_EQ(getCromerEntryCount(Au, mat.indices.data()), 450);

auto Au0 = getCromerEntry(0, Au, mat.indices.data(), mat.materials.data());
CHECK_EQ(Au0.m_n, 75.80310173166059);
CHECK_EQ(Au0.m_k, 14.68569867739777);

auto Au10 = getCromerEntry(10, Au, mat.indices.data(), mat.materials.data());
CHECK_EQ(Au10.m_n, 76.187030489298166);
CHECK_EQ(Au10.m_k, 11.20875960827477);
}

TEST_F(TestSuite, testRefractiveIndex) {
auto mat = createMaterialTables({Material::Cu, Material::Au});

Expand Down
Loading