kr::Mat3<Scalar> skewSymmetric2(const kr::Vec3<Scalar>& w) { kr::Mat3<Scalar> W2; W2(0, 0) = -(w[2] * w[2] + w[1] * w[1]); W2(1, 1) = -(w[2] * w[2] + w[0] * w[0]); W2(2, 2) = -(w[1] * w[1] + w[0] * w[0]); W2(1, 0) = W2(0, 1) = w[0] * w[1]; W2(2, 0) = W2(0, 2) = w[0] * w[2]; W2(1, 2) = W2(2, 1) = w[1] * w[2]; return W2; }
Array3d Analysis::getParticleFluxKy(int sp) { Array3d G(RFields, RkyLD, RsLD); G = 0.; Array3z V2(RxLD, RkyLD, RzLD); V2 = 0.; Array3z W2(RxLD, RkyLD, RzLD); W2 = 0.; for(int s = NsLlD; s <= NsLuD; s++) { const double d6Z = M_PI * plasma->species(s).n0 * plasma->species(s).T0 * plasma->B0 * dv * dm * scaleXYZ; for(int m=NmLlD; m<= NmLuD;m++ ) { for(int z=NzLlD; z<= NzLuD;z++){ // multiply in real-space for(int x=NxLlD; x <= NxLuD ; x++) { for(int y_k=NkyLlD; y_k<= NkyLuD;y_k++) { const cmplxd ky=cmplxd(0.,-fft->ky(y_k)); V2(x,y_k,z) = ky * fields->phi(x,y_k,z,m,s); // integrate over velocity space W2(x,y_k,z) = sum(vlasov->f(x, y_k, z, RvLD, m, s)) * d6Z; }} // V2(RxLD, RkyLD, RzLD) = fft->multiply(V2, W2, A_xyz); // sum over x and z for(int x=NxLlD; x <= NxLuD ; x++) { G(Field::phi, RkyLD, s) += abs(A_xyz(x, RkyLD,z)) ; } } } } return parallel->collect(G); };
// note the hear flux rate have to be calculted after getkinetic energy // this should go hand-in-hand with the temperature calculation Array4z Analysis::getHeatFlux(int sp) { A4_z = 0.; Array3z V2(RxLD, RkyLD, RzLD); Array3z W2(RxLD, RkyLD, RzLD); //for(int s = ((sp == TOTAL) ? NsLlD : sp); s <= NsLuD && ((sp != TOTAL) ? s == sp : true) ; s++) { // for(int s = ((sp == TOTAL) ? NsLlD : sp); (s <= ((sp == TOTAL) ? NsLuD : sp)) && ( (sp >= NsLlD) && (sp <= NsLuD)) ; s++) { for(int s = NsLlD; s <= NsLuD; s++) { const double d6Z = M_PI * plasma->species(s).n0 * plasma->species(s).T0 * plasma->B0 * dv * dm * scaleXYZ; for(int m=NmLlD; m<= NmLuD;m++ ) { V2 = 0.; W2 = 0.; // multiply in real-space for(int z=NzLlD; z<= NzLuD;z++){ for(int x=NxLlD; x <= NxLuD ; x++) { for(int y_k=NkyLlD; y_k<= NkyLuD;y_k++) { const cmplxd ky=cmplxd(0.,-fft->ky(y_k)); V2(x,y_k,z) = ky * fields->phi(x,y_k,z,m,s); // integrate over velocity space for(int v=NvLlD; v<= NvLuD;v++) W2(x,y_k,z) += (pow2(V(v)) + M(m) * plasma->B0) * vlasov->f(x, y_k, z, v, m, s) * d6Z; }}} A4_z(RxLD, RkyLD, RzLD,s) = fft->multiply(V2, W2, A_xyz); } } return parallel->collect(A4_z, OP_SUM, DIR_VM); };
// ------------------ TEST(Array, CrossConstruct2) { array<long, 2> A(2, 3); for (int i = 0; i < 2; ++i) for (int j = 0; j < 3; ++j) A(i, j) = 10 * i + j; std::vector<array<long, 2>> V(3, A); std::vector<array_view<long, 2>> W; for (auto& x : V) W.push_back(x); std::vector<array_view<long, 2>> W2(W); for (int i = 1; i < 3; ++i) V[i] *= i; for (int i = 1; i < 3; ++i) EXPECT_ARRAY_NEAR(W2[i], i * A); }
virtual void paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); int xOffset = -70; int yOffset = -50; int zoom = -200; glTranslatef(xOffset, yOffset, zoom); glColor3f(0.0f, 0.0f, 0.0f); glLineWidth(5.0); float scale = 1.0; if(showFilters) { Eigen::MatrixXd W1 = sae.getInputWeights(); Eigen::MatrixXd W2 = sae.getOutputWeights(); double mi = sae.getInputWeights().minCoeff(); double ma = sae.getInputWeights().maxCoeff(); double range = ma - mi; for(int row = 0, filter = 0; row < neuronRows; row++) { for(int col = 0; col < neuronCols; col++, filter++) { glBegin(GL_QUADS); for(int yIdx = 0; yIdx < 28; yIdx++) { for(int xIdx = 0; xIdx < 28; xIdx++) { int h = (filter + offset) / 2; bool in = (filter + offset) % 2 == 0; int idx = yIdx * 28 + xIdx; float c = ((in ? W1(h, idx) : W2(idx, h)) - mi) / range; float x = xIdx * scale + col * 29.0f * scale - 30.0f; float y = (28.0f - yIdx) * scale - row * scale * 29.0f + 90.0f; glColor3f(c, c, c); glVertex2f(x, y); glVertex2f(x + scale, y); glVertex2f(x + scale, y + scale); glVertex2f(x, y + scale); } } glEnd(); } } } else { for(int row = 0; row < neuronRows; row++) { for(int col = 0; col < neuronCols; col++) { Eigen::VectorXd out = sae.reconstruct(dataSet.getInstance(offset + row*neuronCols+col)); glBegin(GL_QUADS); for(int yIdx = 0; yIdx < 28; yIdx++) { for(int xIdx = 0; xIdx < 28; xIdx++) { int idx = yIdx * 28 + xIdx; float c = out(idx); float x = xIdx * scale + col * 29.0f * scale - 30.0f; float y = (28.0f - yIdx) * scale - row * scale * 29.0f + 90.0f; glColor3f(c, c, c); glVertex2f(x, y); glVertex2f(x + scale, y); glVertex2f(x + scale, y + scale); glVertex2f(x, y + scale); } } glEnd(); } } } glColor3f(0.0f, 0.0f, 0.0f); renderText(10, 35, "MNIST data set", QFont("Helvetica", 20)); glFlush(); }
void rotation(double *vo, double *vt, int n, symatrix &R) { int i,j,k; symatrix A(4),AT(4),C(4),W(3),W2(3),RS(3); double **B,**U,eval[5],gamma; // char s[100]; B = dmatrix(1,4,1,4); U = dmatrix(1,4,1,4); for (i = 1; i <= 4; i++) for (j = 1; j <= 4; j++) B[i][j] = 0.0; for (i = 0; i < 4; i++) A.el(i,i) = 0.0; for (k = 0; k < n; k++) { A.el(0,1) = vo[3*k+2] + vt[3*k+2]; A.el(0,2) = -vo[3*k+1] - vt[3*k+1]; A.el(1,2) = vo[3*k] + vt[3*k]; for (i = 0; i < 3; i++) A.el(i,3) = vo[3*k+i] - vt[3*k+i]; for (i = 1; i < 4; i++) for (j = 0; j < i; j++) A.el(i,j) = -A.el(j,i); AT = A.transpose(); C = A * AT; for (i = 0; i < 4; i++) for (j = 0; j < 4; j++) { B[i+1][j+1] += C.el(i,j); } } djacobi(B,4,eval,U,&i); deigsrt(eval,U,4); R.identity(); RS.identity(); gamma = 2 * acos(U[4][4]); for (i = 0; i < 3; i++) W.el(i,i) = 0.0; W.el(0,1) = U[3][4] / sin(gamma/2); W.el(0,2) = -U[2][4] / sin(gamma/2); W.el(1,2) = U[1][4] / sin(gamma/2); for (i = 1; i < 3; i++) for (j = 0; j < i; j++) W.el(i,j) = - W.el(j,i); W2 = W * W; for (i = 0; i < 3; i++) { W.multiply_col(i,sin(gamma)); W2.multiply_col(i,1-cos(gamma)); } RS += (W + W2); RS = RS.transpose(); for (i = 0; i < 3; i++) for (j = 0; j < 3; j++) R.el(i,j) = RS.el(i,j); free_dmatrix(B,1,4,1,4); free_dmatrix(U,1,4,1,4); }