Exemplo n.º 1
0
//---------------------------------------------------------
void Maxwell2D::Report(bool bForce)
//---------------------------------------------------------
{
  if (1 == tstep) {
    // print header
    umLOG(1, "\n step    time     Ezmin    Ezmax\n"
             "----------------------------------\n");
  }

  if (1 == tstep || !umMOD(tstep,Nreport) || bForce) {
    umLOG(1, "%5d  %7.3lf   %8.5lf %8.5lf\n", 
              tstep, time, Ez.min_val(), Ez.max_val());
  }

  //#####################################
  // skip field output for timing tests
  //#####################################
  //return;


  if (!umMOD(tstep,Nrender) || bForce) {
    Q_plot.set_col(1, Hx);    // load plot data
    Q_plot.set_col(2, Hy);
    Q_plot.set_col(3, Ez);
    OutputVTK(Q_plot, NvtkInterp);
  }
}
Exemplo n.º 2
0
//---------------------------------------------------------
void CurvedINS2D::Report(bool bForce)
//---------------------------------------------------------
{
  static DMat vort;
  bool normal_report=true;
  if (eVolkerCylinder == sim_type) {normal_report=false;}

#if (1)
  normal_report=true;
#endif

  // print report header on first step
  if (1 == tstep) {
    if (normal_report) {
      umLOG(1, "\n  step    time      min(Ux)    max(Ux)   min(Vort)    max(Vort)\n"
                 "--------------------------------------------------------------------\n");
    } else {
      umLOG(1, "\n  step     time        Cd/ra      Cl/ra       dP   \n"
                 "---------------------------------------------------\n");
    }
  }

  if (normal_report) {
    if (!umMOD(tstep,Nreport)||(1==tstep)||(tstep==Nsteps)||bForce) {

      Curl2D(Ux, Uy, vort);

      umLOG(1, "%7d  %6.3lf  %10.5lf %10.5lf  %10.2lf %10.2lf\n", 
               tstep, time, Ux.min_val(), Ux.max_val(), vort.min_val(), vort.max_val());
    }
  } else {
    // VolkerCylinder: compute coefficients of drag and lift,
    // as well as the pressure drop at the two sample points.
    INSLiftDrag2D(0.05);
  }


  if (!umMOD(tstep,Nrender)||(1==tstep)||(tstep==Nsteps)||bForce) 
  {
    // (this->*ExactSolution)(x, y, time, nu, exUx, exUy, exPR);

    Curl2D(Ux, Uy, vort);

    // load render data
    Q_plot.set_col(1, Ux); // -exUx);
    Q_plot.set_col(2, Uy); // -exUy);
    Q_plot.set_col(3, PR); // -exPR);
    Q_plot.set_col(4, vort);

    OutputVTK(Q_plot, NvtkInterp);
  }
}
Exemplo n.º 3
0
//---------------------------------------------------------
void CurvedINS2D::INSLiftDrag2D(double ra)
//---------------------------------------------------------
{
  // function [Cd, Cl, dP, sw, stri] = INSLiftDrag2D(Ux, Uy, PR, ra, nu, time, tstep, Nsteps)
  // Purpose: compute coefficients of lift, drag and pressure drop at cylinder

  static FILE* fid; 
  static DVec sw1, sw2; 
  static int Nc=0, stri1=0, stri2=0;

  if (1 == tstep) {
    char buf[50]; sprintf(buf, "liftdraghistory%d.dat", N);
    fid = fopen(buf, "w");
    fprintf(fid, "timeCdCldP = [...\n");

    // Sample location and weights for pressure drop
    // Note: the VolkerCylinder test assumes the 2 
    // sample points (-ra, 0), (ra, 0), are vertices 
    // located on the internal cylinder boundary

    Sample2D(-ra, 0.0,  sw1, stri1);
    Sample2D( ra, 0.0,  sw2, stri2);

    Nc = mapC.size()/Nfp;
  }

  bool bDo=false; 
  if (1==tstep || tstep==Nsteps || !umMOD(tstep,10)) { bDo=true; }
  else if (time > 3.90 && time < 3.96) { bDo=true; } // catch C_d  (3.9362)
  else if (time > 5.65 && time < 5.73) { bDo=true; } // catch C_l  (5.6925)
  else if (time > 7.999) { bDo=true; } // catch dP  (8.0)
  if (!bDo) return;

  DVec PRC, nxC, nyC, wv, tv;
  DMat dUxdx,dUxdy, dUydx,dUydy, MM1D, V1D;
  DMat dUxdxC,dUxdyC, dUydxC,dUydyC, hforce, vforce, sJC;
  double dP=0.0, Cd=0.0, Cl=0.0;

  dP = sw1.inner(PR(All,stri1)) - sw2.inner(PR(All,stri2));

  // compute derivatives
  Grad2D(Ux, dUxdx,dUxdy);  dUxdxC=dUxdx(vmapC); dUxdyC=dUxdy(vmapC);
  Grad2D(Uy, dUydx,dUydy);  dUydxC=dUydx(vmapC); dUydyC=dUydy(vmapC);

  PRC=PR(vmapC); nxC=nx(mapC); nyC=ny(mapC); sJC=sJ(mapC);
  hforce = -PRC.dm(nxC) + nu*( nxC.dm(  2.0 *dUxdxC) + nyC.dm(dUydxC+dUxdyC) );
  vforce = -PRC.dm(nyC) + nu*( nxC.dm(dUydxC+dUxdyC) + nyC.dm(  2.0 *dUydyC) );

  hforce.reshape(Nfp, Nc);
  vforce.reshape(Nfp, Nc);
  sJC   .reshape(Nfp, Nc);

  // compute weights for integrating (1,hforce) and (1,vforce)
  V1D = Vandermonde1D(N, r(Fmask(All,1)));
  MM1D = trans(inv(V1D)) / V1D;

  wv = MM1D.col_sums();
  tv = wv*(sJC.dm(hforce));  Cd=tv.sum();  // Compute drag coefficient
  tv = wv*(sJC.dm(vforce));  Cl=tv.sum();  // Compute lift coefficient

  // Output answers for plotting
  fprintf(fid, "%15.14f %15.14f %15.14f %15.14f;...\n", time, Cd/ra, Cl/ra, dP);
  fflush(fid);

  // LOG report
  if (1==tstep || tstep==Nsteps || !umMOD(tstep,Nreport)) { 
    umLOG(1, "%7d   %6.3lf   %9.5lf  %10.6lf  %9.5lf\n", 
              tstep, time, Cd/ra, Cl/ra, dP);
  }

  if (tstep==Nsteps) {
    fprintf(fid, "];\n");
    fclose(fid); fid=NULL;
  }
}
//---------------------------------------------------------
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));
}