void GLGPUDataset::SerializeDataInfoToString(std::string& buf) const { #if WITH_PROTOBUF PBDataInfo pb; pb.set_model(PBDataInfo::GLGPU); pb.set_name(_data_name); if (Lengths()[0]>0) { pb.set_ox(Origins()[0]); pb.set_oy(Origins()[1]); pb.set_oz(Origins()[2]); pb.set_lx(Lengths()[0]); pb.set_ly(Lengths()[1]); pb.set_lz(Lengths()[2]); } pb.set_bx(B()[0]); pb.set_by(B()[1]); pb.set_bz(B()[2]); pb.set_kex(Kex()); pb.set_dx(dims()[0]); pb.set_dy(dims()[1]); pb.set_dz(dims()[2]); pb.set_pbc_x(pbc()[0]); pb.set_pbc_y(pbc()[0]); pb.set_pbc_z(pbc()[0]); pb.SerializeToString(&buf); #endif }
float GLGPUDataset::QP(const float X0_[], const float X1_[], int slot) const { float X0[3], X1[3]; float N[3]; for (int i=0; i<3; i++) { X0[i] = (X0_[i] - Origins()[i]) / CellLengths()[i]; X1[i] = (X1_[i] - Origins()[i]) / CellLengths()[i]; N[i] = dims()[i]; } if (B(slot)[1]>0 && fabs(X1[0]-X0[0])>N[0]/2) { // TODO assert(false); return 0.0; } else if (fabs(X1[1]-X0[1])>N[1]/2) { // pbc j float dj = X1[1] - X0[1]; if (dj > N[1]/2) dj = dj - N[1]; else if (dj < -N[1]/2) dj = dj + N[1]; float dist = fabs(dj); float dist1 = fabs(fmod1(X0[1] + N[1]/2, N[1]) - N[1]); float f = dist1/dist; // pbc k float dk = X1[2] - X0[2]; if (dk > N[2]/2) dk = dk - N[2]; else if (dk < -N[2]/2) dk = dk + N[2]; float k = fmod1(X0[2] + f*dk, N[2]); // pbc i float di = X1[0] - X0[0]; if (di > N[0]/2) di = di - N[0]; else if (di < -N[0]/2) di = di + N[0]; float i = fmod1(X0[0] + f*dk, N[0]); float sign = dj>0 ? 1 : -1; float qp = sign * (k*CellLengths()[2]*B(slot)[0]*Lengths()[1] - i*CellLengths()[0]*B(slot)[2]*Lengths()[1]); return qp; } return 0.0; }
bool SteerLib::GJK_EPA::GJK(const std::vector<Util::Vector>& _shapeA, const std::vector<Util::Vector>& _shapeB, std::vector<Util::Vector>& _simplex) { Util::Vector d(1, 0, -1); _simplex.push_back(Support(_shapeA, _shapeB, d)); d = d * -1; while (true) { _simplex.push_back(Support(_shapeA, _shapeB, d)); if (_simplex.back() * d <= 0) { return false; } else { if (Origins(_simplex, d)) return true; } } return false; }
float GLGPUDataset::QP(const float X0[], const float X1[]) const { const float *L = Lengths(), *O = Origins(); float d[3] = {X1[0] - X0[0], X1[1] - X0[1], X1[2] - X0[2]}; int p[3] = {0}; // 0: not crossed; 1: positive; -1: negative for (int i=0; i<3; i++) { d[i] = X1[i] - X0[i]; if (d[i]>L[i]/2) {d[i] -= L[i]; p[i] = 1;} else if (d[i]<-L[i]/2) {d[i] += L[i]; p[i] = -1;} } const float X[3] = {X0[0] - O[0], X0[1] - O[1], X0[2] - O[2]}; if (By()>0 && p[0]!=0) { // By>0 return p[0] * L[0] * (Bz()*X[1] - By()*X[2]); } else if (p[1]!=0) { return p[1] * L[1] * (Bx()*X[2] - Bz()*X[0]); } else return 0.0; }
void GLGPUDataset::ModulateKex(int slot) { float K = Kex(slot); float *re = slot == 0 ? _re : _re1, *im = slot == 0 ? _im : _im1; for (int i=0; i<dims()[0]; i++) for (int j=0; j<dims()[1]; j++) for (int k=0; k<dims()[2]; k++) { const int idx[3] = {i, j, k}; NodeIdType nid = Idx2Nid(idx); float x = i * CellLengths()[0] + Origins()[0]; float rho = sqrt(re[nid]*re[nid] + im[nid]*im[nid]), // phi = atan2(im[nid], re[nid]) - K*x; phi = atan2(im[nid], re[nid]) + K*x; re[nid] = rho * cos(phi); im[nid] = rho * sin(phi); } }
void GLGPUDataset::Pos2Grid(const float pos[], float gpos[]) const { for (int i=0; i<3; i++) gpos[i] = (pos[i] - Origins()[i]) / CellLengths()[i]; }
void GLGPUDataset::Pos2Idx(const float pos[], int idx[]) const { for (int i=0; i<3; i++) idx[i] = (pos[i] - Origins()[i]) / CellLengths()[i]; // TODO: perodic boundary conditions }
void GLGPUDataset::Idx2Pos(const int idx[], float pos[]) const { for (int i=0; i<3; i++) pos[i] = idx[i] * CellLengths()[i] + Origins()[i]; }