/** * @brief Has a pilot attempt to board another pilot. * * @param p Pilot doing the boarding. * @return 1 if target was boarded. */ int pilot_board( Pilot *p ) { Pilot *target; /* Make sure target is sane. */ target = pilot_get(p->target); if (target == NULL) { DEBUG("NO TARGET"); return 0; } /* Check if can board. */ if (!pilot_isDisabled(target)) return 0; else if (vect_dist(&p->solid->pos, &target->solid->pos) > target->ship->gfx_space->sw * PILOT_SIZE_APROX ) return 0; else if ((pow2(VX(p->solid->vel)-VX(target->solid->vel)) + pow2(VY(p->solid->vel)-VY(target->solid->vel))) > (double)pow2(MAX_HYPERSPACE_VEL)) return 0; else if (pilot_isFlag(target,PILOT_BOARDED)) return 0; /* Set the boarding flag. */ pilot_setFlag(target, PILOT_BOARDED); pilot_setFlag(p, PILOT_BOARDING); /* Set time it takes to board. */ p->ptimer = 3.; return 1; }
//--------------------------------------------------------- bool NDG3D::StartUp3D() //--------------------------------------------------------- { // Purpose : Setup script, building operators, grid, metric, // and connectivity tables for 3D meshes of tetrahedra. // Definition of constants Np = (N+1)*(N+2)*(N+3)/6; Nfp = (N+1)*(N+2)/2; Nfaces=4; NODETOL = 1e-7; // Compute nodal set DVec x1,y1,z1; Nodes3D(N, x1,y1,z1); xyztorst(x1,y1,z1, r,s,t); // Build reference element matrices V = Vandermonde3D(N,r,s,t); invV = inv(V); MassMatrix = trans(invV)*invV; ::Dmatrices3D(N, r, s, t, V, Dr, Ds, Dt); // build coordinates of all the nodes IVec va = EToV(All,1), vb = EToV(All,2), vc = EToV(All,3), vd = EToV(All,4); x = 0.5*(-(1.0+r+s+t)*VX(va) + (1.0+r)*VX(vb) + (1.0+s)*VX(vc) + (1.0+t)*VX(vd)); y = 0.5*(-(1.0+r+s+t)*VY(va) + (1.0+r)*VY(vb) + (1.0+s)*VY(vc) + (1.0+t)*VY(vd)); z = 0.5*(-(1.0+r+s+t)*VZ(va) + (1.0+r)*VZ(vb) + (1.0+s)*VZ(vc) + (1.0+t)*VZ(vd)); // find all the nodes that lie on each edge IVec fmask1,fmask2,fmask3,fmask4; fmask1 = find( abs(1.0+t), '<', NODETOL); fmask2 = find( abs(1.0+s), '<', NODETOL); fmask3 = find( abs(1.0+r+s+t), '<', NODETOL); fmask4 = find( abs(1.0+r), '<', NODETOL); Fmask.resize(Nfp,4); // set shape (M,N) before concat() Fmask = concat(fmask1,fmask2,fmask3,fmask4); // load vector into shaped matrix Fx=x(Fmask,All); Fy=y(Fmask,All); Fz=z(Fmask,All); // Create surface integral terms Lift3D(); // calculate geometric factors and normals Normals3D(); Fscale = sJ.dd(J(Fmask,All)); // Build connectivity matrix tiConnect3D(EToV, EToE, EToF); // Build connectivity maps BuildMaps3D(); // Compute weak operators (could be done in preprocessing to save time) DMat Vr,Vs,Vt; GradVandermonde3D(N, r, s, t, Vr, Vs, Vt); VVT = V*trans(V); Drw = (V*trans(Vr))/VVT; Dsw = (V*trans(Vs))/VVT; Dtw = (V*trans(Vt))/VVT; return true; }
/** * @brief Computes an estimation of ammo flying time * * @param w the weapon that shoot * @param parent Parent of the weapon * @param target Target of the weapon */ double pilot_weapFlyTime( Outfit *o, Pilot *parent, Vector2d *pos, Vector2d *vel) { Vector2d approach_vector, relative_location, orthoradial_vector; double speed, radial_speed, orthoradial_speed, dist, t; dist = vect_dist( &parent->solid->pos, pos ); /* Beam weapons */ if (outfit_isBeam(o)) { if (dist > o->u.bem.range) return INFINITY; return 0.; } /* A bay doesn't have range issues */ if (outfit_isFighterBay(o)) return 0.; /* Rockets use absolute velocity while bolt use relative vel */ if (outfit_isLauncher(o)) vect_cset( &approach_vector, - vel->x, - vel->y ); else vect_cset( &approach_vector, VX(parent->solid->vel) - vel->x, VY(parent->solid->vel) - vel->y ); speed = outfit_speed(o); /* Get the vector : shooter -> target */ vect_cset( &relative_location, pos->x - VX(parent->solid->pos), pos->y - VY(parent->solid->pos) ); /* Get the orthogonal vector */ vect_cset(&orthoradial_vector, VY(parent->solid->pos) - pos->y, pos->x - VX(parent->solid->pos) ); radial_speed = vect_dot( &approach_vector, &relative_location ); radial_speed = radial_speed / VMOD(relative_location); orthoradial_speed = vect_dot(&approach_vector, &orthoradial_vector); orthoradial_speed = orthoradial_speed / VMOD(relative_location); if( ((speed*speed - VMOD(approach_vector)*VMOD(approach_vector)) != 0) && (speed*speed - orthoradial_speed*orthoradial_speed) > 0) t = dist * (sqrt( speed*speed - orthoradial_speed*orthoradial_speed ) - radial_speed) / (speed*speed - VMOD(approach_vector)*VMOD(approach_vector)); else return INFINITY; /* if t < 0, try the other solution */ if (t < 0) t = - dist * (sqrt( speed*speed - orthoradial_speed*orthoradial_speed ) + radial_speed) / (speed*speed - VMOD(approach_vector)*VMOD(approach_vector)); /* if t still < 0, no solution */ if (t < 0) return INFINITY; return t; }
void operator() (double *X, double *Y) { Map<VectorXd> VX(X, this->W->rows()); Map<VectorXd> VY(Y, this->W->rows()); VectorXd XmWX = VX - (*this->W) * VX; VY = XmWX - this->W->transpose() * XmWX; }
void AddThing(short x, short y, short type) { if (type != 1) return; //!!!! type = ENT_PLAYERSTART; short z = the_world->Loc(x, y).floor_h*4 + 1; lev_ents.push_back(new entity_c(VX(x,2), VY(y,2), z, type)); }
/** * @brief Weapon hit the pilot. * * @param w Weapon involved in the collision. * @param p Pilot that got hit. * @param layer Layer to which the weapon belongs. * @param pos Position of the hit. * @param dt Current delta tick. */ static void weapon_hitBeam( Weapon* w, Pilot* p, WeaponLayer layer, Vector2d pos[2], const double dt ) { (void) layer; Pilot *parent; int spfx; double damage; DamageType dtype; WeaponLayer spfx_layer; /* Get general details. */ parent = pilot_get(w->parent); damage = outfit_damage(w->outfit) * dt; dtype = outfit_damageType(w->outfit); /* Have pilot take damage and get real damage done. */ damage = pilot_hit( p, w->solid, w->parent, dtype, damage ); /* Add sprite, layer depends on whether player shot or not. */ if (w->lockon == -1.) { /* Get the layer. */ spfx_layer = (p==player) ? SPFX_LAYER_FRONT : SPFX_LAYER_BACK; /* Choose spfx. */ if (p->shield > 0.) spfx = outfit_spfxShield(w->outfit); else spfx = outfit_spfxArmour(w->outfit); /* Add graphic. */ spfx_add( spfx, pos[0].x, pos[0].y, VX(p->solid->vel), VY(p->solid->vel), spfx_layer ); spfx_add( spfx, pos[1].x, pos[1].y, VX(p->solid->vel), VY(p->solid->vel), spfx_layer ); w->lockon = -2; } /* Inform AI that it's been hit. */ weapon_hitAI( p, parent, damage ); }
/** * @brief Renders the entire spfx layer. * * @param layer Layer to render. */ void spfx_render( const int layer ) { SPFX *spfx_stack; int i, spfx_nstack; SPFX_Base *effect; int sx, sy; double time; /* get the appropriate layer */ switch (layer) { case SPFX_LAYER_FRONT: spfx_stack = spfx_stack_front; spfx_nstack = spfx_nstack_front; break; case SPFX_LAYER_BACK: spfx_stack = spfx_stack_back; spfx_nstack = spfx_nstack_back; break; default: WARN("Rendering invalid SPFX layer."); return; } /* Now render the layer */ for (i=spfx_nstack-1; i>=0; i--) { effect = &spfx_effects[ spfx_stack[i].effect ]; /* Simplifies */ sx = (int)effect->gfx->sx; sy = (int)effect->gfx->sy; if (!paused) { /* don't calculate frame if paused */ time = fmod(spfx_stack[i].timer,effect->anim) / effect->anim; spfx_stack[i].lastframe = sx * sy * MIN(time, 1.); } /* Renders */ gl_blitSprite( effect->gfx, VX(spfx_stack[i].pos), VY(spfx_stack[i].pos), spfx_stack[i].lastframe % sx, spfx_stack[i].lastframe / sx, NULL ); } }
FOR_LOC(x, y, loc) { if (loc.Void()) continue; if (RandomPerc(90)) continue; short z = the_world->Loc(x, y).ceil_h*4 - 2; lev_ents.push_back(new entity_c(VX(x,2), VY(y,2), z, ENT_LIGHT)); entity_c *E = lev_ents[lev_ents.size()-1]; E->attrs[0] = RandomRange(4,16); E->attrs[1] = RandomRange(25,255); }}
ObjExplosion::ObjExplosion(const Point3d& pos, const Point3d& vel): Drawable3D(std::string("explosion"), pos, vel), sparkles() { for(int i =0;i != 100;i ++){ double vx = VX() +rand()%1000/(double)1-50; double vy = VY()+ rand()%1000/(double)1-50; double vz = VZ()+ rand()%1000/(double)1-50; std::cout << pos.z << std::endl; sparkles.push_back( Sparkle(pos, Point3d(vx,vy,vz)) ); } }
/** * @brief Updates an individual spfx. * * @param layer Layer the spfx is on. * @param nlayer Pointer to the assosciated nlayer. * @param dt Current delta tick. */ static void spfx_update_layer( SPFX *layer, int *nlayer, const double dt ) { int i; for (i=0; i<*nlayer; i++) { layer[i].timer -= dt; /* less time to live */ /* time to die! */ if (layer[i].timer < 0.) { spfx_destroy( layer, nlayer, i ); i--; continue; } /* actually update it */ vect_cadd( &layer[i].pos, dt*VX(layer[i].vel), dt*VY(layer[i].vel) ); } }
/** * @brief Weapon hit the pilot. * * @param w Weapon involved in the collision. * @param p Pilot that got hit. * @param layer Layer to which the weapon belongs. * @param pos Position of the hit. */ static void weapon_hit( Weapon* w, Pilot* p, WeaponLayer layer, Vector2d* pos ) { Pilot *parent; int spfx; double damage; DamageType dtype; WeaponLayer spfx_layer; int s; /* Get general details. */ parent = pilot_get(w->parent); damage = w->strength * outfit_damage(w->outfit); dtype = outfit_damageType(w->outfit); /* Play sound if they have it. */ s = outfit_soundHit(w->outfit); if (s != -1) w->voice = sound_playPos( s, w->solid->pos.x, w->solid->pos.y, w->solid->vel.x, w->solid->vel.y); /* Have pilot take damage and get real damage done. */ damage = pilot_hit( p, w->solid, w->parent, dtype, damage ); /* Get the layer. */ spfx_layer = (p==player) ? SPFX_LAYER_FRONT : SPFX_LAYER_BACK; /* Choose spfx. */ if (p->shield > 0.) spfx = outfit_spfxShield(w->outfit); else spfx = outfit_spfxArmour(w->outfit); /* Add sprite, layer depends on whether player shot or not. */ spfx_add( spfx, pos->x, pos->y, VX(p->solid->vel), VY(p->solid->vel), spfx_layer ); /* Inform AI that it's been hit. */ weapon_hitAI( p, parent, damage ); /* no need for the weapon particle anymore */ weapon_destroy(w,layer); }
void Obj3DDrawable::update(Uint32 ticks){ //todo // setPosition(getPosition((double)ticks/10*getVelocity() )); setPosition( Point3d(X()+VX()/1000*ticks, Y()+VY()/1000*ticks, Z()+VZ()/1000*ticks ) ); /// std::cout << Z() << std::endl; // std::cout << VZ()<< std::endl; // ticks = ticks;//delete this line projectedLines.clear(); for(std::vector<Line3d>::iterator i = lines.begin();i != lines.end();i ++){ projectedLines. push_back(Viewpoint::getInstance().lookAtLine3D(*i)); } }
//--------------------------------------------------------- void NDG2D::MakeCylinder2D ( const IMat& faces, double ra, double xo, double yo ) //--------------------------------------------------------- { // Function: MakeCylinder2D(faces, ra, xo, yo) // Purpose: Use Gordon-Hall blending with an isoparametric // map to modify a list of faces so they conform // to a cylinder of radius r centered at (xo,yo) int NCurveFaces = faces.num_rows(); IVec vflag(VX.size()); IMat VFlag(EToV.num_rows(),EToV.num_cols()); int n=0,k=0,f=0,v1=0,v2=0; double theta1=0.0,theta2=0.0,x1=0.0,x2=0.0,y1=0.0,y2=0.0; double newx1=0.0,newx2=0.0,newy1=0.0,newy2=0.0; DVec vr, fr, theta, fdx,fdy, vdx, vdy, blend,numer,denom; IVec va,vb,vc, ks, Fm_f, ids; DMat Vface, Vvol; for (n=1; n<=NCurveFaces; ++n) { // move vertices of faces to be curved onto circle k = faces(n,1); f = faces(n,2); v1 = EToV(k, f); v2 = EToV(k, umMOD(f,Nfaces)+1); theta1 = atan2(VY(v1),VX(v1)); theta2 = atan2(VY(v2),VX(v2)); newx1 = xo + ra*cos(theta1); newy1 = yo + ra*sin(theta1); newx2 = xo + ra*cos(theta2); newy2 = yo + ra*sin(theta2); // update mesh vertex locations VX(v1) = newx1; VX(v2) = newx2; VY(v1) = newy1; VY(v2) = newy2; // store modified vertex numbers vflag(v1) = 1; vflag(v2) = 1; } // map modified vertex flag to each element //vflag = vflag(EToV); VFlag.resize(EToV); VFlag.set_map(EToV, vflag); // (map, values) // locate elements with at least one modified vertex //ks = find(sum(vflag,2)>0); ks = find(VFlag.row_sums(), '>', 0); // build coordinates of all the corrected nodes IMat VA=EToV(ks,1), VB=EToV(ks,2), VC=EToV(ks,3); // FIXME: loading 2D mapped data into 1D vectors int Nr=VA.num_rows(); va.copy(Nr,VA.data()); vb.copy(Nr,VB.data()); vc.copy(Nr,VC.data()); // Note: outer products of (Vector,MappedRegion1D) x(All,ks) = 0.5*(-(r+s)*VX(va)+(1.0+r)*VX(vb)+(1.0+s)*VX(vc)); y(All,ks) = 0.5*(-(r+s)*VY(va)+(1.0+r)*VY(vb)+(1.0+s)*VY(vc)); // deform specified faces for (n=1; n<=NCurveFaces; ++n) { k = faces(n,1); f = faces(n,2); // find vertex locations for this face and tangential coordinate if (f==1) { v1=EToV(k,1); v2=EToV(k,2); vr=r; } else if (f==2) { v1=EToV(k,2); v2=EToV(k,3); vr=s; } else if (f==3) { v1=EToV(k,1); v2=EToV(k,3); vr=s; } fr = vr(Fmask(All,f)); x1 = VX(v1); y1 = VY(v1); x2 = VX(v2); y2 = VY(v2); // move vertices at end points of this face to the cylinder theta1 = atan2(y1-yo, x1-xo); theta2 = atan2(y2-yo, x2-xo); // check to make sure they are in the same quadrant if ((theta2 > 0.0) && (theta1 < 0.0)) { theta1 += 2*pi; } if ((theta1 > 0.0) && (theta2 < 0.0)) { theta2 += 2*pi; } // distribute N+1 nodes by arc-length along edge theta = 0.5*theta1*(1.0-fr) + 0.5*theta2*(1.0+fr); // evaluate deformation of coordinates fdx = xo + ra*apply(cos,theta) - x(Fmask(All,f),k); fdy = yo + ra*apply(sin,theta) - y(Fmask(All,f),k); // build 1D Vandermonde matrix for face nodes and volume nodes Vface = Vandermonde1D(N, fr); Vvol = Vandermonde1D(N, vr); // compute unblended volume deformations vdx = Vvol * (Vface|fdx); vdy = Vvol * (Vface|fdy); // blend deformation and increment node coordinates ids = find(abs(1.0-vr), '>', 1e-7); // warp and blend denom = 1.0-vr(ids); if (1==f) { numer = -(r(ids)+s(ids)); } else if (2==f) { numer = (r(ids)+1.0 ); } else if (3==f) { numer = -(r(ids)+s(ids)); } blend = numer.dd(denom); x(ids,k) += (blend.dm(vdx(ids))); y(ids,k) += (blend.dm(vdy(ids))); } // repair other coordinate dependent information Fx = x(Fmask, All); Fy = y(Fmask, All); ::GeometricFactors2D(x,y,Dr,Ds, rx,sx,ry,sy,J); Normals2D(); Fscale = sJ.dd(J(Fmask,All)); }
//--------------------------------------------------------- DMat& NDG2D::ConformingHrefine2D(IMat& edgerefineflag, const DMat& Qin) //--------------------------------------------------------- { #if (0) OutputNodes(false); // volume nodes //OutputNodes(true); // face nodes #endif // function newQ = ConformingHrefine2D(edgerefineflag, Q) // Purpose: apply edge splits as requested by edgerefineflag IVec v1("v1"), v2("v2"), v3("v3"), tvi; DVec x1("x1"), x2("x2"), x3("x3"), y1("y1"), y2("y2"), y3("y3"); DVec a1("a1"), a2("a2"), a3("a3"); // count vertices assert (VX.size() == Nv); // find vertex triplets for elements to be refined v1 = EToV(All,1); v2 = EToV(All,2); v3 = EToV(All,3); x1 = VX(v1); x2 = VX(v2); x3 = VX(v3); y1 = VY(v1); y2 = VY(v2); y3 = VY(v3); // find angles at each element vertex (in radians) VertexAngles(x1,x2,x3,y1,y2,y3, a1,a2,a3); // absolute value of angle size a1.set_abs(); a2.set_abs(); a3.set_abs(); int k=0,k1=0,f1=0,k2=0,f2=0, e1=0,e2=0,e3=0, b1=0,b2=0,b3=0, ref=0; IVec m1,m2,m3; DVec mx1, my1, mx2, my2, mx3, my3; // create new vertices at edge centers of marked elements // (use unique numbering derived from unique edge number)) m1 = max(IVec(Nv*(v1-1)+v2+1), IVec(Nv*(v2-1)+v1+1)); mx1=0.5*(x1+x2); my1=0.5*(y1+y2); m2 = max(IVec(Nv*(v2-1)+v3+1), IVec(Nv*(v3-1)+v2+1)); mx2=0.5*(x2+x3); my2=0.5*(y2+y3); m3 = max(IVec(Nv*(v1-1)+v3+1), IVec(Nv*(v3-1)+v1+1)); mx3=0.5*(x3+x1); my3=0.5*(y3+y1); // ensure that both elements sharing an edge are split for (k1=1; k1<=K; ++k1) { for (f1=1; f1<=Nfaces; ++f1) { if (edgerefineflag(k1,f1)) { k2 = EToE(k1,f1); f2 = EToF(k1,f1); edgerefineflag(k2,f2) = 1; } } } // store old data IMat oldEToV = EToV; DVec oldVX = VX, oldVY = VY; // count the number of elements in the refined mesh int newK = countrefinefaces(edgerefineflag); EToV.resize(newK, Nfaces, true, 0); IMat newBCType(newK,3, "newBCType"); // kold = []; IVec kold(newK, "kold"); Index1D KI,KIo; int sk=1, skstart=0, skend=0; for (k=1; k<=K; ++k) { skstart = sk; e1 = edgerefineflag(k,1); b1 = BCType(k,1); e2 = edgerefineflag(k,2); b2 = BCType(k,2); e3 = edgerefineflag(k,3); b3 = BCType(k,3); ref = e1 + 2*e2 + 4*e3; switch (ref) { case 0: EToV(sk, All) = IVec(v1(k),v2(k),v3(k)); newBCType(sk,All) = IVec(b1, b2, b3); ++sk; break; case 1: EToV(sk, All) = IVec(v1(k),m1(k),v3(k)); newBCType(sk,All) = IVec(b1, 0, b3); ++sk; EToV(sk, All) = IVec(m1(k),v2(k),v3(k)); newBCType(sk,All) = IVec(b1, b2, 0); ++sk; break; case 2: EToV(sk, All) = IVec(v2(k),m2(k),v1(k)); newBCType(sk,All) = IVec(b2, 0, b1); ++sk; EToV(sk, All) = IVec(m2(k),v3(k),v1(k)); newBCType(sk,All) = IVec(b2, b3, 0); ++sk; break; case 4: EToV(sk, All) = IVec(v3(k),m3(k),v2(k)); newBCType(sk,All) = IVec(b3, 0, b2); ++sk; EToV(sk, All) = IVec(m3(k),v1(k),v2(k)); newBCType(sk,All) = IVec(b3, b1, 0); ++sk; break; case 3: EToV(sk, All) = IVec(m1(k),v2(k),m2(k)); newBCType(sk,All) = IVec(b1, b2, 0); ++sk; if (a1(k) > a3(k)) { // split largest angle EToV(sk, All) = IVec(v1(k),m1(k),m2(k)); newBCType(sk,All) = IVec(b1, 0, 0); ++sk; EToV(sk, All) = IVec(v1(k),m2(k),v3(k)); newBCType(sk,All) = IVec( 0, b2, b3); ++sk; } else { EToV(sk, All) = IVec(v3(k),m1(k),m2(k)); newBCType(sk,All) = IVec( 0, 0, b2); ++sk; EToV(sk, All) = IVec(v3(k),v1(k),m1(k)); newBCType(sk,All) = IVec(b3, b1, 0); ++sk; } break; case 5: EToV(sk, All) = IVec(v1(k),m1(k),m3(k)); newBCType(sk,All) = IVec(b1, 0, b3); ++sk; if (a2(k) > a3(k)) { // split largest angle EToV(sk, All) = IVec(v2(k),m3(k),m1(k)); newBCType(sk,All) = IVec( 0, 0, b1); ++sk; EToV(sk, All) = IVec(v2(k),v3(k),m3(k)); newBCType(sk,All) = IVec(b2, b3, 0); ++sk; } else { EToV(sk, All) = IVec(v3(k),m3(k),m1(k)); newBCType(sk,All) = IVec(b3, 0, 0); ++sk; EToV(sk, All) = IVec(v3(k),m1(k),v2(k)); newBCType(sk,All) = IVec( 0, b1, b2); ++sk; } break; case 6: EToV(sk, All) = IVec(v3(k),m3(k),m2(k)); newBCType(sk,All) = IVec(b3, 0, b2); ++sk; if (a1(k) > a2(k)) { // split largest angle EToV(sk, All) = IVec(v1(k),m2(k),m3(k)); newBCType(sk,All) = IVec( 0, 0, b3); ++sk; EToV(sk, All) = IVec(v1(k),v2(k),m2(k)); newBCType(sk,All) = IVec(b1, b2, 0); ++sk; } else { EToV(sk, All) = IVec(v2(k),m2(k),m3(k)); newBCType(sk,All) = IVec(b2, 0, 0); ++sk; EToV(sk, All) = IVec(v2(k),m3(k),v1(k)); newBCType(sk,All) = IVec( 0 , b3, b1); ++sk; } break; default: // split all EToV(sk, All) = IVec(m1(k),m2(k),m3(k)); newBCType(sk, All) = IVec( 0, 0, 0); ++sk; EToV(sk, All) = IVec(v1(k),m1(k),m3(k)); newBCType(sk, All) = IVec(b1, 0, b3); ++sk; EToV(sk, All) = IVec(v2(k),m2(k),m1(k)); newBCType(sk, All) = IVec(b2, 0, b1); ++sk; EToV(sk, All) = IVec(v3(k),m3(k),m2(k)); newBCType(sk, All) = IVec(b3, 0, b2); ++sk; break; } skend = sk; // kold = [kold; k*ones(skend-skstart, 1)]; // element k is to be refined into (1:4) child elements. // store parent element numbers in array "kold" to help // with accessing parent vertex data during refinement. KI.reset(skstart, skend-1); // ids of child elements kold(KI) = k; // mark as children of element k } // Finished with edgerefineflag. Delete if OBJ_temp if (edgerefineflag.get_mode() == OBJ_temp) { delete (&edgerefineflag); } // renumber new nodes contiguously // ids = unique([v1;v2;v3;m1;m2;m3]); bool unique=true; IVec IDS, ids; IDS = concat( concat(v1,v2,v3), concat(m1,m2,m3) ); ids = sort(IDS, unique); Nv = ids.size(); int max_id = EToV.max_val(); umMSG(1, "max id in EToV is %d\n", max_id); // M N nnz vals triplet CSi newids(max_id,1, Nv, 1, 1 ); // newids = sparse(max(max(EToV)),1); int i=0, j=1; for (i=1; i<=Nv; ++i) { // newids(ids)= (1:Nv); newids.set1(ids(i),j, i); // load 1-based triplets } // row col x newids.compress(); // convert to csc form // Matlab ----------------------------------------------- // v1 = newids(v1); v2 = newids(v2); v3 = newids(v3); // m1 = newids(m1); m2 = newids(m2); m3 = newids(m3); //------------------------------------------------------- int KVi=v1.size(), KMi=m1.size(); // read from copies, overwrite originals // 1. reload ids for new vertices tvi = v1; for (i=1;i<=KVi;++i) {v1(i) = newids(tvi(i), 1);} tvi = v2; for (i=1;i<=KVi;++i) {v2(i) = newids(tvi(i), 1);} tvi = v3; for (i=1;i<=KVi;++i) {v3(i) = newids(tvi(i), 1);} // 2. load ids for new (midpoint) vertices tvi = m1; for (i=1;i<=KMi;++i) {m1(i) = newids(tvi(i), 1);} tvi = m2; for (i=1;i<=KMi;++i) {m2(i) = newids(tvi(i), 1);} tvi = m3; for (i=1;i<=KMi;++i) {m3(i) = newids(tvi(i), 1);} VX.resize(Nv); VY.resize(Nv); VX(v1) = x1; VX(v2) = x2; VX(v3) = x3; VY(v1) = y1; VY(v2) = y2; VY(v3) = y3; VX(m1) = mx1; VX(m2) = mx2; VX(m3) = mx3; VY(m1) = my1; VY(m2) = my2; VY(m3) = my3; if (newK != (sk-1)) { umERROR("NDG2D::ConformingHrefine2D", "Inconsistent element count: expect %d, but sk = %d", newK, (sk-1)); } else { K = newK; // sk-1; } // dumpIMat(EToV, "EToV (before)"); // EToV = newids(EToV); for (j=1; j<=3; ++j) { for (k=1; k<=K; ++k) { EToV(k,j) = newids(EToV(k,j), 1); } } #if (0) dumpIMat(EToV, "EToV (after)"); // umERROR("Checking ids", "Nigel, check EToV"); #endif BCType = newBCType; Nv = VX.size(); // xold = x; yold = y; StartUp2D(); #if (1) OutputNodes(false); // volume nodes //OutputNodes(true); // face nodes //umERROR("Exiting early", "Check adapted {volume,face} nodes"); #endif // allocate return object int Nfields = Qin.num_cols(); DMat* tmpQ = new DMat(Np*K, Nfields, "newQ", OBJ_temp); DMat& newQ = *tmpQ; // use a reference for syntax // quick return, if no interpolation is required if (Qin.size()<1) { return newQ; } DVec rOUT(Np),sOUT(Np),xout,yout,xy1(2),xy2(2),xy3(2),tmp(2),rhs; int ko=0,kv1=0,kv2=0,kv3=0,n=0; DMat A(2,2), interp; DMat oldQ = const_cast<DMat&>(Qin); for (k=1; k<=K; ++k) { ko = kold(k); xout = x(All,k); yout = y(All,k); kv1=oldEToV(ko,1); kv2=oldEToV(ko,2); kv3=oldEToV(ko,3); xy1.set(oldVX(kv1), oldVY(kv1)); xy2.set(oldVX(kv2), oldVY(kv2)); xy3.set(oldVX(kv3), oldVY(kv3)); A.set_col(1, xy2-xy1); A.set_col(2, xy3-xy1); for (i=1; i<=Np; ++i) { tmp.set(xout(i), yout(i)); rhs = 2.0*tmp - xy2 - xy3; tmp = A|rhs; rOUT(i) = tmp(1); sOUT(i) = tmp(2); } KI.reset (Np*(k -1)+1, Np*k ); // nodes in new element k KIo.reset(Np*(ko-1)+1, Np*ko); // nodes in old element ko interp = Vandermonde2D(N, rOUT, sOUT)*invV; for (n=1; n<=Nfields; ++n) { //newQ(:,k,n)= interp* Q(:,ko,n); //DVec tm1 = interp*oldQ(KIo,n); //dumpDVec(tm1, "tm1"); newQ(KI,n) = interp*oldQ(KIo,n); } } return newQ; }
/** * @brief Docks the pilot on its target pilot. * * @param p Pilot that wants to dock. * @param target Pilot to dock on. * @param deployed Was pilot already deployed? * @return 0 on successful docking. */ int pilot_dock( Pilot *p, Pilot *target, int deployed ) { int i; Outfit *o = NULL; /* Must be close. */ if (vect_dist(&p->solid->pos, &target->solid->pos) > target->ship->gfx_space->sw * PILOT_SIZE_APROX ) return -1; /* Cannot be going much faster. */ if ((pow2(VX(p->solid->vel)-VX(target->solid->vel)) + pow2(VY(p->solid->vel)-VY(target->solid->vel))) > (double)pow2(MAX_HYPERSPACE_VEL)) return -1; /* Check to see if target has an available bay. */ for (i=0; i<target->noutfits; i++) { /* Must have outfit. */ if (target->outfits[i]->outfit == NULL) continue; /* Must be fighter bay. */ if (!outfit_isFighterBay(target->outfits[i]->outfit)) continue; /* Must have deployed. */ if (deployed && (target->outfits[i]->u.ammo.deployed <= 0)) continue; o = outfit_ammo(target->outfits[i]->outfit); /* Try to add fighter. */ if (outfit_isFighter(o) && (strcmp(p->ship->name,o->u.fig.ship)==0)) { if (deployed) target->outfits[i]->u.ammo.deployed -= 1; break; } } if ((o==NULL) || (i >= target->noutfits)) return -1; /* Add the pilot's outfit. */ if (pilot_addAmmo(target, target->outfits[i], o, 1) != 1) return -1; /* Remove from pilot's escort list. */ if (deployed) { for (i=0; i<target->nescorts; i++) { if ((target->escorts[i].type == ESCORT_TYPE_BAY) && (target->escorts[i].id == p->id)) break; } /* Not found as pilot's escorts. */ if (i >= target->nescorts) return -1; /* Free if last pilot. */ if (target->nescorts == 1) { free(target->escorts); target->escorts = NULL; target->nescorts = 0; } else { memmove( &target->escorts[i], &target->escorts[i+1], sizeof(Escort_t) * (target->nescorts-i-1) ); target->nescorts--; } } /* Destroy the pilot. */ pilot_delete(p); return 0; }
void Block3DDrawable::update(Uint32 ticks){ // turningRight = true; // accelerating = true; // double currentSpeed= sqrt(VX()*VX()+VY()*VY() + VZ()*VZ()); // std::cout << currentSpeed << std::endl; //accelerating /* if(accelerating && currentSpeed < topSpeed){ VX(VX()+VX()*acceleration*(VX()/currentSpeed)*ticks/1000); VY(VY()+VY()*acceleration*(VY()/currentSpeed)*ticks/1000); VZ(VZ()+VZ()*acceleration*(VZ()/currentSpeed)*ticks/1000); } */ //not accelerating /* if(!accelerating && currentSpeed >0){ if(VX()> VX()*acceleration*(VX()/currentSpeed)*ticks/1000){ VX(VX()-VX()*acceleration*(VX()/currentSpeed)*ticks/1000); }else{ VX(0); } if(VY()> VY()*acceleration*(VY()/currentSpeed)*ticks/1000){ VY(VY()-VY()*acceleration*(VY()/currentSpeed)*ticks/1000); }else{ VY(0); } if(VZ()> VZ()*acceleration*(VZ()/currentSpeed)*ticks/1000){ VZ(VZ()-VZ()*acceleration*(VZ()/currentSpeed)*ticks/1000); }else{ VZ(0); } }*/ /* //turning right if(turningRight){ // std::cout << "turning" << std::endl; VZ(VZ()- VX()*0.1); VX(VX()+ VZ()*0.1); } if(turningLeft){ // std::cout << "turning" << std::endl; VZ(VZ()+ VX()*0.1); VX(VX()- VZ()*0.1); } //turning left */ updateLinesPosition(); Obj3DDrawable::update(ticks); // turningRight = false; // turningLeft = false; accelerating = false; VX(0); VY(0); VZ(0); }
int execute_opcode(s_emu *emu, uint16_t op) { //printf("Current opcode: %X\n", op); switch (op & 0xF000) { case 0x0000: { switch (op & 0x00FF) { case 0x00E0: return _00E0(emu, op); case 0x00EE: return _00EE(emu, op); case 0x00FB: return _00FB(emu, op); case 0x00FC: return _00FC(emu, op); case 0x00FD: return _00FD(emu, op); case 0x00FE: return _00FE(emu, op); case 0x00FF: return _00FF(emu, op); default: if (VY(op) == 0x00C0) return _00CN(emu, op); else break; } } case 0x1000: return _1NNN(emu, op); case 0x2000: return _2NNN(emu, op); case 0x3000: return _3XKK(emu, op); case 0x4000: return _4XKK(emu, op); case 0x5000: return _5XY0(emu, op); case 0x6000: return _6XKK(emu, op); case 0x7000: return _7XKK(emu, op); case 0x8000: { switch (op & 0xF00F) { case 0x8000: return _8XY0(emu, op); case 0x8001: return _8XY1(emu, op); case 0x8002: return _8XY2(emu, op); case 0x8003: return _8XY3(emu, op); case 0x8004: return _8XY4(emu, op); case 0x8005: return _8XY5(emu, op); case 0x8006: return _8XY6(emu, op); case 0x8007: return _8XY7(emu, op); case 0x800E: return _8XYE(emu, op); } } case 0x9000: return _9XY0(emu, op); case 0xA000: return _ANNN(emu, op); case 0xB000: return _BNNN(emu, op); case 0xC000: return _CXKK(emu, op); case 0xD000: return _DXYN(emu, op); case 0xE000: { switch (op & 0xF0FF) { case 0xE09E: return _EX9E(emu, op); case 0xE0A1: return _EXA1(emu, op); } } case 0xF000: switch (op & 0xF0FF) { case 0xF007: return _FX07(emu, op); case 0xF00A: return _FX0A(emu, op); case 0xF015: return _FX15(emu, op); case 0xF018: return _FX18(emu, op); case 0xF01E: return _FX1E(emu, op); case 0xF029: return _FX29(emu, op); case 0xF033: return _FX33(emu, op); case 0xF055: return _FX55(emu, op); case 0xF065: return _FX65(emu, op); case 0xF030: return _FX30(emu, op); case 0xF075: return _FX75(emu, op); case 0xF085: return _FX85(emu, op); } break; default: printf("%s %X\n", "Unknown opcode ", op); } }
static void add_vertices(struct line_list **first, struct line_list *what, double yp) { struct line_list **ins,*c; #ifdef POLYDEBUG char *why="unknown"; #define BECAUSE(X) (why=(X)) #else #define BECAUSE(X) #endif while (what) { what->xmin=line_xmin(what,yp,&what->yxmin); what->xmax=line_xmax(what,yp,&what->yxmax); ins=first; #ifdef POLYDEBUG fprintf(stderr," insert %g,%g - %g,%g [%g,%g - %g,%g]\n", what->xmin,what->yxmin, what->xmax,what->yxmax, what->above->x,what->above->y, what->below->x,what->below->y); #endif /* fast jump vectorgroups on the left */ while (*ins) { if ((*ins)->xmax>what->xmin) break; ins=&((*ins)->next); } /* ok, place in correct y for x=what->xmin or x=(*ins)->xmin */ while (*ins) { /* case: -what-> <-ins- */ BECAUSE("what is left of ins"); if ((*ins)->xmin>=what->xmax) break; /* place left of */ /* case: -what- */ /* <-ins- */ if ((*ins)->xmin==what->xmin && (*ins)->yxmin==what->yxmin) { BECAUSE("ins is above (left exact) what"); if (VY((*ins),what->xmax)>what->yxmax) break; else { ins=&((*ins)->next); continue; } } /* case: -what- */ /* -ins-> */ if ((*ins)->xmax==what->xmax && (*ins)->yxmax==what->yxmax) { BECAUSE("ins is above (right exact) what"); if (VY((*ins),what->xmin)>what->yxmin) break; else { ins=&((*ins)->next); continue; } } /* case: -what- */ /* <-ins- */ if ((*ins)->xmin>what->xmin) { BECAUSE("ins is below (right) what"); if ((*ins)->yxmin>VY(what,(*ins)->xmin)) break; } /* case: <-what- */ /* -ins- */ else { BECAUSE("what is above ins (left)"); if (VY((*ins),what->xmin)>what->yxmin) break; } /* case: -what-> */ /* -ins- */ if ((*ins)->xmax>what->xmax) { BECAUSE("what is above ins (right)"); if (VY((*ins),what->xmax)>what->yxmax) break; } /* case: -what- */ /* -ins-> */ else { BECAUSE("ins is below (left) what"); if ((*ins)->yxmax>VY(what,(*ins)->xmax)) break; } ins=&((*ins)->next); } #ifdef POLYDEBUG if (*ins) fprintf(stderr," before %g,%g - %g,%g [%g,%g - %g,%g] because %s\n", (*ins)->xmin,(*ins)->yxmin, (*ins)->xmax,(*ins)->yxmax, (*ins)->above->x,(*ins)->above->y, (*ins)->below->x,(*ins)->below->y, why); #endif c=malloc(sizeof(struct line_list)); if(!c) return; *c=*what; c->next=*ins; *ins=c; what=what->next; } }
/** * @fn void player_board (void) * * @brief Attempt to board the player's target. * * Creates the window on success. */ void player_board (void) { Pilot *p; unsigned int wdw; if (player->target==PLAYER_ID) { player_message("You need a target to board first!"); return; } p = pilot_get(player->target); if (!pilot_isDisabled(p)) { player_message("You cannot board a ship that isn't disabled!"); return; } else if (vect_dist(&player->solid->pos,&p->solid->pos) > p->ship->gfx_space->sw * PILOT_SIZE_APROX) { player_message("You are too far away to board your target."); return; } else if ((pow2(VX(player->solid->vel)-VX(p->solid->vel)) + pow2(VY(player->solid->vel)-VY(p->solid->vel))) > (double)pow2(MAX_HYPERSPACE_VEL)) { player_message("You are going too fast to board the ship."); return; } else if (pilot_isFlag(p,PILOT_BOARDED)) { player_message("Your target cannot be boarded again."); return; }; /* pilot will be boarded */ pilot_setFlag(p,PILOT_BOARDED); player_message("Boarding ship %s.", p->name); /* * create the boarding window */ wdw = window_create( "Boarding", -1, -1, BOARDING_WIDTH, BOARDING_HEIGHT ); window_addText( wdw, 20, -30, 120, 60, 0, "txtCargo", &gl_smallFont, &cDConsole, "Credits:\n" "Cargo:\n" "Fuel:\n" ); window_addText( wdw, 80, -30, 120, 60, 0, "txtData", &gl_smallFont, &cBlack, NULL ); window_addButton( wdw, 20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnStealCredits", "Credits", board_stealCreds); window_addButton( wdw, 20+BUTTON_WIDTH+20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnStealCargo", "Cargo", board_stealCargo); window_addButton( wdw, 20+2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnStealCargo", "Fuel", board_stealFuel); window_addButton( wdw, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnBoardingClose", "Leave", board_exit ); board_update(wdw); /* * run hook if needed */ pilot_runHook(p, PILOT_HOOK_BOARD); }
static int polyfill_event(double xmin, double xmax, double yp, double *buf, struct line_list **pll, int tog) { struct line_list *c; struct line_list *ll=*pll; int mtog; #ifdef POLYDEBUG fprintf(stderr," event %g,%g - %g,%g tog=%d\n",xmin,yp,xmax,yp+1.0,tog); #endif /* toggle for lines ended at xmin,yp */ c=ll; while (c) { if ( (c->above->y < yp) && ( (c->xmax==xmin && c->yxmax==yp) || (c->xmin==xmin && c->yxmin==yp) ) ) { #ifdef POLYDEBUG fprintf(stderr," toggle for %g,%g - %g,%g [%g,%g - %g,%g]\n", c->xmin,c->yxmin,c->xmax,c->yxmax, c->above->x,c->above->y,c->below->x,c->below->y); #endif tog=!tog; } c=c->next; } #if 0 /* sanity check */ c=ll; while (c && c->next) { if (c->xmin > c->next->xmax || ( c->xmin!=c->xmax && c->next->xmin!=c->next->xmax && c->xmax>=xmin && c->xmin<=xmin && c->next->xmax>=xmin && c->next->xmin<=xmin && (VY(c,xmin)>VY(c->next,xmin) || VY(c,xmax)>VY(c->next,xmax))) ) { struct line_list *l1; /* resort */ #ifdef POLYDEBUG fprintf(stderr," !!! internal resort !!!\n"); fprintf(stderr," on pair: %g,%g - %g,%g [%g,%g - %g,%g]\n %g,%g - %g,%g [%g,%g - %g,%g]\n", c->xmin,c->yxmin,c->xmax,c->yxmax, c->above->x,c->above->y,c->below->x,c->below->y, c->next->xmin,c->next->yxmin,c->next->xmax,c->next->yxmax, c->next->above->x,c->next->above->y, c->next->below->x,c->next->below->y); #endif l1=NULL; add_vertices(&l1,ll,yp); while ((c=*pll)) { *pll=c->next; free(c); } ll=*pll=l1; break; } c=c->next; } #endif /* paint if needed */ if (tog) { #ifdef POLYDEBUG fprintf(stderr," fill %g..%g with 1.0\n",xmin,xmax); #endif polyfill_row_add(buf,xmin,xmax,1.0); } /* loop over events */ mtog=tog; c=ll; while (c) { if (c->xmin<=xmin && c->xmax>=xmax) { double y1 = VY(c,xmin); #ifdef POLYDEBUG double y2 = VY(c,xmax); fprintf(stderr," use line %g,%g - %g,%g [%g,%g - %g,%g] : %g,%g - %g,%g = %+g\n", c->xmin,c->yxmin,c->xmax,c->yxmax, c->above->x,c->above->y,c->below->x,c->below->y, xmin,y1,xmax,y2,(tog?-1.0:1.0)*((y1+y2)/2.0-yp)); #endif polyfill_slant_add(buf,xmin,xmax, DO_NOT_WARN(tog?-1.0:1.0), (yp+1)-y1,-c->dy); tog=!tog; } if (c->xmin>xmax) break; /* skip the rest */ c=c->next; } return mtog; }
static void polyfill_some(struct image *img, struct vertex *v, double *buf) { struct line_list *ll=NULL; int y=0; double ixmax = (double)img->xsize; struct vertex *to_add=v,*to_loose=v; /* beat row for row */ if (y+1.0+1e-10<v->y) y = DOUBLE_TO_INT(v->y); while (y<img->ysize && (to_loose||to_add) ) { double yp = y; struct line_list *c; double xmin, xmax; rgb_group *d; int tog=0; int i; #ifdef POLYDEBUG fprintf(stderr,"\nline %d..%d\n",y,y+1); #endif /* update values for current lines */ c=ll; while (c) { c->xmin=line_xmin(c,yp,&c->yxmin); c->xmax=line_xmax(c,yp,&c->yxmax); c=c->next; } /* add any new vertices */ while (to_add && to_add->y<yp+1.0) { struct vertex *vx=to_add; to_add=to_add->next; add_vertices(&ll,vx->below,yp); } #ifdef POLYDEBUG c=ll; while (c) { fprintf(stderr," line %g,%g - %g,%g [%g,%g - %g,%g]\n", c->xmin,c->yxmin,c->xmax,c->yxmax, c->above->x,c->above->y,c->below->x,c->below->y); c=c->next; } #endif if (!ll) { y++; continue; } /* begin with zeros */ for (i=0; i<img->xsize; i++) buf[i]=0.0; /* sanity check */ c=ll; while (c && c->next) { if (c->xmin > c->next->xmax || c->xmax > c->next->xmin || ( c->xmin!=c->xmax && c->next->xmin!=c->next->xmax && c->next->xmax>=c->xmin && c->next->xmin<=c->xmin && VY(c,c->xmin)>VY(c->next,c->xmin))) { struct line_list *l1; /* resort */ #ifdef POLYDEBUG fprintf(stderr," !!! resort !!!\n"); #endif l1=NULL; add_vertices(&l1,ll,yp); while ((c=ll)) { ll=c->next; free(c); } ll=l1; break; } c=c->next; } /* find first horisintal event */ xmin=ll->xmin; c=ll; while (c) { if (c->xmin<xmin) xmin=c->xmin; c=c->next; } /* loop through all horisontal events */ while (xmin<ixmax) { xmax=1e10; c=ll; while (c) { /* each line has two events: beginning and end */ if (c->xmin<xmax && c->xmin>xmin) xmax=c->xmin; if (c->xmax<xmax && c->xmax>xmin) xmax=c->xmax; c=c->next; } if (xmax==1e10) break; /* no more events */ if (xmax>ixmax) xmax=ixmax; tog=polyfill_event(xmin,xmax,yp,buf,&ll,tog); /* shift to get next event */ xmin = xmax; xmax = DO_NOT_WARN(xmin - 1.0); } /* remove any old vertices */ while (to_loose!=to_add && to_loose->y<yp+1.0-1e-10) { struct vertex *vx=to_loose; to_loose=to_loose->next; sub_vertices(&ll,vx,yp); } /* write this row */ d=img->img+img->xsize*y; if(THIS->alpha) { for (i=0; i<img->xsize; i++) { #ifdef POLYDEBUG fprintf(stderr,"%3.2f ",buf[i]); #endif #define apply_alpha(x,y,alpha) \ ((unsigned char)((y*(255L-(alpha))+x*(alpha))/255L)) d->r = apply_alpha( d->r, DOUBLE_TO_COLORTYPE((d->r*(1.0-buf[i]))+ (img->rgb.r*buf[i])), THIS->alpha ); d->g = apply_alpha( d->g, DOUBLE_TO_COLORTYPE((d->g*(1.0-buf[i]))+ (img->rgb.g*buf[i])), THIS->alpha ); d->b = apply_alpha( d->b, DOUBLE_TO_COLORTYPE((d->b*(1.0-buf[i]))+ (img->rgb.b*buf[i])), THIS->alpha ); d++; } #ifdef POLYDEBUG fprintf(stderr,"\n"); #endif } else { for (i=0; i<img->xsize; i++) { #ifdef POLYDEBUG fprintf(stderr,"%3.2f ",buf[i]); #endif d->r = DOUBLE_TO_COLORTYPE((d->r*(1.0-buf[i]))+(img->rgb.r*buf[i])); d->g = DOUBLE_TO_COLORTYPE((d->g*(1.0-buf[i]))+(img->rgb.g*buf[i])); d->b = DOUBLE_TO_COLORTYPE((d->b*(1.0-buf[i]))+(img->rgb.b*buf[i])); d++; } #ifdef POLYDEBUG fprintf(stderr,"\n"); #endif } y++; } while (ll) { struct line_list *c; ll=(c=ll)->next; free(c); } }
//--------------------------------------------------------- void NDG2D::Output_Mesh() //--------------------------------------------------------- { static int count = 0; string output_dir = "."; // Write the triangles that underlie current DG mesh // in vtk format. Here we write the basic triangles // either read from the original .neu file, or as // adapted during adaptive mesh refinement (AMR). string buf = umOFORM("%s/mesh2D_N%d_%04d.vtk", output_dir.c_str(), this->N, ++count); FILE *fp = fopen(buf.c_str(), "w"); if (!fp) { umLOG(1, "Could no open %s for output!\n", buf.c_str()); return; } // Set flags and totals int Ncells = 1; // 1 "cell" per triangle int Npts = 3; // 3 vertices per triangle this->Nv = this->VX.length(); // set totals for Vtk output int vtkTotalPoints = this->Nv; int vtkTotalCells = this->K * Ncells; int vtkTotalConns = (this->EToV.num_cols()+1) * this->K * Ncells; //------------------------------------- // 1. Write the VTK header details //------------------------------------- fprintf(fp, "# vtk DataFile Version 2"); fprintf(fp, "\nNuDG++ mesh"); fprintf(fp, "\nASCII"); fprintf(fp, "\nDATASET UNSTRUCTURED_GRID\n"); fprintf(fp, "\nPOINTS %d double", vtkTotalPoints); //------------------------------------- // 2. Write the vertex data //------------------------------------- // write 2D vertex data to file for (int i=1; i<=this->Nv; ++i) { fprintf(fp, "\n%20.12e %20.12e 0.0", VX(i), VY(i)); } //------------------------------------- // 3. Write the element connectivity //------------------------------------- // Number of indices required to define connectivity fprintf(fp, "\n\nCELLS %d %d", vtkTotalCells, vtkTotalConns); // write element connectivity to file for (int k=1; k<=this->K; ++k) { fprintf(fp, "\n3 %5d %5d %5d", EToV(k,1)-1, EToV(k,2)-1, EToV(k,3)-1); } //------------------------------------- // 4. Write the cell types //------------------------------------- // For each element (cell) write a single integer // identifying the cell type. The integer should // correspond to the enumeration in the vtk file: // /VTK/Filtering/vtkCellType.h fprintf(fp, "\n\nCELL_TYPES %d\n", vtkTotalCells); for (int k=1; k<=this->K; ++k) { fprintf(fp, "5 "); // 5:VTK_TRIANGLE if (! (k%10)) fprintf(fp, "\n"); } //------------------------------------- // 5. Write scalar "vtkCellData" //------------------------------------- // TODO: output "cell data" such as element area, // or quality measures such as min/max angles, etc. // TODO: "FaceData" i.e. boundary conditions // ... // add final newline to output fprintf(fp, "\n"); fclose(fp); }
//--------------------------------------------------------- void NDG3D::Hrefine3D(IVec& refineflag) //--------------------------------------------------------- { DVec lVX("lVX"), lVY("lVY"), lVZ("lVZ"); int a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10; // a b c d e f g h i j lVX.load(10, " 0 1 0 0 0.5 0.5 0.0 0.0 0.5 0.0 "); lVY.load(10, " 0 0 1 0 0.0 0.5 0.5 0.0 0.0 0.5 "); lVZ.load(10, " 0 0 0 1 0.0 0.0 0.0 0.5 0.5 0.5 "); assert(4 == Nfaces); IMat lEToV(8,4, "lEToV"), im84(8,4, "im84"), oFnodes(4,6, "oFnodes"); set84(lEToV, 8,4, a, e, g, h, e, b, f, i, g, f, c, j, h, i, j, d, e, g, h, i, h, i, g, j, e, f, g, i, g, i, f, j); set46(oFnodes, 4,6, a, e, b, f, c, g, a, e, b, i, d, h, b, f, c, j, d, i, a, g, c, j, d, h); IMat vnum(gRowData, 4,3, "1 2 3 1 2 4 2 3 4 3 1 4"); int lK = lEToV.num_rows(); IMat lBCType(lK, Nfaces), tm1, tm2; IVec tv(3),tv1,tv2, oFn,vnp,ksids; int kk=0,ff=0,oo=0; for (kk=1; kk<=lK; ++kk) { for (ff=1; ff<=Nfaces; ++ff) { for (oo=1; oo<=Nfaces; ++oo) { oFn = oFnodes.get_row(oo); vnp = vnum.get_row(ff); tm1 = lEToV(kk, vnp); const IVec& knodes = dynamic_cast<const IVec&>(tm1); //tv = intersect(lEToV(k, vnum(p,All)), oFnodes(o,All)); tv = intersect(knodes, oFn); if ( tv.length()==3 ) { lBCType(kk, ff) = oo; } } } } int NV = VX.length()+1; int sp_len = NV + NV*NV; // sparse buffers nnz vals,triplet CSd newVX(sp_len,1, NV, 1, 1); CSd newVY(sp_len,1, NV, 1, 1); CSd newVZ(sp_len,1, NV, 1, 1); Index1D II(1, NV-1); newVX(II,1) = VX; newVY(II,1) = VY; newVZ(II,1) = VZ; IVec ids("ids"); int oldK = K, f1=0; for (int k1=1; k1<=oldK; ++k1) { if (refineflag(k1)) { a = EToV(k1,1); b = EToV(k1,2); c = EToV(k1,3); d = EToV(k1,4); e = NV + std::max(a*NV+b, b*NV + a); f = NV + std::max(b*NV+c, c*NV + b); g = NV + std::max(a*NV+c, c*NV + a); h = NV + std::max(a*NV+d, d*NV + a); i = NV + std::max(b*NV+d, d*NV + b); j = NV + std::max(c*NV+d, d*NV + c); //ks = [k1, K+1:K+7]; IVec ks(1, k1); ks.append(Range(K+1,K+7)); //-------------------------- // EToV(ks,:) = [a e g h; // e b f i; // g f c j; // h i j d; // e g h i; // h i g j; // e f g i; // g i f j]; //-------------------------- set84(im84, 8,4, a, e, g, h, e, b, f, i, g, f, c, j, h, i, j, d, e, g, h, i, h, i, g, j, e, f, g, i, g, i, f, j); //EToV(ks,All) = im84; EToV.merge_rows(ks, im84); for (f1=1; f1<=Nfaces; ++f1) { tv = lBCType(All,f1); ids = find(tv, '!', 0); ksids = ks(ids); tm1 = lBCType(ids,f1); tm2 = BCType(k1, (const IVec&)tm1); // expand BCType to accommodate new range int maxI=ksids.max_val(), maxR=BCType.num_rows(); if (maxI>maxR) {BCType.realloc(maxI, BCType.num_cols());} BCType(ksids,f1) = trans(tm2); } K += 7; newVX.set1(e,1, 0.5*(VX(a)+VX(b))); newVX.set1(f,1, 0.5*(VX(b)+VX(c))); newVX.set1(g,1, 0.5*(VX(c)+VX(a))); newVX.set1(h,1, 0.5*(VX(a)+VX(d))); newVX.set1(i,1, 0.5*(VX(b)+VX(d))); newVX.set1(j,1, 0.5*(VX(c)+VX(d))); newVY.set1(e,1, 0.5*(VY(a)+VY(b))); newVY.set1(f,1, 0.5*(VY(b)+VY(c))); newVY.set1(g,1, 0.5*(VY(c)+VY(a))); newVY.set1(h,1, 0.5*(VY(a)+VY(d))); newVY.set1(i,1, 0.5*(VY(b)+VY(d))); newVY.set1(j,1, 0.5*(VY(c)+VY(d))); newVZ.set1(e,1, 0.5*(VZ(a)+VZ(b))); newVZ.set1(f,1, 0.5*(VZ(b)+VZ(c))); newVZ.set1(g,1, 0.5*(VZ(c)+VZ(a))); newVZ.set1(h,1, 0.5*(VZ(a)+VZ(d))); newVZ.set1(i,1, 0.5*(VZ(b)+VZ(d))); newVZ.set1(j,1, 0.5*(VZ(c)+VZ(d))); } } //------------------------------------- // drop duplicates and sort //------------------------------------- newVX.compress(true); newVY.compress(true); newVZ.compress(true); //ids = sort(unique(EToV(:)), 'ascend'); ids = unique(EToV); int len=ids.max_val(); IVec gnum(len); gnum(ids) = Range(1,ids.length()); VX = full( newVX, ids ); VY = full( newVY, ids ); VZ = full( newVZ, ids ); // EToV = gnum(EToV); EToV.set_map(EToV, gnum); int NV_old = NV-1; // local counters this->Nv = VX.length(); // update member variable umLOG(1, "Hrefine3D [%d] : old Nv = %4d, new Nv = %4d\n", ++refine_count, NV_old, Nv); umLOG(1, " old K = %4d, new K = %4d\n\n", oldK, K); #if (0) tetramesh(EToV, [VX', VY', VZ']) #endif }
//--------------------------------------------------------- void EulerShock2D::precalc_limiter_data() //--------------------------------------------------------- { //--------------------------------------------- // pre-calculate element geometry and constant // factors for use in this->EulerLimiter2D() //--------------------------------------------- Lim_AVE = 0.5 * MassMatrix.col_sums(); DMat dropAVE = eye(Np) - outer(ones(Np),Lim_AVE); Lim_dx = dropAVE*x; Lim_dy = dropAVE*y; // Extract coordinates of vertices of elements IVec v1=EToV(All,1); Lim_xv1=VX(v1); Lim_yv1=VY(v1); IVec v2=EToV(All,2); Lim_xv2=VX(v2); Lim_yv2=VY(v2); IVec v3=EToV(All,3); Lim_xv3=VX(v3); Lim_yv3=VY(v3); const DVec &xv1=Lim_xv1,&xv2=Lim_xv2,&xv3=Lim_xv3; const DVec &yv1=Lim_yv1,&yv2=Lim_yv2,&yv3=Lim_yv3; DMat &fnx=Lim_fnx, &fny=Lim_fny, &fL=Lim_fL; // Compute face unit normals and lengths fnx.resize(3,K); fny.resize(3,K); // fnx = (3,K) = [yv2-yv1; yv3-yv2; yv1-yv3]; fnx.set_row(1, yv2-yv1); fnx.set_row(2, yv3-yv2); fnx.set_row(3, yv1-yv3); // fny = (3,K) = -[xv2-xv1;xv3-xv2;xv1-xv3]; //fny.set_row(1, xv2-xv1); fny.set_row(2, xv3-xv2); fny.set_row(3, xv1-xv3); fny.set_row(1, xv1-xv2); fny.set_row(2, xv2-xv3); fny.set_row(3, xv3-xv1); fL = sqrt(sqr(fnx)+sqr(fny)); fnx.div_element(fL); fny.div_element(fL); //------------------------------------------------------- // Compute coords of element centers and face weights //------------------------------------------------------- // Find neighbors in patch Lim_E1=EToE(All,1); Lim_E2=EToE(All,2); Lim_E3=EToE(All,3); // Compute coordinates of element centers xc0=Lim_AVE*x; xc1=xc0(Lim_E1); xc2=xc0(Lim_E2); xc3=xc0(Lim_E3); yc0=Lim_AVE*y; yc1=yc0(Lim_E1); yc2=yc0(Lim_E2); yc3=yc0(Lim_E3); // Compute weights for face gradients A0=Lim_AVE*J*TWOTHIRD; A1=A0+A0(Lim_E1); A2=A0+A0(Lim_E2); A3=A0+A0(Lim_E3); A1_A2_A3 = A1+A2+A3; // Find boundary faces for each face Lim_id1=find(BCType.get_col(1),'!',0); Lim_id2=find(BCType.get_col(2),'!',0); Lim_id3=find(BCType.get_col(3),'!',0); // Compute location of centers of reflected ghost elements at boundary faces if (1) { DMat FL1=fL(1,Lim_id1), Fnx1=fnx(1,Lim_id1), Fny1=fny(1,Lim_id1); DVec fL1=FL1, fnx1=Fnx1, fny1=Fny1; DVec H1 = 2.0*(dd(A0(Lim_id1),fL1)); xc1(Lim_id1) += 2.0*fnx1.dm(H1); yc1(Lim_id1) += 2.0*fny1.dm(H1); DMat FL2=fL(2,Lim_id2), Fnx2=fnx(2,Lim_id2), Fny2=fny(2,Lim_id2); DVec fL2=FL2, fnx2=Fnx2, fny2=Fny2; DVec H2 = 2.0*(dd(A0(Lim_id2),fL2)); xc2(Lim_id2) += 2.0*fnx2.dm(H2); yc2(Lim_id2) += 2.0*fny2.dm(H2); DMat FL3=fL(3,Lim_id3), Fnx3=fnx(3,Lim_id3), Fny3=fny(3,Lim_id3); DVec fL3=FL3, fnx3=Fnx3, fny3=Fny3; DVec H3 = 2.0*(dd(A0(Lim_id3),fL3)); xc3(Lim_id3) += 2.0*fnx3.dm(H3); yc3(Lim_id3) += 2.0*fny3.dm(H3); } // Find boundary faces IVec bct = trans(BCType); Lim_idI = find(bct, '=', (int)BC_In); Lim_idO = find(bct, '=', (int)BC_Out); Lim_idW = find(bct, '=', (int)BC_Wall); Lim_idC = find(bct, '=', (int)BC_Cyl); Lim_ctx.resize(3,K); Lim_cty.resize(3,K); Lim_ctx.set_row(1,xc1); Lim_ctx.set_row(2,xc2); Lim_ctx.set_row(3,xc3); Lim_cty.set_row(1,yc1); Lim_cty.set_row(2,yc2); Lim_cty.set_row(3,yc3); // load the set of ids Lim_ids.resize(6); Lim_ids(1)=1; Lim_ids(2)=Nfp; Lim_ids(3)=Nfp+1; Lim_ids(4)=2*Nfp; Lim_ids(5)=3*Nfp; Lim_ids(6)=2*Nfp+1; limQ = Q; }