/// Returns signed 2 theta (signed scattering angle w.r.t. to beam direction). double DetectorInfo::signedTwoTheta(const std::pair<size_t, size_t> &index) const { if (isMonitor(index)) throw std::logic_error( "Two theta (scattering angle) is not defined for monitors."); const auto samplePos = samplePosition(); const auto beamLine = samplePos - sourcePosition(); if (beamLine.nullVector()) { throw Kernel::Exception::InstrumentDefinitionError( "Source and sample are at same position!"); } // Get the axis defining the sign const auto &instrumentUpAxis = m_instrument->getReferenceFrame()->vecThetaSign(); const auto sampleDetVec = position(index) - samplePos; double angle = sampleDetVec.angle(beamLine); const auto cross = beamLine.cross_prod(sampleDetVec); const auto normToSurface = beamLine.cross_prod(instrumentUpAxis); if (normToSurface.scalar_prod(cross) < 0) { angle *= -1; } return angle; }
void InstrumentRenderer::drawSingleDetector(size_t detIndex, bool picking) { const auto &compInfo = m_actor.componentInfo(); if (picking) m_pickColors[detIndex].paint(); else m_colors[detIndex].paint(); glPushMatrix(); // Translate auto pos = compInfo.position(detIndex); if (!pos.nullVector()) glTranslated(pos[0], pos[1], pos[2]); // Rotate auto rot = compInfo.rotation(detIndex); if (!rot.isNull()) { double deg, ax0, ax1, ax2; rot.getAngleAxis(deg, ax0, ax1, ax2); glRotated(deg, ax0, ax1, ax2); } // Scale auto scale = compInfo.scaleFactor(detIndex); if (scale != Mantid::Kernel::V3D(1, 1, 1)) glScaled(scale[0], scale[1], scale[2]); compInfo.shape(detIndex).draw(); glPopMatrix(); }
/// Returns 2 theta (scattering angle w.r.t. to beam direction). double DetectorInfo::twoTheta(const std::pair<size_t, size_t> &index) const { if (isMonitor(index)) throw std::logic_error( "Two theta (scattering angle) is not defined for monitors."); const auto samplePos = samplePosition(); const auto beamLine = samplePos - sourcePosition(); if (beamLine.nullVector()) { throw Kernel::Exception::InstrumentDefinitionError( "Source and sample are at same position!"); } const auto sampleDetVec = position(index) - samplePos; return sampleDetVec.angle(beamLine); }
static void leaveBootloader() { statusLedOff(); cli(); boot_rww_enable(); USB_INTR_ENABLE = 0; USB_INTR_CFG = 0; /* also reset config bits */ GICR = (1 << IVCE); /* enable change of interrupt vectors */ GICR = (0 << IVSEL); /* move interrupts to application flash section */ /* We must go through a global function pointer variable instead of writing * ((void (*)(void))0)(); * because the compiler optimizes a constant 0 to "rcall 0" which is not * handled correctly by the assembler. */ nullVector(); }
static inline __attribute__((noreturn)) void leaveBootloader(void) { DBG1(0x01, 0, 0); bootLoaderExit(); cli(); USB_INTR_ENABLE = 0; USB_INTR_CFG = 0; /* also reset config bits */ #ifdef TINY85MODE // make sure remainder of flash is erased and write checksum and application reset vectors if(appWriteComplete) { CURRENT_ADDRESS = writeSize; while(CURRENT_ADDRESS < BOOTLOADER_ADDRESS) { fillFlashWithVectors(); } } #else GICR = (1 << IVCE); /* enable change of interrupt vectors */ GICR = (0 << IVSEL); /* move interrupts to application flash section */ #endif // TODO: watchdog reset instead to reset registers? #ifdef APPCHECKSUM if(!testForValidApplication()) asm volatile ("rjmp __vectors"); #endif #ifdef TINY85MODE // clear magic word from bottom of stack before jumping to the app *(uint8_t*)(RAMEND) = 0x00; *(uint8_t*)(RAMEND-1) = 0x00; // jump to application reset vector at end of flash asm volatile ("rjmp __vectors - 4"); #else /* We must go through a global function pointer variable instead of writing * ((void (*)(void))0)(); * because the compiler optimizes a constant 0 to "rcall 0" which is not * handled correctly by the assembler. */ nullVector(); #endif }
static void leaveBootloader() { uint8_t gicr; DBG1(0x01, 0, 0); cli(); boot_rww_enable(); USB_INTR_ENABLE = 0; USB_INTR_CFG = 0; /* also reset config bits */ #if F_CPU == 12800000 TCCR0 = 0; /* default value */ #endif gicr = GICR; GICR = gicr | (1 << IVCE); /* enable change of interrupt vectors */ GICR = gicr & ~(1 << IVSEL); /* move interrupts to application flash section */ bootLoaderShut(); /* We must go through a global function pointer variable instead of writing * ((void (*)(void))0)(); * because the compiler optimizes a constant 0 to "rcall 0" which is not * handled correctly by the assembler. */ nullVector(); }
inline void computeSphereStress(){ printf("Computing sphere stress tensor...\n"); int atom, id1, id2, j; Vector atomDistance, atomForce; double r, r2; double atomArea, atomVolume; double sp_1, sp_2, sp_3; for (atom = 0; atom < pdbData.atomCount; atom++){ atomSphereStress[atom].x = 0.0; atomSphereStress[atom].y = 0.0; atomSphereStress[atom].z = 0.0; atomSphereStress[atom].value = 0.0; } for (atom = 0; atom < pdbData.atomCount; atom++){ r = 0.0; r2 = 0.0; copyVector(&atomDistance, nullVector()); copyVector(&atomForce, nullVector()); copyVector(&ePhi, DCDtoEphi(X[atom], Y[atom], Z[atom])); copyVector(&eTheta, DCDtoEtheta(X[atom], Y[atom], Z[atom])); copyVector(&eRad, DCDtoErad(X[atom], Y[atom], Z[atom])); for (j = 0; j < bondsCount[atom]; j++){ id1 = atom, id2 = bonds[atom * MAX_BONDS + j]; funcParam.refDist = bondsR0[atom * MAX_BONDS + j]; copyVector(&atomDistance, DCDtoVector(X[id1] - X[id2], Y[id1] - Y[id2], Z[id1] - Z[id2])); copyVector(&atomForce, getFENEDerivative_1(atomDistance)); sp_1 = eTheta.x * atomDistance.x + eTheta.y * atomDistance.y + eTheta.z * atomDistance.z; sp_2 = ePhi.x * atomDistance.x + ePhi.y * atomDistance.y + ePhi.z * atomDistance.z; sp_3 = eRad.x * atomDistance.x + eRad.y * atomDistance.y + eRad.z * atomDistance.z; atomSphereStress[atom].x += 0.5 * atomForce.value/atomDistance.value * (sp_1 * sp_1 + sp_2 * sp_2); //lateral atomSphereStress[atom].y += atomForce.value/atomDistance.value * sp_1 * sp_2; //45-shear atomSphereStress[atom].z += atomForce.value/atomDistance.value * sp_3 * sp_3; //radial r += 1.0/atomDistance.value; r2 += 1.0/(atomDistance.value * atomDistance.value); } for (j = 0; j < nativeCount[atom]; j++){ id1 = atom; id2 = native[atom * MAX_NATIVE + j]; funcParam.refDist = nativeR0[atom * MAX_NATIVE + j]; funcParam.Eh = nativeEh[atom * MAX_NATIVE + j]; copyVector(&atomDistance, DCDtoVector(X[id1] - X[id2], Y[id1] - Y[id2], Z[id1] - Z[id2])); copyVector(&atomForce, getNativeDerivative_1(atomDistance)); sp_1 = eTheta.x * atomDistance.x + eTheta.y * atomDistance.y + eTheta.z * atomDistance.z; sp_2 = ePhi.x * atomDistance.x + ePhi.y * atomDistance.y + ePhi.z * atomDistance.z; sp_3 = eRad.x * atomDistance.x + eRad.y * atomDistance.y + eRad.z * atomDistance.z; atomSphereStress[atom].x += 0.5 * atomForce.value/atomDistance.value * (sp_1 * sp_1 + sp_2 * sp_2); //lateral atomSphereStress[atom].y += atomForce.value/atomDistance.value * sp_1 * sp_2; //45-shear atomSphereStress[atom].z += atomForce.value/atomDistance.value * sp_3 * sp_3; //radial r += 1.0/atomDistance.value; r2 += 1.0/(atomDistance.value * atomDistance.value); } for (j = 0; j < pairsCount[atom]; j++){ id1 = atom; id2 = pairs[atom * MAX_PAIRS + j]; copyVector(&atomDistance, DCDtoVector(X[id1] - X[id2], Y[id1] - Y[id2], Z[id1] - Z[id2])); if (atomDistance.value < pairs_cutoff && id1 != id2 ){ copyVector(&atomDistance, DCDtoVector(X[id1] - X[id2], Y[id1] - Y[id2], Z[id1] - Z[id2])); copyVector(&atomForce, getRepulsiveDerivative_1(atomDistance)); sp_1 = eTheta.x * atomDistance.x + eTheta.y * atomDistance.y + eTheta.z * atomDistance.z; sp_2 = ePhi.x * atomDistance.x + ePhi.y * atomDistance.y + ePhi.z * atomDistance.z; sp_3 = eRad.x * atomDistance.x + eRad.y * atomDistance.y + eRad.z * atomDistance.z; atomSphereStress[atom].x += 0.5 * atomForce.value/atomDistance.value * (sp_1 * sp_1 + sp_2 * sp_2); //lateral atomSphereStress[atom].y += atomForce.value/atomDistance.value * sp_1 * sp_2; //45-shear atomSphereStress[atom].z += atomForce.value/atomDistance.value * sp_3 * sp_3; //radial r += 1.0/atomDistance.value; r2 += 1.0/(atomDistance.value * atomDistance.value); } } atomArea = Pi * (0.5*r/r2) * (0.5*r/r2); atomVolume = 4.0/3.0 * Pi * (0.5*r/r2) * (0.5*r/r2) * (0.5*r/r2); atomSphereStress[atom].x /= atomArea; atomSphereStress[atom].y /= atomArea; atomSphereStress[atom].z /= atomVolume; } }