Skip to content
Snippets Groups Projects
Commit b36463a6 authored by R D Schaffer's avatar R D Schaffer
Browse files

move to new initialization of field when creating BFieldCache object as a test...

move to new initialization of field when creating BFieldCache object as a test for optimizing the speed of the bfield calculations
parent 15e98927
No related merge requests found
......@@ -15,7 +15,7 @@ atlas_add_library( MagFieldElements
PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} PathResolver )
atlas_add_test( BFieldExample_test
atlas_add_test( BFieldExample
SOURCES test/BFieldExample_test.cxx
INCLUDE_DIRS ${GTEST_INCLUDE_DIRS} #${GMOCK_INCLUDE_DIRS}
LINK_LIBRARIES TestTools CxxUtils EventPrimitives ${GTEST_LIBRARIES} #${GMOCK_LIBRARIES}
......
......@@ -55,30 +55,34 @@ public:
m_invr = 1.0 / (rmax - rmin);
m_invphi = 1.0 / (phimax - phimin);
}
// set the field values at each corner (rescale for current scale factor)
void setField(const std::array<BFieldVector<double>, 8>& field,
double scaleFactor = 1.0)
{
// We pass array of 8 elements with 3 entries
// Which go to 3x8 matrix
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 3; ++j) {
m_field[j][i] = scaleFactor * field[i][j];
}
}
}
void setField(const std::array<BFieldVector<short>, 8>& field,
double scaleFactor = 1.0)
{
// We pass array of 8 elements with 3 entries
// Which go to 3x8 matrix
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 3; ++j) {
m_field[j][i] = scaleFactor * field[i][j];
}
}
}
// **
// ** The following two methods are commented out, and replaced by the third setField as optimization test
// **
// // set the field values at each corner (rescale for current scale factor)
// void setField(const std::array<BFieldVector<double>, 8>& field,
// double scaleFactor = 1.0)
// {
// // We pass array of 8 elements with 3 entries
// // Which go to 3x8 matrix
// for (int i = 0; i < 8; ++i) {
// for (int j = 0; j < 3; ++j) {
// m_field[j][i] = scaleFactor * field[i][j];
// }
// }
// }
// void setField(const std::array<BFieldVector<short>, 8>& field,
// double scaleFactor = 1.0)
// {
// // We pass array of 8 elements with 3 entries
// // Which go to 3x8 matrix
// for (int i = 0; i < 8; ++i) {
// for (int j = 0; j < 3; ++j) {
// m_field[j][i] = scaleFactor * field[i][j];
// }
// }
// }
// set field array, filled externally
void setField(double field[][8]) {
......
......@@ -98,9 +98,6 @@ public:
double bscale() const { return m_scale; }
int memSize() const;
bool m_doNew{false};
protected:
std::array<double, 3> m_min;
std::array<double, 3> m_max;
......
......@@ -79,21 +79,21 @@ public:
BFieldCache cache3d;
double z{0}, r{1250}, phi{1.6};
if (doDebug) std::cout << "do getCache old " << std::endl;
// if (doDebug) std::cout << "do getCache old " << std::endl;
zone.m_doNew = false;
// zone.m_doNew = false;
zone.getCache(z, r, phi, cache3d, 1);
// zone.getCache(z, r, phi, cache3d, 1);
cache3d.printField();
// cache3d.printField();
if (doDebug) std::cout << "do getCache new " << std::endl;
// if (doDebug) std::cout << "do getCache new " << std::endl;
zone.m_doNew = true;
// zone.m_doNew = true;
zone.getCache(z, r, phi, cache3d, 1);
// zone.getCache(z, r, phi, cache3d, 1);
cache3d.printField();
// cache3d.printField();
// get field at steps of 10 mm from 1200 to 1300
......@@ -135,9 +135,6 @@ public:
// get field std: i, bxyz_std 9 -2.6281e-07, -8.34762e-08, -0.00165093
// get field new: i, bxyz_new 9 -2.6281e-07, -8.34762e-08, -0.00165093
// zone.m_doNew = false;
zone.m_doNew = true;
for (unsigned int i = 0; i < 10; ++i) {
double r1 = r0 + 5 + i*10.;
......@@ -152,7 +149,12 @@ public:
std::cout << "get field std: i, bxyz " << i << " "
<< bxyz[0] << ", " << bxyz[1] << ", "
<< bxyz[2] << std::endl;
<< bxyz[2]
<< " fractional diff gt 10^-5: "
<< int(fabs(bxyz[0] - bxyz_std[0][i])/bxyz[0] > 0.00001) << ", "
<< int(fabs(bxyz[1] - bxyz_std[1][i])/bxyz[1] > 0.00001) << ", "
<< int(fabs(bxyz[2] - bxyz_std[2][i])/bxyz[2] > 0.00001)
<< std::endl;
if (fabs(bxyz[0] - bxyz_std[0][i]) > 0.00001) {
std::cout << "failed bz comparison - bz, bz std " << bxyz[0] << ", " << bxyz_std[0][i] << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment