GdkPixmap * ghid_render_pixmap (int cx, int cy, double zoom, int width, int height, int depth) { extern HID ghid_hid; GdkPixmap *pixmap; GdkDrawable *save_drawable; double save_zoom; int save_left, save_top; int save_width, save_height; int save_view_width, save_view_height; BoxType region; save_drawable = gport->drawable; save_zoom = gport->zoom; save_width = gport->width; save_height = gport->height; save_left = gport->view_x0; save_top = gport->view_y0; save_view_width = gport->view_width; save_view_height = gport->view_height; pixmap = gdk_pixmap_new (NULL, width, height, depth); /* Setup drawable and zoom factor for drawing routines */ gport->drawable = pixmap; gport->zoom = zoom; gport->width = width; gport->height = height; gport->view_width = width * gport->zoom; gport->view_height = height * gport->zoom; gport->view_x0 = ghid_flip_x ? PCB->MaxWidth - cx : cx; gport->view_x0 -= gport->view_height / 2; gport->view_y0 = ghid_flip_y ? PCB->MaxHeight - cy : cy; gport->view_y0 -= gport->view_width / 2; /* clear background */ gdk_draw_rectangle (pixmap, gport->bg_gc, TRUE, 0, 0, width, height); /* call the drawing routine */ region.X1 = MIN(Px(0), Px(gport->width + 1)); region.Y1 = MIN(Py(0), Py(gport->height + 1)); region.X2 = MAX(Px(0), Px(gport->width + 1)); region.Y2 = MAX(Py(0), Py(gport->height + 1)); hid_expose_callback (&ghid_hid, ®ion, NULL); gport->drawable = save_drawable; gport->zoom = save_zoom; gport->width = save_width; gport->height = save_height; gport->view_x0 = save_left; gport->view_y0 = save_top; gport->view_width = save_view_width; gport->view_height = save_view_height; return pixmap; }
GdkPixmap * ghid_render_pixmap (int cx, int cy, double zoom, int width, int height, int depth) { GdkPixmap *pixmap; GdkDrawable *save_drawable; view_data save_view; int save_width, save_height; BoxType region; render_priv *priv = gport->render_priv; save_drawable = gport->drawable; save_view = gport->view; save_width = gport->width; save_height = gport->height; pixmap = gdk_pixmap_new (NULL, width, height, depth); /* Setup drawable and zoom factor for drawing routines */ gport->drawable = pixmap; gport->view.coord_per_px = zoom; gport->width = width; gport->height = height; gport->view.width = width * gport->view.coord_per_px; gport->view.height = height * gport->view.coord_per_px; gport->view.x0 = gport->view.flip_x ? PCB->MaxWidth - cx : cx; gport->view.x0 -= gport->view.height / 2; gport->view.y0 = gport->view.flip_y ? PCB->MaxHeight - cy : cy; gport->view.y0 -= gport->view.width / 2; /* clear background */ gdk_draw_rectangle (pixmap, priv->bg_gc, TRUE, 0, 0, width, height); /* call the drawing routine */ region.X1 = MIN(Px(0), Px(gport->width + 1)); region.Y1 = MIN(Py(0), Py(gport->height + 1)); region.X2 = MAX(Px(0), Px(gport->width + 1)); region.Y2 = MAX(Py(0), Py(gport->height + 1)); region.X1 = MAX (0, MIN (PCB->MaxWidth, region.X1)); region.X2 = MAX (0, MIN (PCB->MaxWidth, region.X2)); region.Y1 = MAX (0, MIN (PCB->MaxHeight, region.Y1)); region.Y2 = MAX (0, MIN (PCB->MaxHeight, region.Y2)); hid_expose_callback (&ghid_hid, ®ion, NULL); gport->drawable = save_drawable; gport->view = save_view; gport->width = save_width; gport->height = save_height; return pixmap; }
boost::shared_ptr<Mesh<Simplex<2> > > createSubMeshLaplacianBlock(boost::shared_ptr<Mesh<Simplex<2> > > mesh) { auto P0d = Pdh<0>(mesh); double r=0.2; auto proj = vf::project(_space=P0d,_range=elements(mesh), _expr=vf::chi( (Px()*Px()+Py()*Py()) < r*r ) ); mesh->updateMarker3( proj ); auto submesh = createSubmesh( mesh, marked3elements(mesh,1) ); //saveGMSHMesh(_mesh=submesh,_filename="mysubmesh.msh"); return submesh; }
void HHV4Vector::Rotate(const HHV4Vector & q) { Double_t ex, ey, ez, en; Double_t a, b, c, d, px1, py1, pz1, px2, py2, pz2, px3, py3, pz3; px1 = Px(); py1 = Py(); pz1 = Pz(); ex = q.Px(); ey = q.Py(); ez = q.Pz(); en = sqrt(ex * ex + ey * ey + ez * ez); ex = ex / en; ey = ey / en; ez = ez / en; // cout << "Rotate e: " << ex << " " << ey << " " << ez << endl; a = ez; b = sqrt(1. - a * a); c = ex / b; d = -ey / b; px2 = a * px1 + b * pz1; // rotation around y-axis py2 = py1; pz2 = -b * px1 + a * pz1; // cout << "Rotate p2: " << px2 << " " << py2 << " " << pz2 << endl; px3 = c * px2 + d * py2; // rotation around z-axis py3 = -d * px2 + c * py2; pz3 = pz2; // cout << "Rotate p3: " << px3 << " " << py3 << " " << pz3 << endl; SetPxPyPzE(px3, py3, pz3, E()); }
void HHV4Vector::Draw(Int_t color, Int_t style) const { // draw particle for event display in x-y view TArrow *Ar = new TArrow(0, 0, Px(), Py(), 0.001, "|>"); Ar->SetLineColor(color); Ar->SetFillColor(color); Ar->SetLineWidth(3); Ar->SetLineStyle(style); Ar->Draw(); }
void cv<Dim,Order>::run() { auto mesh = loadMesh(_mesh = new mesh_type ,_update = MESH_CHECK|MESH_UPDATE_FACES|MESH_UPDATE_EDGES|MESH_RENUMBER ); auto Xh = space_type::New( mesh ); auto phi = Xh->element(); phi = vf::project(Xh,elements(mesh),Px()+Py()); auto e = exporter(_mesh= mesh,_name= "myExporter"); e->add( "phi", phi ); e->save(); }
void SecondTimer(void) { send("0123456789", 10, 1); fprintf(stdout, "S\n"); fflush(stdout); g_nSecCount++; if ( g_nSecCount > 5 ) { g_nSecCount = 0; if ( g_nTestValue == 0 ) { g_nTestValue = 1; Py(CKT1_SST, g_nTestValue); } else { g_nTestValue = 0; Py(CKT1_SST, g_nTestValue); } } }
void HHV4Vector::Boost(Double_t bx, Double_t by, Double_t bz) { //Boost this Lorentz vector //cout << "Boost: beta " << bx << " " << by << " " << bz << " " << bx**2+by**2+bz**2 << endl; // cout << "Boost: P " << Px()<<" " << Py()<<" " << Pz()<<" " << endl; Double_t b2 = bx * bx + by * by + bz * bz; Double_t gamma = 1.0 / sqrt(1.0 - b2); Double_t bp = bx * Px() + by * Py() + bz * Pz(); Double_t gamma2 = b2 > 0 ? (gamma - 1.0) / b2 : 0.0; Double_t px, py, pz; // cout << "Boost: b2,g,bp,g2: " << b2 << " " << gamma << " " << bp << " " << gamma2 << endl; px = Px() + gamma2 * bp * bx + gamma * bx * E(); py = Py() + gamma2 * bp * by + gamma * by * E(); pz = Pz() + gamma2 * bp * bz + gamma * bz * E(); m_e = gamma * (E() + bp); m_phi = atan2(py, px); m_eta = -log(tan(0.5 * acos(pz / sqrt(px * px + py * py + pz * pz)))); // cout << "Boost: E " << E << " px " << px<< " py " << py<< " pz " << pz // << " Phi " <<Phi<<" Eta " <<Eta << endl; }
void cv<Dim,Order>::run() { auto mesh = loadMesh(_mesh = new mesh_type ,_update = MESH_CHECK|MESH_UPDATE_FACES|MESH_UPDATE_EDGES|MESH_RENUMBER ); auto Xh = space_type::New( mesh ); auto Xhm1 = space_pm1_type::New( mesh ); auto Xhm1vec = space_pm1vec_type::New( mesh ); auto phi = Xh->element(); auto gphi = Xhm1vec->element(); auto gphi0 = Xhm1->element(); phi = vf::project(Xh,elements(mesh), Px()*Px() + Py()*Py() ); // P0 vector gphi = vf::project(Xhm1vec, elements(mesh), trans( gradv(phi) ) ); // P0 scalar auto gphi_compx = gphi.comp( ( ComponentType )0 ); gphi0 = vf::project(Xhm1, elements(mesh), idv(gphi_compx) ); auto e = exporter(_mesh = mesh, _name = "myExporter"); e->add( "phi", phi ); e->add( "grad_phi", gphi ); e->add( "grad_phi0", gphi0 ); e->save(); }
double gcta::lgL_reduce_mdl(double y_Ssq, bool no_constrain) { if(_r_indx.size()==0) return 0; bool multi_comp=(_r_indx.size()-_r_indx_drop.size()>1); cout<<"\nCalculating the logLikelihood for the reduced model ...\n(variance component"<<(multi_comp?"s ":" "); for(int i=0; i<_r_indx.size(); i++){ if(find(_r_indx_drop.begin(), _r_indx_drop.end(), _r_indx[i])==_r_indx_drop.end()) cout<<_r_indx[i]+1<<" "; } cout<<(multi_comp?"are":"is")<<" dropped from the model)"<<endl; vector<int> vi_buf(_r_indx); _r_indx=_r_indx_drop; eigenMatrix Vi_X(_n, _X_c), Xt_Vi_X_i(_X_c, _X_c), Hi(_r_indx.size()+1, _r_indx.size()+1); eigenVector Py(_n); eigenVector varcmp(_r_indx.size()+1); varcmp.setConstant(y_Ssq/(_r_indx.size()+1)); double lgL=reml_iteration(y_Ssq, Vi_X, Xt_Vi_X_i, Hi, Py, varcmp, false, no_constrain); _r_indx=vi_buf; return(lgL); }
void computeMIvalues(vector< vector< double> > *mm, MIvalues *val) { if (!check_jointmatrix(mm)) {throw notajointmatrix();} int m=mm->size(); int n=(*mm)[0].size(); vector <double> Px (m,0.0E-20); int p,q; for(p=0; p < m; p++) for (q=0; q<n; q++) { Px[p]+= (*mm)[p][q]; } //for(p=0; p < m; p++) {cout << "Px " << Px[p] << "\n";} (*val).Hx = entropy(&Px); //cout << "Hx " << (*val).Hx << "\n"; vector <double> Py (n,0.0E-20); for (q=0; q<n; q++) for(p=0; p < m; p++) { Py[q] += (*mm)[p][q]; } //for(q=0; q < n; q++) {cout << "Py " << Py[q] << "\n";} (*val).Hy = entropy(&Py); //cout << "Hy " << (*val).Hy << "\n"; double HXY=0.0E-20; for (q=0; q<n; q++) for(p=0; p < m; p++) { if ((*mm)[p][q] > 0) { HXY = HXY + (*mm)[p][q] * MyLog((*mm)[p][q]);} } //cout << "TT " << (*mm)[11][11] * MyLog((*mm)[11][11]) << " \n"; //cout << "HXY " << HXY << " \n"; (*val).I=(*val).Hy + (*val).Hx + HXY; }
void PreconditionerBlockMS<space_type>::initAMS( void ) { M_grad = Grad( _domainSpace=M_Qh, _imageSpace=M_Vh); // This preconditioner is linked to that backend : the backend will // automatically use the preconditioner. auto prec = preconditioner(_pc=pcTypeConvertStrToEnum(soption(M_prefix_11+".pc-type")), _backend=backend(_name=M_prefix_11), _prefix=M_prefix_11, _matrix=M_11 ); prec->setMatrix(M_11); prec->attachAuxiliarySparseMatrix("G",M_grad.matPtr()); if(boption(M_prefix_11+".useEdge")) { LOG(INFO) << "[ AMS ] : using SetConstantEdgeVector \n"; ozz.on(_range=elements(M_Vh->mesh()),_expr=vec(cst(1),cst(0),cst(0))); zoz.on(_range=elements(M_Vh->mesh()),_expr=vec(cst(0),cst(1),cst(0))); zzo.on(_range=elements(M_Vh->mesh()),_expr=vec(cst(0),cst(0),cst(1))); *M_ozz = ozz; M_ozz->close(); *M_zoz = zoz; M_zoz->close(); *M_zzo = zzo; M_zzo->close(); prec->attachAuxiliaryVector("Px",M_ozz); prec->attachAuxiliaryVector("Py",M_zoz); prec->attachAuxiliaryVector("Pz",M_zzo); } else { LOG(INFO) << "[ AMS ] : using SetCoordinates \n"; X.on(_range=elements(M_Vh->mesh()),_expr=Px()); Y.on(_range=elements(M_Vh->mesh()),_expr=Py()); Z.on(_range=elements(M_Vh->mesh()),_expr=Pz()); *M_X = X; M_X->close(); *M_Y = Y; M_Y->close(); *M_Z = Z; M_Z->close(); prec->attachAuxiliaryVector("X",M_X); prec->attachAuxiliaryVector("Y",M_Y); prec->attachAuxiliaryVector("Z",M_Z); } }
void HHV4Vector::PrintEPxPyPzM(int pos) const { if (pos >= 0) { PSTools::coutf(4, pos); std::cout << " "; } PSTools::coutf(10, m_name); PSTools::coutf(4, ID()); PSTools::coutf(9, 2, E()); PSTools::coutf(9, 2, Px()); PSTools::coutf(9, 2, Py()); PSTools::coutf(9, 2, Pz()); PSTools::coutf(9, 2, M()); PSTools::coutf(5, Mother()); for (int i = 0; i < nDaughter(); i++) { PSTools::coutf(4, Daughter(i)); } std::cout << std::endl; // cout << Name << " " << ID << " "; // Printf(" (EPxPyPzM)= %8.2f %8.2f %8.2f %8.2f %8.2f", E(), Px(), Py(), // Pz(), M()); }
boca::LorentzVector< Momentum > PseudoJet::LorentzVector() const { return {Px(), Py(), Pz(), Energy()}; }
Vector2<Momentum> PseudoJet::Transverse() const { return {Px(), Py()}; }
void ghid_invalidate_all () { int eleft, eright, etop, ebottom; BoxType region; if (!gport->pixmap) return; region.X1 = MIN(Px(0), Px(gport->width + 1)); region.Y1 = MIN(Py(0), Py(gport->height + 1)); region.X2 = MAX(Px(0), Px(gport->width + 1)); region.Y2 = MAX(Py(0), Py(gport->height + 1)); eleft = Vx (0); eright = Vx (PCB->MaxWidth); etop = Vy (0); ebottom = Vy (PCB->MaxHeight); if (eleft > eright) { int tmp = eleft; eleft = eright; eright = tmp; } if (etop > ebottom) { int tmp = etop; etop = ebottom; ebottom = tmp; } if (eleft > 0) gdk_draw_rectangle (gport->drawable, gport->offlimits_gc, 1, 0, 0, eleft, gport->height); else eleft = 0; if (eright < gport->width) gdk_draw_rectangle (gport->drawable, gport->offlimits_gc, 1, eright, 0, gport->width - eright, gport->height); else eright = gport->width; if (etop > 0) gdk_draw_rectangle (gport->drawable, gport->offlimits_gc, 1, eleft, 0, eright - eleft + 1, etop); else etop = 0; if (ebottom < gport->height) gdk_draw_rectangle (gport->drawable, gport->offlimits_gc, 1, eleft, ebottom, eright - eleft + 1, gport->height - ebottom); else ebottom = gport->height; gdk_draw_rectangle (gport->drawable, gport->bg_gc, 1, eleft, etop, eright - eleft + 1, ebottom - etop + 1); ghid_draw_bg_image(); hid_expose_callback (&ghid_hid, ®ion, 0); ghid_draw_grid (); if (ghidgui->need_restore_crosshair) RestoreCrosshair (FALSE); ghidgui->need_restore_crosshair = FALSE; ghid_screen_update (); }
void gcta::reml(bool pred_rand_eff, bool est_fix_eff, vector<double> &reml_priors, vector<double> &reml_priors_var, double prevalence, bool no_constrain, bool no_lrt, bool mlmassoc) { int i=0, j=0, k=0; // case-control double ncase=0.0; bool flag_cc=check_case_control(ncase); if(flag_cc){ if(mlmassoc) throw("Error: the option --mlm-assoc is valid for the quantitative trait only."); if(prevalence<-1) cout<<"Warning: please specify the disease prevalence by the option --prevalence so that GCTA can transform the variance explained to the underlying liability scale."<<endl; } // Initialize variance component // 0: AI; 1: REML equation; 2: EM stringstream errmsg; double d_buf=0.0, y_mean=_y.mean(); eigenVector y(_y); for(i=0; i<_n; i++) y(i)-=y_mean; double y_Ssq=y.squaredNorm()/(_n-1.0); if(!(fabs(y_Ssq)<1e30)) throw("Error: the phenotypic variance is infinite. Please check the missing data in your phenotype file. Missing values should be represented by \"NA\" or \"-9\"."); bool reml_priors_flag=!reml_priors.empty(), reml_priors_var_flag=!reml_priors_var.empty(); if(reml_priors_flag && reml_priors.size()<_r_indx.size()){ errmsg<<"Error: in option --reml-priors. There are "<<_r_indx.size()+1<<" variance components. At least "<<_r_indx.size()<<" prior values should be specified."; throw(errmsg.str()); } if(reml_priors_var_flag && reml_priors_var.size()<_r_indx.size()){ errmsg<<"Error: in option --reml-priors-var. There are "<<_r_indx.size()+1<<" variance components. At least "<<_r_indx.size()<<" prior values should be specified."; throw(errmsg.str()); } cout<<"\nPerforming REML analysis ... (NOTE: may take hours depending on sample size)."<<endl; if(_n<10) throw("Error: sample size is too small."); cout<<_n<<" observations, "<<_X_c<<" fixed effect(s), and "<<_r_indx.size()+1<<" variance component(s)(including residual variance)."<<endl; eigenMatrix Vi_X(_n, _X_c), Xt_Vi_X_i(_X_c, _X_c), Hi(_r_indx.size()+1, _r_indx.size()+1); eigenVector Py(_n), varcmp(_r_indx.size()+1); if(reml_priors_var_flag){ for(i=0; i<_r_indx.size(); i++) varcmp[i]=reml_priors_var[i]; if(varcmp[_r_indx.size()]<1e-30) varcmp[i]=y_Ssq-varcmp.sum(); } else if(reml_priors_flag){ for(i=0; i<_r_indx.size(); i++) { varcmp[i]=reml_priors[i]*y_Ssq; d_buf+=reml_priors[i]; } varcmp[_r_indx.size()]=(1.0-d_buf)*y_Ssq; } else varcmp.setConstant(y_Ssq/(_r_indx.size()+1)); double lgL=reml_iteration(y_Ssq, Vi_X, Xt_Vi_X_i, Hi, Py, varcmp, reml_priors_var_flag|reml_priors_flag, no_constrain); eigenMatrix u; if(pred_rand_eff){ u.resize(_n, _r_indx.size()); for(i=0; i<_r_indx.size(); i++) (u.col(i))=(((_A.block(0,_r_indx[i]*_n,_n,_n))*Py)*varcmp[i]); } eigenVector b; if(est_fix_eff){ b.resize(_X_c); b=Xt_Vi_X_i*(Vi_X.transpose()*_y); } // calculate Hsq and SE double Vp=0.0, VarVp=0.0, Vp_f=0.0, VarVp_f=0.0; vector<double> Hsq(_r_indx.size()), VarHsq(_r_indx.size()); calcu_Vp(Vp, VarVp, -1, varcmp, Hi); for(i=0; i<_r_indx.size(); i++) calcu_hsq(i, Vp, VarVp, -1, Hsq[i], VarHsq[i], varcmp, Hi); // calculate the logL for a reduce model double lgL_rdu_mdl=0.0, LRT=0.0; if(!no_lrt){ lgL_rdu_mdl=lgL_reduce_mdl(y_Ssq, no_constrain); LRT=2.0*(lgL-lgL_rdu_mdl); if(LRT<0.0) LRT=0.0; } // output results cout<<"\nSummary result of REML analysis:"<<endl; cout<<"Source\tVariance\tSE"<<setiosflags(ios::fixed)<<setprecision(6)<<endl; for(i=0; i<_r_indx.size()+1; i++) cout<<_var_name[i]<<"\t"<<varcmp[i]<<"\t"<<sqrt(Hi(i,i))<<endl; cout<<"Vp\t"<<Vp<<"\t"<<sqrt(VarVp)<<endl; for(i=0; i<_r_indx.size(); i++) cout<<_hsq_name[i]<<"\t"<<Hsq[i]<<"\t"<<sqrt(VarHsq[i])<<endl; if(flag_cc && prevalence>-1){ cout<<"The estimate of variance explained on the observed scale is transformed to that on the underlying scale:"<<endl; cout<<"(Proportion of cases in the sample = "<<ncase<<"; User-specified disease prevalence = "<<prevalence<<")"<<endl; for(i=0; i<_r_indx.size(); i++) cout<<_hsq_name[i]<<"_L\t"<<transform_hsq_L(ncase, prevalence, Hsq[i])<<"\t"<<transform_hsq_L(ncase, prevalence, sqrt(VarHsq[i]))<<endl; } if(mlmassoc) return; cout<<"\nCovariance/Variance/Correlation Matrix:"<<endl; for(i=0; i<_r_indx.size()+1; i++){ for(j=0; j<=i; j++) cout<<setiosflags(ios::scientific)<<Hi(i,j)<<"\t"; cout<<endl; } if(est_fix_eff){ cout<<"Estimate"<<(_X_c>1?"s":"")<<"of fixed effect"<<(_X_c>1?"s":"")<<":"<<endl; cout<<"\nSource\tEstimate\tSE"<<endl; for(i=0; i<_X_c; i++){ if(i==0) cout<<"mean\t"; else cout<<"X_"<<i+1<<"\t"; cout<<setiosflags(ios::fixed)<<b[i]<<"\t"<<sqrt(Xt_Vi_X_i(i,i))<<endl; } } // save summary result into a file string reml_rst_file=_out+".hsq"; ofstream o_reml(reml_rst_file.c_str()); o_reml<<"Source\tVariance\tSE"<<setiosflags(ios::fixed)<<setprecision(6)<<endl; for(i=0; i<_r_indx.size()+1; i++) o_reml<<_var_name[i]<<"\t"<<varcmp[i]<<"\t"<<sqrt(Hi(i,i))<<endl; o_reml<<"Vp\t"<<Vp<<"\t"<<sqrt(VarVp)<<endl; for(i=0; i<_r_indx.size(); i++) o_reml<<_hsq_name[i]<<"\t"<<Hsq[i]<<"\t"<<sqrt(VarHsq[i])<<endl; if(flag_cc && prevalence>-1){ o_reml<<"The estimate of variance explained on the observed scale is transformed to that on the underlying scale:"<<endl; o_reml<<"(Proportion of cases in the sample = "<<ncase<<"; User-specified disease prevalence = "<<prevalence<<")"<<endl; for(i=0; i<_r_indx.size(); i++) o_reml<<_hsq_name[i]<<"_L\t"<<transform_hsq_L(ncase, prevalence, Hsq[i])<<"\t"<<transform_hsq_L(ncase, prevalence, sqrt(VarHsq[i]))<<endl; } o_reml<<"logL\t"<<setprecision(3)<<lgL<<endl; if(!no_lrt && _r_indx.size()>0){ o_reml<<"logL0\t"<<setprecision(3)<<lgL_rdu_mdl<<endl; o_reml<<"LRT\t"<<setprecision(3)<<LRT<<endl; o_reml<<"Pval\t"<<setiosflags(ios::scientific)<<0.5*StatFunc::chi_prob(_r_indx.size()-_r_indx_drop.size(), LRT)<<setiosflags(ios::fixed)<<endl; } o_reml<<"n\t"<<_n<<endl; if(est_fix_eff){ o_reml<<"\nFix_eff\tSE"<<endl; for(i=0; i<_X_c; i++) o_reml<<setprecision(6)<<b[i]<<"\t"<<sqrt(Xt_Vi_X_i(i,i))<<endl; o_reml.close(); } cout<<"\nSummary result of REML analysis has been saved in the file ["+reml_rst_file+"]."<<endl; // save random effect to a file if(pred_rand_eff){ string rand_eff_file=_out+".indi.blp"; ofstream o_rand_eff(rand_eff_file.c_str()); for(i=0; i<_keep.size(); i++){ o_rand_eff<<_fid[_keep[i]]<<"\t"<<_pid[_keep[i]]<<"\t"; for(j=0; j<_r_indx.size(); j++) o_rand_eff<<setprecision(6)<<Py[i]*varcmp[j]<<"\t"<<u(i,j)<<"\t"; o_rand_eff<<endl; } cout<<"\nBLUP of the genetic effects for "<<_keep.size()<<" individuals has been saved in the file ["+rand_eff_file+"]."<<endl; } }
static void redraw_region (GdkRectangle *rect) { int eleft, eright, etop, ebottom; BoxType region; render_priv *priv = gport->render_priv; if (!gport->pixmap) return; if (rect != NULL) { priv->clip_rect = *rect; priv->clip = true; } else { priv->clip_rect.x = 0; priv->clip_rect.y = 0; priv->clip_rect.width = gport->width; priv->clip_rect.height = gport->height; priv->clip = false; } set_clip (priv, priv->bg_gc); set_clip (priv, priv->offlimits_gc); set_clip (priv, priv->mask_gc); set_clip (priv, priv->grid_gc); region.X1 = MIN(Px(priv->clip_rect.x), Px(priv->clip_rect.x + priv->clip_rect.width + 1)); region.Y1 = MIN(Py(priv->clip_rect.y), Py(priv->clip_rect.y + priv->clip_rect.height + 1)); region.X2 = MAX(Px(priv->clip_rect.x), Px(priv->clip_rect.x + priv->clip_rect.width + 1)); region.Y2 = MAX(Py(priv->clip_rect.y), Py(priv->clip_rect.y + priv->clip_rect.height + 1)); region.X1 = MAX (0, MIN (PCB->MaxWidth, region.X1)); region.X2 = MAX (0, MIN (PCB->MaxWidth, region.X2)); region.Y1 = MAX (0, MIN (PCB->MaxHeight, region.Y1)); region.Y2 = MAX (0, MIN (PCB->MaxHeight, region.Y2)); eleft = Vx (0); eright = Vx (PCB->MaxWidth); etop = Vy (0); ebottom = Vy (PCB->MaxHeight); if (eleft > eright) { int tmp = eleft; eleft = eright; eright = tmp; } if (etop > ebottom) { int tmp = etop; etop = ebottom; ebottom = tmp; } if (eleft > 0) gdk_draw_rectangle (gport->drawable, priv->offlimits_gc, 1, 0, 0, eleft, gport->height); else eleft = 0; if (eright < gport->width) gdk_draw_rectangle (gport->drawable, priv->offlimits_gc, 1, eright, 0, gport->width - eright, gport->height); else eright = gport->width; if (etop > 0) gdk_draw_rectangle (gport->drawable, priv->offlimits_gc, 1, eleft, 0, eright - eleft + 1, etop); else etop = 0; if (ebottom < gport->height) gdk_draw_rectangle (gport->drawable, priv->offlimits_gc, 1, eleft, ebottom, eright - eleft + 1, gport->height - ebottom); else ebottom = gport->height; gdk_draw_rectangle (gport->drawable, priv->bg_gc, 1, eleft, etop, eright - eleft + 1, ebottom - etop + 1); ghid_draw_bg_image(); hid_expose_callback (&ghid_hid, ®ion, 0); ghid_draw_grid (); /* In some cases we are called with the crosshair still off */ if (priv->attached_invalidate_depth == 0) DrawAttached (); /* In some cases we are called with the mark still off */ if (priv->mark_invalidate_depth == 0) DrawMark (); draw_lead_user (priv); priv->clip = false; /* Rest the clip for bg_gc, as it is used outside this function */ gdk_gc_set_clip_mask (priv->bg_gc, NULL); }
Vector3< Momentum > PseudoJet::Spatial() const { return {Px(), Py(), Pz()}; }
void run() { Environment::changeRepository( boost::format( "/testsuite/feeldiscr/%1%/P%2%/" ) % Environment::about().appName() % OrderPoly ); /* change parameters below */ const int nDim = 2; const int nOrderPoly = OrderPoly; const int nOrderGeo = 1; //------------------------------------------------------------------------------// typedef Mesh< Simplex<nDim, 1,nDim> > mesh_type; typedef Mesh< Simplex<nDim, 1,nDim> > mesh_bis_type; double meshSize = option("hsize").as<double>(); double meshSizeBis = option("hsize-bis").as<double>(); // mesh GeoTool::Node x1( 0,0 ); GeoTool::Node x2( 4,1 ); GeoTool::Rectangle Omega( meshSize,"Omega",x1,x2 ); Omega.setMarker( _type="line",_name="Entree",_marker4=true ); Omega.setMarker( _type="line",_name="Sortie",_marker2=true ); Omega.setMarker( _type="line",_name="Paroi",_marker1=true,_marker3=true ); Omega.setMarker( _type="surface",_name="Fluid",_markerAll=true ); auto mesh = Omega.createMesh(_mesh=new mesh_type,_name="omega_"+ mesh_type::shape_type::name() ); LOG(INFO) << "created mesh\n"; GeoTool::Rectangle OmegaBis( meshSizeBis,"Omega",x1,x2 ); OmegaBis.setMarker( _type="line",_name="Entree",_marker4=true ); OmegaBis.setMarker( _type="line",_name="Sortie",_marker2=true ); OmegaBis.setMarker( _type="line",_name="Paroi",_marker1=true,_marker3=true ); OmegaBis.setMarker( _type="surface",_name="Fluid",_markerAll=true ); auto meshBis = OmegaBis.createMesh(_mesh=new mesh_bis_type,_name="omegaBis_"+ mesh_type::shape_type::name() ); //auto meshBis= mesh->createP1mesh(); LOG(INFO) << "created meshBis\n"; typedef Lagrange<nOrderPoly,Scalar,Continuous,PointSetFekete> basis_type; typedef FunctionSpace<mesh_type, bases<basis_type> > space_type; auto Xh = space_type::New( mesh ); auto u = Xh->element(); auto v = Xh->element(); auto u2 = Xh->element(); LOG(INFO) << "created space and elements\n"; auto mybackend = backend(); //--------------------------------------------------------------// auto A = mybackend->newMatrix( Xh, Xh ); auto F = mybackend->newVector( Xh ); auto pi = cst( M_PI ); auto u_exact = cos( pi*Px() )*sin( pi*Py() ); auto dudx = -pi*sin( pi*Px() )*sin( pi*Py() ); auto dudy = pi*cos( pi*Px() )*cos( pi*Py() ); auto grad_u_uexact = vec( dudx,dudy ); auto lap = -2*pi*pi*cos( pi*Px() )*sin( pi*Py() ); //auto lap = -pi*pi*cos(pi*Px())*sin(pi*Py()) // -pi*pi*cos(pi*Px())*sin(pi*Py()); LOG(INFO) << "created exact data and matrix/vector\n"; auto f = -lap;//cst(1.); double gammabc=10; // assemblage form2( Xh, Xh, A, _init=true ) = integrate( elements( mesh ), //_Q<15>(), + gradt( u )*trans( grad( v ) ) ); form2( Xh, Xh, A ) += integrate( boundaryfaces( mesh ), - gradt( u )*N()*id( v ) + gammabc*idt( u )*id( v )/hFace() ); form1( Xh, F, _init=true ) = integrate( elements( mesh ), // _Q<10>(), trans( f )*id( v ) ); form1( Xh, F ) += integrate( boundaryfaces( mesh ), + gammabc*u_exact*id( v )/hFace() ); LOG(INFO) << "A,F assembled\n"; //form2( Xh, Xh, A ) += // on( boundaryfaces(mesh) , u, F, u_exact ); // solve system mybackend->solve( A,u,F ); LOG(INFO) << "A u = F solved\n"; //--------------------------------------------------------------// auto a2 = form2( _test=Xh, _trial=Xh ); auto f2 = form1( _test=Xh ); LOG(INFO) << "created form2 a2 and form1 F2\n"; // assemblage a2 = integrate( elements( meshBis ), + gradt( u2 )*trans( grad( v ) ), _Q<10>() ); LOG(INFO) << "a2 grad.grad term\n"; a2 += integrate( boundaryfaces( meshBis ), - gradt( u2 )*N()*id( v ) + gammabc*idt( u2 )*id( v )/hFace(), _Q<10>() ); LOG(INFO) << "a2 weak dirichlet terms\n"; f2 = integrate( elements( meshBis ), trans( f )*id( v ), _Q<10>() ); LOG(INFO) << "f2 source term\n"; f2 += integrate( boundaryfaces( meshBis ), + gammabc*u_exact*id( v )/hFace(), _Q<10>() ); LOG(INFO) << "f2 dirichlet terms\n"; LOG(INFO) << "a2,f2 assembled\n"; //form2( Xh, Xh, A2 ) += // on( boundaryfaces(mesh) , u2, F2, u_exact ); #if 0 for ( size_type i = 0 ; i< F->size() ; ++i ) { auto errOnF = std::abs( ( *F )( i )-( *F2 )( i ) ); if ( errOnF > 1e-8 ) std::cout << "\nerrOnF : " << errOnF; } std::cout << "\nFin errOnF !!!!\n"; #endif // solve system a2.solve( _rhs=f2, _solution=u2 ); auto diff = std::sqrt( integrate( elements( mesh ), ( idv( u )-idv( u2 ) )*( idv( u )-idv( u2 ) ) ).evaluate()( 0,0 ) ); #if 0 auto int1 = integrate( elements( mesh ), abs( idv( u ) ) ).evaluate()( 0,0 ); auto int2 = integrate( elements( mesh ), abs( idv( u2 ) ) ).evaluate()( 0,0 ); std::cout << "\nThe diff : " << diff << " int1 :" << int1 << " int2 :" << int2 << "\n"; #endif #if USE_BOOST_TEST BOOST_CHECK_SMALL( diff,1e-2 ); #endif //--------------------------------------------------------------// if ( option("exporter.export").as<bool>() ) { // export auto ex = exporter( _mesh=mesh ); ex->add( "u", u ); ex->add( "ubis", u2 ); ex->save(); } }
PreconditionerBlockMS<space_type>::PreconditionerBlockMS(space_ptrtype Xh, // (u)x(p) ModelProperties model, // model std::string const& p, // prefix sparse_matrix_ptrtype AA ) // The matrix : M_backend(backend()), // the backend associated to the PC M_Xh( Xh ), M_Vh( Xh->template functionSpace<0>() ), // Potential M_Qh( Xh->template functionSpace<1>() ), // Lagrange M_Vh_indices( M_Vh->nLocalDofWithGhost() ), M_Qh_indices( M_Qh->nLocalDofWithGhost() ), M_uin( M_backend->newVector( M_Vh ) ), M_uout( M_backend->newVector( M_Vh ) ), M_pin( M_backend->newVector( M_Qh ) ), M_pout( M_backend->newVector( M_Qh ) ), U( M_Xh, "U" ), M_mass(M_backend->newMatrix(M_Vh,M_Vh)), M_L(M_backend->newMatrix(M_Qh,M_Qh)), M_er( 1. ), M_model( model ), M_prefix( p ), M_prefix_11( p+".11" ), M_prefix_22( p+".22" ), u(M_Vh, "u"), ozz(M_Vh, "ozz"), zoz(M_Vh, "zoz"), zzo(M_Vh, "zzo"), M_ozz(M_backend->newVector( M_Vh )), M_zoz(M_backend->newVector( M_Vh )), M_zzo(M_backend->newVector( M_Vh )), X(M_Qh, "X"), Y(M_Qh, "Y"), Z(M_Qh, "Z"), M_X(M_backend->newVector( M_Qh )), M_Y(M_backend->newVector( M_Qh )), M_Z(M_backend->newVector( M_Qh )), phi(M_Qh, "phi") { tic(); LOG(INFO) << "[PreconditionerBlockMS] setup starts"; this->setMatrix( AA ); this->setName(M_prefix); /* Indices are need to extract sub matrix */ std::iota( M_Vh_indices.begin(), M_Vh_indices.end(), 0 ); std::iota( M_Qh_indices.begin(), M_Qh_indices.end(), M_Vh->nLocalDofWithGhost() ); M_11 = AA->createSubMatrix( M_Vh_indices, M_Vh_indices, true, true); /* Boundary conditions */ BoundaryConditions M_bc = M_model.boundaryConditions(); map_vector_field<FEELPP_DIM,1,2> m_dirichlet_u { M_bc.getVectorFields<FEELPP_DIM> ( "u", "Dirichlet" ) }; map_scalar_field<2> m_dirichlet_p { M_bc.getScalarFields<2> ( "phi", "Dirichlet" ) }; /* Compute the mass matrix (needed in first block, constant) */ auto f2A = form2(_test=M_Vh, _trial=M_Vh, _matrix=M_mass); auto f1A = form1(_test=M_Vh); f2A = integrate(_range=elements(M_Vh->mesh()), _expr=inner(idt(u),id(u))); // M for(auto const & it : m_dirichlet_u ) { LOG(INFO) << "Applying " << it.second << " on " << it.first << " for "<<M_prefix_11<<"\n"; f2A += on(_range=markedfaces(M_Vh->mesh(),it.first), _expr=it.second,_rhs=f1A, _element=u, _type="elimination_symmetric"); } /* Compute the L (= er * grad grad) matrix (the second block) */ auto f2L = form2(_test=M_Qh,_trial=M_Qh, _matrix=M_L); for(auto it : M_model.materials() ) { f2L += integrate(_range=markedelements(M_Qh->mesh(),marker(it)), _expr=M_er*inner(gradt(phi), grad(phi))); } auto f1LQ = form1(_test=M_Qh); for(auto const & it : m_dirichlet_p) { LOG(INFO) << "Applying " << it.second << " on " << it.first << " for "<<M_prefix_22<<"\n"; f2L += on(_range=markedfaces(M_Qh->mesh(),it.first),_element=phi, _expr=it.second, _rhs=f1LQ, _type="elimination_symmetric"); } if(soption(_name="pc-type", _prefix=M_prefix_11) == "ams") #if FEELPP_DIM == 3 { M_grad = Grad( _domainSpace=M_Qh, _imageSpace=M_Vh); // This preconditioner is linked to that backend : the backend will // automatically use the preconditioner. auto prec = preconditioner(_pc=pcTypeConvertStrToEnum(soption(M_prefix_11+".pc-type")), _backend=backend(_name=M_prefix_11), _prefix=M_prefix_11, _matrix=M_11 ); prec->setMatrix(M_11); prec->attachAuxiliarySparseMatrix("G",M_grad.matPtr()); if(boption(M_prefix_11+".useEdge")) { LOG(INFO) << "[ AMS ] : using SetConstantEdgeVector \n"; ozz.on(_range=elements(M_Vh->mesh()),_expr=vec(cst(1),cst(0),cst(0))); zoz.on(_range=elements(M_Vh->mesh()),_expr=vec(cst(0),cst(1),cst(0))); zzo.on(_range=elements(M_Vh->mesh()),_expr=vec(cst(0),cst(0),cst(1))); *M_ozz = ozz; M_ozz->close(); *M_zoz = zoz; M_zoz->close(); *M_zzo = zzo; M_zzo->close(); prec->attachAuxiliaryVector("Px",M_ozz); prec->attachAuxiliaryVector("Py",M_zoz); prec->attachAuxiliaryVector("Pz",M_zzo); } else { LOG(INFO) << "[ AMS ] : using SetCoordinates \n"; X.on(_range=elements(M_Vh->mesh()),_expr=Px()); Y.on(_range=elements(M_Vh->mesh()),_expr=Py()); Z.on(_range=elements(M_Vh->mesh()),_expr=Pz()); *M_X = X; M_X->close(); *M_Y = Y; M_Y->close(); *M_Z = Z; M_Z->close(); prec->attachAuxiliaryVector("X",M_X); prec->attachAuxiliaryVector("Y",M_Y); prec->attachAuxiliaryVector("Z",M_Z); } } #else std::cerr << "ams preconditioner is not interfaced in two dimensions\n"; #endif toc( "[PreconditionerBlockMS] setup done ", FLAGS_v > 0 ); }