int main(int argc, char* argv[])
{
// store the invoking program name
   char* prg_name = argv[0];

// create an object of cpuClock and start it
   cpuClock clock;
   clock.Start();

// provide convenient i/o streams
   std::ostream& out = std::cout;
   std::istream& ein = std::cin;

// begin application
   try
   {
#if 0
      TestCode();
#endif

#if 1
   // create some objects (which will be used repeatedly later)
      tCalDate<int> date;
      tCalGregorian<int> g;
      tCalJulian<int> j;
      tCalRataDie<int> rd;
      tCalIso<int> iso;
      tCalOldHinduSolar<int> oldHS;

   // rather than build date using the followig (which works).
      date = tCalDate<int>( -586,  7, 24);

   // it is safer to build a date using the following
      calYear  y;
      calMonth m;
      calDay   d;

      y = 1968;   m =  5;  d = 15;
      tCalDate<int> bDay(y, m, d);
      g = bDay;
      out << "Day of week for: " << g << " is " << g.Fixed().DayOfWeek() << std::endl << std::endl;

      y = -1900;  m = 12;  d =  5;
      y =  1968;  m =  5;  d = 15;
      y =  1994;  m =  3;  d =  1;
      y =  -586;  m =  7;  d = 24;

      date.Set(y, m, d);

   // test gregorian calendar

   // test assignment, special construction etc.
      g = date;

      tCalGregorian<int> g1(g);
      tCalGregorian<int> g2;

      g2 = g;

      out << g << std::endl << std::endl;

      if ( g.isLeapYear() == true )
      {
         out << g.Year() << " is a leap year " << std::endl;
      }

      out << "Gregorian: " << g << "  => Fixed: " << g.Fixed() << std::endl;
      out << "Day of the week:      " << g.Fixed().DayOfWeek() << std::endl << std::endl;

      tCalDate<int> g_ep_dt(-4713, 11, 24);
      tCalGregorian<int> g_ep( g_ep_dt );

      tCalRataDie<int> rd_g_ep = g_ep.Fixed();

      out << "Fixed from gregorian epoch: " << rd_g_ep << std::endl << std::endl;

   // RD to gregorian.
      rd = -1373427;    // -3760-09-07. Hebrew epoch
      rd = -1721424;    // -4713-11-24. Julian day epoch
      rd =  -214193;    // -0586-07-24. Table entry from book
      rd =       -1;    //  0000-12-30. A day before RD epoch
      rd =  -272787;    // -0746-02-18. Egyptian epoch
      rd =        1;    //  0001-01-01. RD epoch
      rd =   654415;    //  1792-09-22. French Revolutionary epoch.
      rd =   -61387;    // -0168-12-05. Table entry from book
      rd = -1132959;    // -3101-01-23. Hindu Kali Yuga
      rd =   671401;    //  1839-03-27. Table entry from book

      g = rd.Gregorian();

      out << "Fixed: " << rd << " => Gregorian(epoch): " << g << std::endl << std::endl;

   // RD to julian day numbers.
      rd = -214193;

      out << "Julian day number for " << rd << " is " << rd.JulianDayNumber() << std::endl;

      y = 1993;   m = 7;   d = 14;
      date.Set(y, m, d);

      g = date;

      rd = g.Fixed();

      out << "Julian day number for " << g << " is " << rd.JulianDayNumber() << std::endl
          << std::endl;

   // test Julian calendar
      y = -4713;
      m = 1;
      d = 1;
      date.Set(y, m, d);
      j = date;

      tCalJulian<int> j1(j);
      tCalJulian<int> j2;
      j2 = j1;

      rd = j.Fixed();
      out << "Julian day number for " << j << " is " << rd.JulianDayNumber() << std::endl
          << std::endl;

      y = -3761;   m = 10;   d =  7;   // Hebrew epoch (rd = 1,373,427)
      y = -3102;   m =  2;   d = 18;   // Hindu Kali Yuga (rd = -1,132,959)
      y =     1;   m =  1;   d =  3;   // Gregorian epoch (rd = 1)
      y =  1792;   m =  9;   d = 11;   // French Revolutionary (rd = 654,415)
      y = - 747;   m =  2;   d = 26;   // Egyptian epoch. (rd = -272,787)

      y = - 587;   m =  7;   d = 30;   // table entry (checked)

      date.Set(y, m, d);
      j = date;
      rd = j.Fixed();
      out << "Fixed date for " << j << " is " << rd << std::endl;

   // take the same rd and invert and check.
      out << "Julian date for rd: " << rd << "  is: " << rd.Julian() << std::endl;

   // check for Julian epoch (it is the Fixed date corresponding to
   // gregorian date of 0-12-30 (and it yields -1).
      y = 0;
      m = 12;
      d =30;

      date.Set(y, m, d);
      g = date;

      out << "Fixed from Gregorian (Julian epoch): " << g << " is: " << g.Fixed() << std::endl
          << std::endl;
      
   // RD to Julian.
      rd = -1721424;    // -4713-01-02. Julian day epoch
      rd =        1;    //  0001-01-03. RD epoch
      rd =   654415;    //  1792-09-11. French Revolutionary epoch.
      rd =  -272787;    // -0747-02-26. Egyptian epoch
      rd =       -1;    //  0001-01-01. Julian epoch
      rd =   -61387;    // -0169-12-08. Table entry from book
      rd =  -214193;    // -0587-07-30. Table entry from book
      rd = -1132959;    // -3102-02-18. Hindu Kali Yuga
      rd = -1373427;    // -3761-10-07. Hebrew epoch
      rd =   671401;    //  1839-03-15. Table entry from book
      
      j = rd.Julian();

      out << "Fixed:  " << rd << "           => Julian (epoch): " << j << std::endl;
      rd = j.Fixed();
      out << "Julian: " << j << " => RD (epoch): " << rd << std::endl << std::endl;

#if 0 // not testing iso, hindu etc for now.
   // Test ISO calender
      calIsoDate isoDate;

      calWeek w;
      y = -586;   w = 29;  d = 7;
      isoDate.Set(y, w, d);
      iso = isoDate;

      tCalIso<int> iso1 = iso;
      tCalIso<int> iso2;
      iso2 = iso1;

      rd = iso.Fixed();
      out << "For IsoDate: " << iso << " Fixed = " << rd << std::endl;

      rd =   671401;    //  1839-13-03. Table entry from book
      rd =   -61387;    //  -168-49-03
      rd =   601716;    //  1648-24-03
      rd =  -214193;    // -0586-29-07. Table entry from book
      rd =   434355;    //  1190-12-05

      iso = rd.Iso();
      out << "Fixed:  " << rd << "           => ISO (epoch): " << iso << std::endl;
      rd = iso.Fixed();
      out << "ISO: " << iso << " => RD (epoch): " << rd << std::endl << std::endl;

   // what is the iso of todays date? (2004-04-16);
      y = 2004;   m = 4;   d = 19;
      date.Set(y, m, d);
      g = date;
      rd = g.Fixed();

      out << "Gregorian: " << g << "  => ISO: " << rd.Iso() << std::endl << std::endl;

      y = 2005;   m = 1;   d = 1;
      date.Set(y, m, d);
      g = date;
      rd = g.Fixed();

      out << "Gregorian: " << g << "  => ISO: " << rd.Iso() << std::endl << std::endl;

   // date difference (gives number of days between two dates)
      tCalGregorian<int> g_beg;
      tCalGregorian<int> g_end;

      g_beg = tCalDate<int>(1968, 5, 15);
      g_end = tCalDate<int>(2004, 4, 16);
      out << "No of days between: " << g_beg << " and " 
          << g_end << "  = " << g_end-g_beg << std::endl << std::endl;

   // Old hindu calendars
      y = -3102;  m = 2;   d = 18;
      date.Set(y, m, d);
      j = date;
      rd = j.Fixed();
      g = rd.Gregorian();

      out << "Hindu epoch (in RD) = " << j.Fixed() << " => Julian date: " << j << std::endl 
          << "          Gregorian date is: " << g << std::endl << std::endl;


      tCalOldHinduSolar<int> oldHS1 =  oldHS;
      tCalOldHinduSolar<int> oldHS2;

      oldHS2 = oldHS1;

      out << "Arya solar year: " << std::setprecision(16) << oldHS.AryaSolarYear() << std::endl
          << "Jovian period: " << oldHS.JovianPeriod() << std::endl << std::endl;

      rd = -214193;
      rd =  764652;

      oldHS = rd.OldHinduSolar();

      out << "rd: " << rd << " => old hindu solar: " << oldHS << std::endl << std::endl;

      y = 2515;   m = 5;   d = 19;
      date.Set(y, m, d);

      oldHS = date;

      rd = oldHS.Fixed();

      out << "Old hindu solar date: " << oldHS << " => rd: " << rd << std::endl << std::endl;

   // there is some trouble in implementing calOldHinduLunar. dont know what it is
   // but we are not able to put the copy constructor in the implementation file.
   // calOldHinduLunar is an imitation written afresh to settle this problem.
      tCalOldHinduLunar<int> old_hl;

      rd = -214193;
      rd =  764652;

      old_hl = rd.OldHinduLunar();

      out << "rd: " << rd << " => old hindu lunar: " << old_hl << std::endl << std::endl;

      bool lm;
      calDateOldHinduLunar l_date;
      y = 2515;   m = 6;   lm = false; d = 11;
      y = 5195;   m = 4;   lm = false; d =  6;
      l_date.Set(y, m, lm, d);

      old_hl = l_date;

      rd = old_hl.Fixed();
      g = rd.Gregorian();

      out << "Old hindu lunar date: " << old_hl << " => rd: " << rd << std::endl
          << "     Gregorian date: " << g << std::endl << std::endl;


      y = 1968;   m = 5;   d = 15;
      date.Set(y, m, d);
      g = date;

      rd = g.Fixed();

      old_hl = rd.OldHinduLunar();

      out << " Gregorian: " << g << " Old hindu lunar: " << old_hl << std::endl << std::endl;

      y = 5069;   m =  2;  lm = false; d = 19;
      l_date.Set(y, m, lm, d);
      old_hl = l_date;
      rd = old_hl.Fixed();
      g = rd.Gregorian();

      out << " Old hindu solar: " << old_hl << " Gregorian: " << g << std::endl << std::endl;
#endif
#endif

#if 0
   // old hindu lunisolar calendar
      calOldHinduLunar oldHL;

      rd = -214193;
      rd =  764652;

      oldHL = rd.OldHinduLunar();

      out << "rd: " << rd << " => old hindu lunar: " << oldHL << std::endl << std::endl;

      bool lm;
      calDateOldHinduLunar l_date;
      y = 2515;   m = 6;   lm = false; d = 11;
      y = 5195;   m = 4;   lm = false; d =  6;
      l_date.Set(y, m, lm, d);

      oldHL = l_date;

      rd = oldHL.Fixed();

      out << "Old hindu lunar date: " << oldHL << " => rd: " << rd << std::endl << std::endl;

#endif

#if 0 // data for Amogh to test his Java code
      std::cout << " Gregorian Date        Rata Die" << std::endl;

      y = -1900;  m = 12;  d =  5;
      date.Set(y, m, d);
      g = date;
      rd = g.Fixed();
      std::cout << "   " << g << "          " << rd << std::endl;

      y =  1968;  m =  5;  d = 15;
      date.Set(y, m, d);
      g = date;
      rd = g.Fixed();
      std::cout << "   " << g << "          " << rd << std::endl;

      y =  1994;  m =  3;  d =  1;
      date.Set(y, m, d);
      g = date;
      rd = g.Fixed();
      std::cout << "   " << g << "          " << rd << std::endl;

      y =  -586;  m =  7;  d = 24;
      date.Set(y, m, d);
      g = date;
      rd = g.Fixed();
      std::cout << "   " << g << "          " << rd << std::endl;

      y =  2004;  m =  9;  d = 16;
      date.Set(y, m, d);
      g = date;
      rd = g.Fixed();
      std::cout << "   " << g << "          " << rd << std::endl;

#endif
   }

   catch (anException e)
   {
      out << std::endl << e << std::endl;
   }

// stop the clock and display cpu time
   clock.Stop();
   clock.Display();

// write a closure message and finish the program
   out << std::endl << "Program <"       << prg_name
       << "> completed successfully :-)"
       << std::endl;
   return 0;
}
예제 #2
0
 int __cdecl g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8)
     const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); return 0; }
예제 #3
0
파일: nnls.c 프로젝트: EESI/quikr
int64_t nnls_algorithm(double *a, int64_t m,int64_t n, double *b, double *x, double *rnorm) {
  int64_t pfeas;
  int ret=0;
  int64_t iz;
  int64_t jz;
  int64_t k, j=0, l, itmax, izmax=0, ii, jj=0, ip;
  double d1, d2, sm, up, ss; 
  double temp, wmax, t, alpha, asave, dummy, unorm, ztest, cc;


  /* Check the parameters and data */
  if(m <= 0 || n <= 0 || a == NULL || b == NULL || x == NULL) 
    return(2);

  /* Allocate memory for working space, if required */
  double *w = calloc(n, sizeof(double));
  double *zz = calloc(m, sizeof(double));
  int64_t *index = calloc(n, sizeof(int64_t));
  if(w == NULL || zz == NULL || index == NULL) 
    return(2);

  /* Initialize the arrays INDEX[] and X[] */
  for(k=0; k<n; k++) {
    x[k]=0.;
    index[k]=k;
  }

  int64_t iz2 = n - 1;
  int64_t iz1 = 0;
  int64_t iter=0; 
  int64_t nsetp=0;
  int64_t npp1=0;

  /* Main loop; quit if all coeffs are already in the solution or */
  /* if M cols of A have been triangularized */
  if(n < 3) 
    itmax=n*3;
  else 
    itmax=n*n;
 

  while(iz1 <= iz2 && nsetp < m) {
    /* Compute components of the dual (negative gradient) vector W[] */
    for(iz=iz1; iz<=iz2; iz++) {
      j=index[iz];
      sm=0.;
      for(l=npp1; l<m; l++) 
        sm+=a[j*m + l]*b[l];
      w[j]=sm;
    }

    while(1) {
      /* Find largest positive W[j] */
      for(wmax=0., iz=iz1; iz<=iz2; iz++) {
        j=index[iz]; if(w[j]>wmax) {wmax=w[j]; izmax=iz;}}

      /* Terminate if wmax<=0.; */
      /* it indicates satisfaction of the Kuhn-Tucker conditions */
      if(wmax<=0.0)
        break;

      iz=izmax; 
      j=index[iz];

      /* The sign of W[j] is ok for j to be moved to set P. */
      /* Begin the transformation and check new diagonal element to avoid */
      /* near linear dependence. */
      asave=a[j*m + npp1];
      h12(1, npp1, npp1+1, m, &a[j*m +0], 1, &up, &dummy, 1, 1, 0);
      unorm=0.;
      if(nsetp!=0){
        for(l=0; l<nsetp; l++) {
          d1=a[j*m + l]; 
          unorm+=d1*d1;
        }
      }

      unorm=sqrt(unorm);
      d2=unorm+(d1=a[j*m + npp1], fabs(d1)) * 0.01;
      if((d2-unorm)>0.) {
        /* Col j is sufficiently independent. Copy B into ZZ, update ZZ */
        /* and solve for ztest ( = proposed new value for X[j] ) */
        for(l=0; l<m; l++) zz[l]=b[l];
        h12(2, npp1, npp1+1, m, &a[j*m + 0], 1, &up, zz, 1, 1, 1);
        ztest=zz[npp1]/a[j*m +npp1];
        /* See if ztest is positive */
        if(ztest>0.) break;
      }

      /* Reject j as a candidate to be moved from set Z to set P. Restore */
      /* A[npp1,j], set W[j]=0., and loop back to test dual coeffs again */
      a[j*m+ npp1]=asave; w[j]=0.;
    } /* while(1) */

    if(wmax<=0.0)
      break;

    /* Index j=INDEX[iz] has been selected to be moved from set Z to set P. */
    /* Update B and indices, apply householder transformations to cols in */
    /* new set Z, zero subdiagonal elts in col j, set W[j]=0. */
    for(l=0; l<m; ++l) 
      b[l]=zz[l];

    index[iz]=index[iz1];
    index[iz1]=j;
    iz1++;
    npp1++;
    nsetp=npp1;

    if(iz1<=iz2) {
     for(jz=iz1; jz<=iz2; jz++) {
        jj=index[jz];
        h12(2, nsetp-1, npp1, m, &a[j*m +0], 1, &up, &a[jj*m +0], 1, m, 1);
      }
    }

    if(nsetp!=m) {
      for(l=npp1; l<m; l++) 
        a[j*m +l]=0.;
    }

    w[j]=0.;

    /* Solve the triangular system; store the solution temporarily in Z[] */
    for(l=0; l<nsetp; l++) {
      ip=nsetp-(l+1);
      if(l!=0) for(ii=0; ii<=ip; ii++) zz[ii]-=a[jj*m + ii]*zz[ip+1];
      jj=index[ip]; zz[ip]/=a[jj*m +ip];
    }

    /* Secondary loop begins here */
    while(++iter < itmax) {
      /* See if all new constrained coeffs are feasible; if not, compute alpha */
      for(alpha = 2.0, ip = 0; ip < nsetp; ip++) {
        l=index[ip];
        if(zz[ip]<=0.) {
          t = -x[l]/(zz[ip]-x[l]);
          if(alpha > t) {
            alpha = t; 
            jj = ip - 1;
          }
        }
      }

      /* If all new constrained coeffs are feasible then still alpha==2. */
      /* If so, then exit from the secondary loop to main loop */
      if(alpha==2.0) 
        break;

      /* Use alpha (0.<alpha<1.) to interpolate between old X and new ZZ */
      for(ip=0; ip<nsetp; ip++) {
        l = index[ip];
        x[l] += alpha*(zz[ip]-x[l]);
      }

      /* Modify A and B and the INDEX arrays to move coefficient i */
      /* from set P to set Z. */
      k=index[jj+1]; pfeas=1;
      do {
        x[k]=0.;
        if(jj!=(nsetp-1)) {
          jj++;
          for(j=jj+1; j<nsetp; j++) {
            ii=index[j]; index[j-1]=ii;
            g1(a[ii*m + (j-1)], a[ii*m + j], &cc, &ss, &a[ii*m + j-1]);
            for(a[ii*m + j]=0., l=0; l<n; l++) if(l!=ii) {
              /* Apply procedure G2 (CC,SS,A(J-1,L),A(J,L)) */
              temp=a[l*m + j-1];
              a[l*m + j-1]=cc*temp+ss*a[l*m + j];
              a[l*m + j]=-ss*temp+cc*a[l*m + j];
            }
            /* Apply procedure G2 (CC,SS,B(J-1),B(J)) */
            temp=b[j-1]; b[j-1]=cc*temp+ss*b[j]; b[j]=-ss*temp+cc*b[j];
          }
        }
        npp1=nsetp-1; nsetp--; iz1--; index[iz1]=k;

        /* See if the remaining coeffs in set P are feasible; they should */
        /* be because of the way alpha was determined. If any are */
        /* infeasible it is due to round-off error. Any that are */
        /* nonpositive will be set to zero and moved from set P to set Z */
        for(jj=0, pfeas=1; jj<nsetp; jj++) {
          k=index[jj]; if(x[k]<=0.) {pfeas=0; break;}
        }
      } while(pfeas==0);

      /* Copy B[] into zz[], then solve again and loop back */
      for(k=0; k<m; k++) 
        zz[k]=b[k];
      for(l=0; l<nsetp; l++) {
        ip=nsetp-(l+1);
        if(l!=0) for(ii=0; ii<=ip; ii++) zz[ii]-=a[jj*m + ii]*zz[ip+1];
        jj=index[ip]; zz[ip]/=a[jj*m + ip];
      }
    } /* end of secondary loop */

    if(iter>=itmax) {
      ret = 1;
      break;
    }

    for(ip=0; ip<nsetp; ip++) {
      k=index[ip];
      x[k]=zz[ip];
      }
  } /* end of main loop */

  /* Compute the norm of the final residual vector */
  sm=0.;

  if (rnorm != NULL) {
    if (npp1<m) 
      for (k=npp1; k<m; k++) 
        sm+=(b[k] * b[k]);
    else 
      for (j=0; j<n; j++) 
        w[j]=0.;
    *rnorm=sqrt(sm);
  } 

  /* Free working space, if it was allocated here */
  free(w);
  free(zz);
  free(index);
  return(ret);
}
예제 #4
0
 int __cdecl g4(int a1, int a2, int a3, int a4)
     const { g3(a1, a2, a3); g1(a4); return 0; }
예제 #5
0
 int __cdecl g6(int a1, int a2, int a3, int a4, int a5, int a6)
     const { g5(a1, a2, a3, a4, a5); g1(a6); return 0; }
예제 #6
0
파일: ct.c 프로젝트: zeotrope/j7-src
static DF2(fork2){DECLFG;A hs=sv->h;AF h2=VAV(hs)->f2;
 PREF2(fork2);
 R CLBKCO==ID(fs) ? g1(h2(a,w,hs),gs) :
   (NOUN&AT(fs) ? g2(fs,h2(a,w,hs),gs) : g2(f2(a,w,fs),h2(a,w,hs),gs));
}
예제 #7
0
 int __cdecl g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
예제 #8
0
 void g6(int a1, int a2, int a3, int a4, int a5, int a6) const { g5(a1, a2, a3, a4, a5); g1(a6); }
예제 #9
0
 void g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7) const { g6(a1, a2, a3, a4, a5, a6); g1(a7); }
예제 #10
0
 void g4(int a1, int a2, int a3, int a4) const { g3(a1, a2, a3); g1(a4); }
예제 #11
0
 void g5(int a1, int a2, int a3, int a4, int a5) const { g4(a1, a2, a3, a4); g1(a5); }
예제 #12
0
 void g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); }
예제 #13
0
 void g2(int a1, int a2) const { g1(a1); g1(a2); }
예제 #14
0
 void g0() const { g1(17); }
예제 #15
0
파일: main.cpp 프로젝트: LeiDai/hermes
int main(int argc, char* argv[])
{
  // Time measurement.
  Hermes::Mixins::TimeMeasurable cpu_time;
  cpu_time.tick();

  // Load the mesh.
  MeshSharedPtr u_mesh(new Mesh), v_mesh(new Mesh);
  MeshReaderH2D mloader;
  mloader.load("domain.mesh", u_mesh);
  if (MULTI == false)
    u_mesh->refine_towards_boundary("Bdy", INIT_REF_BDY);

  // Create initial mesh (master mesh).
  v_mesh->copy(u_mesh);

  // Initial mesh refinements in the v_mesh towards the boundary.
  if (MULTI == true)
    v_mesh->refine_towards_boundary("Bdy", INIT_REF_BDY);

  // Set exact solutions.
  MeshFunctionSharedPtr<double> exact_u(new ExactSolutionFitzHughNagumo1(u_mesh));
  MeshFunctionSharedPtr<double> exact_v(new ExactSolutionFitzHughNagumo2(MULTI ? v_mesh : u_mesh, K));

  // Define right-hand sides.
  CustomRightHandSide1 g1(K, D_u, SIGMA);
  CustomRightHandSide2 g2(K, D_v);

  // Initialize the weak formulation.
  WeakFormSharedPtr<double> wf(new CustomWeakForm(&g1, &g2));

  // Initialize boundary conditions
  DefaultEssentialBCConst<double> bc_u("Bdy", 0.0);
  EssentialBCs<double> bcs_u(&bc_u);
  DefaultEssentialBCConst<double> bc_v("Bdy", 0.0);
  EssentialBCs<double> bcs_v(&bc_v);

  // Create H1 spaces with default shapeset for both displacement components.
  SpaceSharedPtr<double> u_space(new H1Space<double>(u_mesh, &bcs_u, P_INIT_U));
  SpaceSharedPtr<double> v_space(new H1Space<double>(MULTI ? v_mesh : u_mesh, &bcs_v, P_INIT_V));

  // Initialize coarse and reference mesh solutions.
  MeshFunctionSharedPtr<double> u_sln(new Solution<double>()), v_sln(new Solution<double>()), u_ref_sln(new Solution<double>()), v_ref_sln(new Solution<double>());
  std::vector<MeshFunctionSharedPtr<double> > slns({ u_sln, v_sln });
  std::vector<MeshFunctionSharedPtr<double> > ref_slns({ u_ref_sln, v_ref_sln });
  std::vector<MeshFunctionSharedPtr<double> > exact_slns({ exact_u, exact_v });

  // Initialize refinement selector.
  H1ProjBasedSelector<double> selector(CAND_LIST);
  //HOnlySelector<double> selector;

  // Initialize views.
  Views::ScalarView s_view_0("Solution[0]", new Views::WinGeom(0, 0, 440, 350));
  s_view_0.show_mesh(false);
  Views::OrderView  o_view_0("Mesh[0]", new Views::WinGeom(450, 0, 420, 350));
  Views::ScalarView s_view_1("Solution[1]", new Views::WinGeom(880, 0, 440, 350));
  s_view_1.show_mesh(false);
  Views::OrderView o_view_1("Mesh[1]", new Views::WinGeom(1330, 0, 420, 350));

  // DOF and CPU convergence graphs.
  SimpleGraph graph_dof_est, graph_cpu_est;
  SimpleGraph graph_dof_exact, graph_cpu_exact;

  NewtonSolver<double> newton;
  newton.set_weak_formulation(wf);

  // Adaptivity loop:
  int as = 1;
  bool done = false;
  do
  {
    Hermes::Mixins::Loggable::Static::info("---- Adaptivity step %d:", as);

    // Construct globally refined reference mesh and setup reference space->
    Mesh::ReferenceMeshCreator u_ref_mesh_creator(u_mesh);
    MeshSharedPtr u_ref_mesh = u_ref_mesh_creator.create_ref_mesh();
    Mesh::ReferenceMeshCreator v_ref_mesh_creator(v_mesh);
    MeshSharedPtr v_ref_mesh = v_ref_mesh_creator.create_ref_mesh();
    Space<double>::ReferenceSpaceCreator u_ref_space_creator(u_space, u_ref_mesh);
    SpaceSharedPtr<double> u_ref_space = u_ref_space_creator.create_ref_space();
    Space<double>::ReferenceSpaceCreator v_ref_space_creator(v_space, MULTI ? v_ref_mesh : u_ref_mesh);
    SpaceSharedPtr<double> v_ref_space = v_ref_space_creator.create_ref_space();

    newton.set_spaces({ u_ref_space, v_ref_space });

    int ndof_ref = Space<double>::get_num_dofs({ u_ref_space, v_ref_space });

    // Initialize reference problem.
    Hermes::Mixins::Loggable::Static::info("Solving on reference mesh.");

    // Time measurement.
    cpu_time.tick();

    // Perform Newton's iteration.
    try
    {
      newton.solve();
    }
    catch (Hermes::Exceptions::Exception& e)
    {
      std::cout << e.info();
    }
    catch (std::exception& e)
    {
      std::cout << e.what();
    }

    // Translate the resulting coefficient vector into the instance of Solution.
    Solution<double>::vector_to_solutions(newton.get_sln_vector(), { u_ref_space, v_ref_space }, { u_ref_sln, v_ref_sln });

    // Project the fine mesh solution onto the coarse mesh.
    Hermes::Mixins::Loggable::Static::info("Projecting reference solution on coarse mesh.");
    OGProjection<double> ogProjection; ogProjection.project_global({ u_space, v_space }, ref_slns, slns);

    cpu_time.tick();

    // View the coarse mesh solution and polynomial orders.
    s_view_0.show(u_sln);
    o_view_0.show(u_space);
    s_view_1.show(v_sln);
    o_view_1.show(v_space);

    // Calculate element errors.
    Hermes::Mixins::Loggable::Static::info("Calculating error estimate and exact error.");
    errorCalculator.calculate_errors(slns, exact_slns, false);
    double err_exact_rel_total = errorCalculator.get_total_error_squared() * 100;
    std::vector<double> err_exact_rel;
    err_exact_rel.push_back(errorCalculator.get_error_squared(0) * 100);
    err_exact_rel.push_back(errorCalculator.get_error_squared(1) * 100);

    errorCalculator.calculate_errors(slns, ref_slns, true);
    double err_est_rel_total = errorCalculator.get_total_error_squared() * 100;
    std::vector<double> err_est_rel;
    err_est_rel.push_back(errorCalculator.get_error_squared(0) * 100);
    err_est_rel.push_back(errorCalculator.get_error_squared(1) * 100);

    adaptivity.set_spaces({ u_space, v_space });

    // Time measurement.
    cpu_time.tick();

    // Report results.
    Hermes::Mixins::Loggable::Static::info("ndof_coarse[0]: %d, ndof_fine[0]: %d",
      u_space->get_num_dofs(), u_ref_space->get_num_dofs());
    Hermes::Mixins::Loggable::Static::info("err_est_rel[0]: %g%%, err_exact_rel[0]: %g%%", err_est_rel[0], err_exact_rel[0]);
    Hermes::Mixins::Loggable::Static::info("ndof_coarse[1]: %d, ndof_fine[1]: %d",
      v_space->get_num_dofs(), v_ref_space->get_num_dofs());
    Hermes::Mixins::Loggable::Static::info("err_est_rel[1]: %g%%, err_exact_rel[1]: %g%%", err_est_rel[1], err_exact_rel[1]);
    Hermes::Mixins::Loggable::Static::info("ndof_coarse_total: %d, ndof_fine_total: %d",
      Space<double>::get_num_dofs({ u_space, v_space }),
      Space<double>::get_num_dofs({ u_ref_space, v_ref_space }));
    Hermes::Mixins::Loggable::Static::info("err_est_rel_total: %g%%, err_est_exact_total: %g%%", err_est_rel_total, err_exact_rel_total);

    // Add entry to DOF and CPU convergence graphs.
    graph_dof_est.add_values(Space<double>::get_num_dofs({ u_space, v_space }),
      err_est_rel_total);
    graph_dof_est.save("conv_dof_est.dat");
    graph_cpu_est.add_values(cpu_time.accumulated(), err_est_rel_total);
    graph_cpu_est.save("conv_cpu_est.dat");

    graph_dof_exact.add_values(Space<double>::get_num_dofs({ u_space, v_space }),
      err_exact_rel_total);
    graph_dof_exact.save("conv_dof_exact.dat");
    graph_cpu_exact.add_values(cpu_time.accumulated(), err_exact_rel_total);
    graph_cpu_exact.save("conv_cpu_exact.dat");

    // If err_est too large, adapt the mesh->
    if (err_est_rel_total < ERR_STOP)
      done = true;
    else
    {
      Hermes::Mixins::Loggable::Static::info("Adapting coarse mesh.");
      done = adaptivity.adapt({ &selector, &selector });
    }

    // Increase counter.
    as++;
  } while (done == false);

  Hermes::Mixins::Loggable::Static::info("Total running time: %g s", cpu_time.accumulated());

  // Wait for all views to be closed.
  Views::View::wait();
  return 0;
}
예제 #16
0
 void g8(int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8) const { g7(a1, a2, a3, a4, a5, a6, a7); g1(a8); }
예제 #17
0
파일: ct.c 프로젝트: zeotrope/j7-src
static DF1(fork1){DECLFG;A hs=sv->h;AF h1=VAV(hs)->f1;
 PREF1(fork1);
 R CLBKCO==ID(fs) ? g1(h1(w,hs),gs) :
   (NOUN&AT(fs) ? g2(fs,h1(w,hs),gs) : g2(f1(w,fs),h1(w,hs),gs));
}
예제 #18
0
파일: compiler.c 프로젝트: vroman/edivc
/*
 * void sentencia(void)
 * Analiza un bloque de sentencias
 */
void sentencia(void)
{

  int im1, im2, im3, im4;
  int dir, from, to, step;

  while (pieza >= p_return)
  {
    test_buffer(&mem, &imem_max, imem);
    switch (pieza)
    {
    case p_return:
      inicio_sentencia();
      lexico();
      if (pieza == p_abrir)
      {
        lexico();
        if (pieza != p_cerrar)
        {
          expresion();
          if (pieza != p_cerrar)
            error(3, 18); /* esperando ')' */
          g1(lrtf);
        }
        else
        {
          g1(lret);
        }
        lexico();
      }
      else
      {
        g1(lret);
      }
      if (!free_sintax)
        if (pieza != p_ptocoma)
          error(3, 9); /* esperando ';' */
      while (pieza == p_ptocoma || pieza == p_coma)
        lexico();
      final_sentencia();
      grabar_sentencia();
      break;
    case p_if:
      telseif[itelseif++] = 0;
      inicio_sentencia();
      lexico();
      if (!free_sintax)
        if (pieza != p_abrir)
          error(3, 22); /* esperando '(' */
      if (pieza == p_abrir)
        lexico();
      condicion();
      if (!free_sintax)
        if (pieza != p_cerrar)
          error(3, 18); /* esperando ')' */
      if (pieza == p_cerrar)
        lexico();
      g2(ljpf, 0);
      im1 = imem - 1;
      final_sentencia();
      grabar_sentencia();
    if1:
      sentencia();
      if (pieza == p_else)
      {
        inicio_sentencia();
        lexico();
        g2(ljmp, 0);
        mem[im1] = imem;
        im1 = imem - 1;
        final_sentencia();
        grabar_sentencia();
        sentencia();
      }
      else if (pieza == p_elseif)
      {
        if (itelseif == 0)
          error(0, 73); /* elseif fuera de bloque if */
        inicio_sentencia();
        g2(ljmp, 0);
        telseif[itelseif++] = imem - 1;
        mem[im1] = imem;
        lexico();
        if (!free_sintax)
          if (pieza != p_abrir)
            error(3, 22); /* esperando '(' */
        if (pieza == p_abrir)
          lexico();
        condicion();
        if (!free_sintax)
          if (pieza != p_cerrar)
            error(3, 18); /* esperando ')' */
        if (pieza == p_cerrar)
          lexico();
        g2(ljpf, 0);
        im1 = imem - 1;
        final_sentencia();
        grabar_sentencia();
        goto if1;
      }
      mem[im1] = imem;
      if (pieza != p_end)
        error(0, 57);
      lexico(); /* esperando END */
      while (telseif[--itelseif] != 0)
        mem[telseif[itelseif]] = imem;
      break;
    case p_loop:
      tbreak[itbreak++] = 0;
      tcont[itcont++] = 0;
      lexico();
      im1 = imem;
      sentencia();
      if (pieza != p_end)
        error(0, 57); /* esperando END */
      inicio_sentencia();
      lexico();
      g2(ljmp, im1);
      while (tbreak[--itbreak] != 0)
        mem[tbreak[itbreak]] = imem;
      while (tcont[--itcont] != 0)
        mem[tcont[itcont]] = im1;
      final_sentencia();
      grabar_sentencia();
      break;
    case p_while:
      inicio_sentencia();
      tbreak[itbreak++] = 0;
      tcont[itcont++] = 0;
      im1 = imem;
      lexico();
      if (!free_sintax)
        if (pieza != p_abrir)
          error(3, 22); /* esperando '(' */
      if (pieza == p_abrir)
        lexico();
      condicion();
      if (!free_sintax)
        if (pieza != p_cerrar)
          error(3, 18); /* esperando ')' */
      if (pieza == p_cerrar)
        lexico();
      g2(ljpf, 0);
      im2 = imem - 1;
      final_sentencia();
      grabar_sentencia();
      sentencia();
      if (pieza != p_end)
        error(0, 57);
      inicio_sentencia(); /* esperando END */
      lexico();
      g2(ljmp, im1);
      mem[im2] = imem;
      while (tbreak[--itbreak] != 0)
        mem[tbreak[itbreak]] = imem;
      while (tcont[--itcont] != 0)
        mem[tcont[itcont]] = im1;
      final_sentencia();
      grabar_sentencia();
      break;
    case p_repeat:
      tbreak[itbreak++] = 0;
      tcont[itcont++] = 0;
      lexico();
      im1 = imem;
      sentencia();
      if (pieza != p_until)
        error(0, 58); /* esperando UNTIL */
      inicio_sentencia();
      lexico();
      if (!free_sintax)
        if (pieza != p_abrir)
          error(3, 22); /* esperando '(' */
      if (pieza == p_abrir)
        lexico();
      condicion();
      if (!free_sintax)
        if (pieza != p_cerrar)
          error(3, 18); /* esperando ')' */
      if (pieza == p_cerrar)
        lexico();
      g2(ljpf, im1);
      while (tbreak[--itbreak] != 0)
        mem[tbreak[itbreak]] = imem;
      while (tcont[--itcont] != 0)
        mem[tcont[itcont]] = im1;
      final_sentencia();
      grabar_sentencia();
      break;
    case p_from:
      inicio_sentencia();
      tbreak[itbreak++] = 0;
      tcont[itcont++] = 0;
      lexico();
      if (pieza != p_id)
        error(0, 59); /* esperando una variable */

      if (o->tipo == tvglo)
      {
        dir = o->vglo.offset;
        g2(lcar, dir);
      }
      else if (o->tipo == tvloc && (!o->bloque || o->bloque == bloque_actual))
      {
        dir = -o->vloc.offset;
        g2(lcar, -dir);
        g1(laid);
      }
      else
        error(0, 59); /* esperando una variable */

      lexico();
      if (pieza != p_asig)
        error(3, 7);
      lexico(); /* esperando '=' */
      from = constante();
      if (pieza != p_to)
        error(1, 60);
      lexico(); /* esperando TO */
      to = constante();
      if (from == to)
        error(4, 61); /* sentencia FROM incorrecta */
      if (pieza == p_step)
      {
        lexico();
        step = constante();
        if (from < to && step <= 0)
          error(4, 62); /* el valor step no es válido */
        if (from > to && step >= 0)
          error(4, 62);
      }
      else
      {
        if (from < to)
          step = 1;
        else
          step = -1;
      }
      g2(lcar, from); /* Asignación del from */
      g1(lasi);
      g1(lasp);

      im1 = imem; /* Inicio del bucle */

      if (dir >= 0)
      { /* Comparación de la condición de permanencia */
        g2(lcar, dir);
      }
      else
      {
        g2(lcar, -dir);
        g1(laid);
      }
      g1(lptr);
      g2(lcar, to);
      if (step > 0)
        g1(lmei);
      else
        g1(lmai);
      g2(ljpf, 0);
      im2 = imem - 1;

      final_sentencia();
      grabar_sentencia();
      if (!free_sintax)
        if (pieza != p_ptocoma)
          error(3, 9); /* esperando ';' */
      while (pieza == p_ptocoma || pieza == p_coma)
        lexico();

      sentencia();
      if (pieza != p_end)
        error(0, 57);
      inicio_sentencia(); /* esperando END */
      lexico();

      im3 = imem; /* Posición del continue */

      if (dir >= 0)
      { /* Incremento y vuelta al inicio del bucle */
        g2(lcar, dir);
      }
      else
      {
        g2(lcar, -dir);
        g1(laid);
      }
      g2(lcar, step);
      g1(lada);
      g1(lasp);
      g2(ljmp, im1);
      mem[im2] = imem;

      while (tbreak[--itbreak] != 0)
        mem[tbreak[itbreak]] = imem;
      while (tcont[--itcont] != 0)
        mem[tcont[itcont]] = im3;
      final_sentencia();
      grabar_sentencia();

      break;

    case p_for:
      inicio_sentencia();
      tbreak[itbreak++] = 0;
      tcont[itcont++] = 0;
      lexico();
      if (pieza != p_abrir)
        error(3, 22);
      lexico(); /* esperando '(' */
      if (pieza != p_ptocoma)
      {
        expresion();
        g1(lasp);
        while (pieza == p_coma)
        {
          lexico();
          expresion();
          g1(lasp);
        }
      }
      im1 = imem;
      if (pieza != p_ptocoma)
        error(3, 9);
      lexico(); /* esperando ';' */
      if (pieza == p_ptocoma)
      {
        g2(lcar, 1);
      }
      else
        expresion();
      g2(ljpf, 0);
      im2 = imem - 1;
      while (pieza == p_coma)
      {
        lexico();
        expresion();
        g2(ljpf, im2);
        im2 = imem - 1;
      }
      g2(ljmp, 0);
      im3 = imem - 1;
      if (pieza != p_ptocoma)
        error(3, 9);
      lexico(); /* esperando ';' */
      if (pieza != p_cerrar)
      {
        expresion();
        g1(lasp);
        while (pieza == p_coma)
        {
          lexico();
          expresion();
          g1(lasp);
        }
      }
      g2(ljmp, im1);
      if (pieza != p_cerrar)
        error(3, 18);
      lexico(); /* esperando ')' */
      final_sentencia();
      grabar_sentencia();
      mem[im3++] = imem;
      sentencia();
      if (pieza != p_end)
        error(0, 57); /* esperando END */
      inicio_sentencia();
      lexico();
      g2(ljmp, im3);
      do
      {
        im1 = mem[im2];
        mem[im2] = imem;
        im2 = im1;
      } while (im2);
      while (tbreak[--itbreak] != 0)
        mem[tbreak[itbreak]] = imem;
      while (tcont[--itcont] != 0)
        mem[tcont[itcont]] = im3;
      final_sentencia();
      grabar_sentencia();
      break;
    case p_switch:
      inicio_sentencia();
      lexico();
      if (!free_sintax)
        if (pieza != p_abrir)
          error(3, 22); /* esperando '(' */
      if (pieza == p_abrir)
        lexico();
      condicion();
      if (!free_sintax)
        if (pieza != p_cerrar)
          error(3, 18); /* esperando ')' */
      if (pieza == p_cerrar)
        lexico();
      while (pieza == p_ptocoma)
      {
        lexico();
      }
      final_sentencia();
      grabar_sentencia();
      im1 = 0;
      im2 = 0;
      while (pieza != p_end)
      {
        inicio_sentencia();
        if (pieza == p_case)
        {
          im3 = 0;
          do
          {

            lexico();
            if (im1)
              mem[im1] = imem;
            expresion();
            if (pieza != p_rango)
            {
              g2(lcse, 0);
              im1 = imem - 1;
            }
            else
            {
              lexico();
              expresion();
              g2(lcsr, 0);
              im1 = imem - 1;
            }

            if (pieza == p_coma)
            {
              g2(ljmp, im3);
              im3 = imem - 1;
            }

          } while (pieza == p_coma);

          while (im3)
          {
            im4 = mem[im3];
            mem[im3] = imem;
            im3 = im4;
          }
        }
        else if (pieza == p_default)
        {
          lexico();
          if (im1)
            mem[im1] = imem;
          im1 = 0;
        }
        else
          error(0, 63); /* esperando case, default o end */
        if (!free_sintax)
          if (pieza != p_ptocoma)
            error(3, 64); /* esperando ':' */
        while (pieza == p_ptocoma || pieza == p_coma)
          lexico();
        g1(lasp);
        final_sentencia();
        grabar_sentencia();
        sentencia();
        if (pieza != p_end)
          error(0, 57); /* esperando END */
        inicio_sentencia();
        g2(ljmp, im2);
        im2 = imem - 1;
        pasa_ptocoma();
        final_sentencia();
        grabar_sentencia();
      }
      inicio_sentencia();
      if (im1)
        mem[im1] = imem;
      g1(lasp);
      while (im2)
      {
        im1 = mem[im2];
        mem[im2] = imem;
        im2 = im1;
      }
      lexico();
      final_sentencia();
      grabar_sentencia();
      break;
    case p_frame:
      inicio_sentencia();
      lexico();
      if (pieza == p_abrir)
      {
        lexico();
        if (pieza != p_cerrar)
        {
          expresion();
          if (pieza != p_cerrar)
            error(3, 18); /* esperando ')' */
          g1(lfrf);
        }
        else
        {
          g1(lfrm);
        }
        lexico();
      }
      else
      {
        g1(lfrm);
      }
      if (!free_sintax)
        if (pieza != p_ptocoma)
          error(3, 9); /* esperando ';' */
      while (pieza == p_ptocoma || pieza == p_coma)
        lexico();
      final_sentencia();
      grabar_sentencia();
      break;
    case p_debug:
      inicio_sentencia();
      g1(ldbg);
      lexico();
      if (!free_sintax)
        if (pieza != p_ptocoma)
          error(3, 9); /* esperando ';' */
      while (pieza == p_ptocoma || pieza == p_coma)
        lexico();
      final_sentencia();
      grabar_sentencia();
      break;
    case p_break:
      inicio_sentencia();
      if (itbreak == 0)
        error(0, 65);
      lexico(); /* break fuera de un bucle */
      if (!free_sintax)
        if (pieza != p_ptocoma)
          error(3, 9); /* esperando ';' */
      while (pieza == p_ptocoma || pieza == p_coma)
        lexico();
      g2(ljmp, 0);
      tbreak[itbreak++] = imem - 1;
      final_sentencia();
      grabar_sentencia();
      break;
    case p_continue:
      inicio_sentencia();
      if (itcont == 0)
        error(0, 66);
      lexico(); /* continue fuera de un bucle */
      if (!free_sintax)
        if (pieza != p_ptocoma)
          error(3, 9); /* esperando ';' */
      while (pieza == p_ptocoma || pieza == p_coma)
        lexico();
      g2(ljmp, 0);
      tcont[itcont++] = imem - 1;
      final_sentencia();
      grabar_sentencia();
      break;
    case p_clone:
      inicio_sentencia();
      lexico();
      g2(lclo, 0);
      im1 = imem - 1;
      final_sentencia();
      grabar_sentencia();
      sentencia();
      if (pieza != p_end)
        error(0, 57);
      lexico(); /* esperando END */
      mem[im1] = imem;
      break;
    case p_ptocoma:
      lexico();
      break;
    default:
      inicio_sentencia();
      error_25 = 67;
      expresion();
      do
      {
        _exp--;
      } while ((*_exp).tipo == eoper && (*_exp).token == p_string);
      error_25 = 25;
      switch ((*_exp).tipo)
      {
      case ecall:
        break;
      case efext:
        break;
      case eoper:
        switch ((*_exp).token)
        {
        case p_asig:
        case p_inc:
        case p_suma:
        case p_dec:
        case p_resta:
        case p_add_asig:
        case p_sub_asig:
        case p_mul_asig:
        case p_div_asig:
        case p_mod_asig:
        case p_and_asig:
        case p_or_asig:
        case p_xor_asig:
        case p_shr_asig:
        case p_shl_asig:

        case p_asigword:
        case p_incword:
        case p_sumaword:
        case p_decword:
        case p_restaword:
        case p_add_asigword:
        case p_sub_asigword:
        case p_mul_asigword:
        case p_div_asigword:
        case p_mod_asigword:
        case p_and_asigword:
        case p_or_asigword:
        case p_xor_asigword:
        case p_shr_asigword:
        case p_shl_asigword:

        case p_asigchar:
        case p_incchar:
        case p_sumachar:
        case p_decchar:
        case p_restachar:
        case p_add_asigchar:
        case p_sub_asigchar:
        case p_mul_asigchar:
        case p_div_asigchar:
        case p_mod_asigchar:
        case p_and_asigchar:
        case p_or_asigchar:
        case p_xor_asigchar:
        case p_shr_asigchar:
        case p_shl_asigchar:

        case p_strcpy:
        case p_strcat:
        case p_strsub:
          break;
        default:
          error(4, 68);
          break; /* expresion sin sentido */
        }
        break;
      default:
        error(4, 68); /* expresion sin sentido */
      }
      if (!free_sintax)
        if (pieza != p_ptocoma)
          error(3, 9); /* esperando ';' */
      while (pieza == p_ptocoma || pieza == p_coma)
        lexico();
      g1(lasp);
      final_sentencia();
      grabar_sentencia();
      break;
    }
  }
}
예제 #19
0
 int __cdecl g0() const { g1(17); return 0; }
예제 #20
0
파일: t121.C 프로젝트: MaxKellermann/gcc
void g1 (void (*) (...)); void h1 () { g1 (f); }// { dg-error "invalid conversion" }
예제 #21
0
 int __cdecl g3(int a1, int a2, int a3) const { g2(a1, a2); g1(a3); return 0; }
예제 #22
0
	void CLabelUI::PaintText(HDC hDC)
	{
		if( m_dwTextColor == 0 ) m_dwTextColor = m_pManager->GetDefaultFontColor();
		if( m_dwDisabledTextColor == 0 ) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor();

		RECT rc = m_rcItem;
		rc.left += m_rcTextPadding.left;
		rc.right -= m_rcTextPadding.right;
		rc.top += m_rcTextPadding.top;
		rc.bottom -= m_rcTextPadding.bottom;

		if(!GetEnabledEffect())
		{
			if( m_sText.IsEmpty() ) return;
			int nLinks = 0;
			if( IsEnabled() ) {
				if( m_bShowHtml )
					CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \
					NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle);
				else
					CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \
					m_iFont, DT_SINGLELINE | m_uTextStyle);
			}
			else {
				if( m_bShowHtml )
					CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \
					NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle);
				else
					CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \
					m_iFont, DT_SINGLELINE | m_uTextStyle);
			}
		}
		else
		{
			Font	nFont(hDC,m_pManager->GetFont(GetFont()));
			Graphics nGraphics(hDC);
			nGraphics.SetTextRenderingHint(TextRenderingHintAntiAlias);

			StringFormat format;
			StringAlignment sa = StringAlignment::StringAlignmentNear;
			if ((m_uTextStyle & DT_VCENTER) != 0) sa = StringAlignment::StringAlignmentCenter;
			else if( (m_uTextStyle & DT_BOTTOM) != 0) sa = StringAlignment::StringAlignmentFar;
			format.SetAlignment((StringAlignment)sa);
			sa = StringAlignment::StringAlignmentNear;
			if ((m_uTextStyle & DT_CENTER) != 0) sa = StringAlignment::StringAlignmentCenter;
			else if( (m_uTextStyle & DT_RIGHT) != 0) sa = StringAlignment::StringAlignmentFar;
			format.SetLineAlignment((StringAlignment)sa);

			RectF nRc((float)rc.left,(float)rc.top,(float)rc.right-rc.left,(float)rc.bottom-rc.top);
			RectF nShadowRc = nRc;
			nShadowRc.X += m_ShadowOffset.X;
			nShadowRc.Y += m_ShadowOffset.Y;

			int nGradientLength	= GetGradientLength();

			if(nGradientLength == 0)
				nGradientLength = (rc.bottom-rc.top);

			LinearGradientBrush nLineGrBrushA(Point(GetGradientAngle(), 0),Point(0,nGradientLength),ARGB2Color(GetTextShadowColorA()),ARGB2Color(GetTextShadowColorB() == -1?GetTextShadowColorA():GetTextShadowColorB()));
			LinearGradientBrush nLineGrBrushB(Point(GetGradientAngle(), 0),Point(0,nGradientLength),ARGB2Color(GetTextColor()),ARGB2Color(GetTextColor1() == -1?GetTextColor():GetTextColor1()));

			if (GetEnabledLuminous())
			{
				// from http://bbs.csdn.net/topics/390346428
				int iFuzzyWidth = (int)(nRc.Width/GetLuminousFuzzy());
				if (iFuzzyWidth < 1) iFuzzyWidth = 1;
				int iFuzzyHeight = (int)(nRc.Height/GetLuminousFuzzy());
				if (iFuzzyHeight < 1) iFuzzyHeight = 1;
				RectF nTextRc(0.0f, 0.0f, nRc.Width, nRc.Height);

				Bitmap Bit1((INT)nRc.Width, (INT)nRc.Height);
				Graphics g1(&Bit1);
				g1.SetSmoothingMode(SmoothingModeAntiAlias);
				g1.SetTextRenderingHint(TextRenderingHintAntiAlias);
				g1.SetCompositingQuality(CompositingQualityAssumeLinear);
				Bitmap Bit2(iFuzzyWidth, iFuzzyHeight);
				Graphics g2(&Bit2);
				g2.SetInterpolationMode(InterpolationModeHighQualityBicubic);
				g2.SetPixelOffsetMode(PixelOffsetModeNone);

				FontFamily ftFamily;
				nFont.GetFamily(&ftFamily);
				int iLen = wcslen(m_pWideText);
				g1.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushB);

				g2.DrawImage(&Bit1, 0, 0, (int)iFuzzyWidth, (int)iFuzzyHeight);
				g1.Clear(Color(0));
				g1.DrawImage(&Bit2, (int)m_ShadowOffset.X, (int)m_ShadowOffset.Y, (int)nRc.Width, (int)nRc.Height);
				g1.SetTextRenderingHint(TextRenderingHintAntiAlias);

				nGraphics.DrawImage(&Bit1, nRc.X, nRc.Y);
			}
			
			if(GetEnabledStroke() && GetStrokeColor() > 0)
			{
				LinearGradientBrush nLineGrBrushStroke(Point(GetGradientAngle(),0),Point(0,rc.bottom-rc.top+2),ARGB2Color(GetStrokeColor()),ARGB2Color(GetStrokeColor()));
#ifdef _UNICODE
				nRc.Offset(-1,0);
				nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
				nRc.Offset(2,0);
				nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
				nRc.Offset(-1,-1);
				nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
				nRc.Offset(0,2);
				nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
				nRc.Offset(0,-1);
#else
				int iLen = wcslen(m_pWideText);
				nRc.Offset(-1,0);
				nGraphics.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushStroke);
				nRc.Offset(2,0);
				nGraphics.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushStroke);
				nRc.Offset(-1,-1);
				nGraphics.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushStroke);
				nRc.Offset(0,2);
				nGraphics.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushStroke);
				nRc.Offset(0,-1);
#endif	
			}
#ifdef _UNICODE
			if(GetEnabledShadow() && (GetTextShadowColorA() > 0 || GetTextShadowColorB() > 0))
				nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nShadowRc,&format,&nLineGrBrushA);

			nGraphics.DrawString(m_sText,m_sText.GetLength(),&nFont,nRc,&format,&nLineGrBrushB);
#else
			int iLen = wcslen(m_pWideText);
			if(GetEnabledShadow() && (GetTextShadowColorA() > 0 || GetTextShadowColorB() > 0))
				nGraphics.DrawString(m_pWideText,iLen,&nFont,nShadowRc,&format,&nLineGrBrushA);

			nGraphics.DrawString(m_pWideText,iLen,&nFont,nRc,&format,&nLineGrBrushB);
#endif
		}
	}
예제 #23
0
 int __cdecl g5(int a1, int a2, int a3, int a4, int a5)
     const { g4(a1, a2, a3, a4); g1(a5); return 0; }
예제 #24
0
TEST(McmcDiagEMetric, gradients) {
  rng_t base_rng(0);

  Eigen::VectorXd q = Eigen::VectorXd::Ones(11);

  stan::mcmc::diag_e_point z(q.size());
  z.q = q;
  z.p.setOnes();

  std::fstream data_stream(std::string("").c_str(), std::fstream::in);
  stan::io::dump data_var_context(data_stream);
  data_stream.close();

  std::stringstream model_output;
  funnel_model_namespace::funnel_model model(data_var_context, &model_output);


  std::stringstream debug, info, warn, error, fatal;
  stan::callbacks::stream_logger logger(debug, info, warn, error, fatal);

  stan::mcmc::diag_e_metric<funnel_model_namespace::funnel_model, rng_t> metric(model);

  double epsilon = 1e-6;

  metric.init(z, logger);
  Eigen::VectorXd g1 = metric.dtau_dq(z, logger);

  for (int i = 0; i < z.q.size(); ++i) {

    double delta = 0;

    z.q(i) += epsilon;
    metric.update_potential(z, logger);
    delta += metric.tau(z);

    z.q(i) -= 2 * epsilon;
    metric.update_potential(z, logger);
    delta -= metric.tau(z);

    z.q(i) += epsilon;
    metric.update_potential(z, logger);

    delta /= 2 * epsilon;

    EXPECT_NEAR(delta, g1(i), epsilon);

  }

  Eigen::VectorXd g2 = metric.dtau_dp(z);

  for (int i = 0; i < z.q.size(); ++i) {

    double delta = 0;

    z.p(i) += epsilon;
    delta += metric.tau(z);

    z.p(i) -= 2 * epsilon;
    delta -= metric.tau(z);

    z.p(i) += epsilon;

    delta /= 2 * epsilon;

    EXPECT_NEAR(delta, g2(i), epsilon);

  }

  Eigen::VectorXd g3 = metric.dphi_dq(z, logger);

  for (int i = 0; i < z.q.size(); ++i) {

    double delta = 0;

    z.q(i) += epsilon;
    metric.update_potential(z, logger);
    delta += metric.phi(z);

    z.q(i) -= 2 * epsilon;
    metric.update_potential(z, logger);
    delta -= metric.phi(z);

    z.q(i) += epsilon;
    metric.update_potential(z, logger);

    delta /= 2 * epsilon;

    EXPECT_NEAR(delta, g3(i), epsilon);

  }
  EXPECT_EQ("", model_output.str());
  EXPECT_EQ("", debug.str());
  EXPECT_EQ("", info.str());
  EXPECT_EQ("", warn.str());
  EXPECT_EQ("", error.str());
  EXPECT_EQ("", fatal.str());
}
예제 #25
0
 int __cdecl g7(int a1, int a2, int a3, int a4, int a5, int a6, int a7)
     const { g6(a1, a2, a3, a4, a5, a6); g1(a7); return 0; }
예제 #26
0
 int g0() const { g1(17); return 0; }
예제 #27
0
파일: SSPquadUP.cpp 프로젝트: cix1/OpenSees
void
SSPquadUP::GetStab(void)
// this function computes the stabilization stiffness matrix for the element
{
	Vector g1(SQUP_NUM_DIM);
	Vector g2(SQUP_NUM_DIM);
	Matrix I(SQUP_NUM_DIM,SQUP_NUM_DIM);
	Matrix FCF(SQUP_NUM_DIM,SQUP_NUM_DIM);
	Matrix Jmat(SQUP_NUM_DIM,SQUP_NUM_DIM);
	Matrix Jinv(SQUP_NUM_DIM,SQUP_NUM_DIM);
	Matrix dNloc(SQUP_NUM_NODE,SQUP_NUM_DIM);
	Matrix Mben(2,SQUP_NUM_DOF);
	double Hss;
	double Hst;
	double Htt;
	
	// shape function derivatives (local crd) at center
	dNloc(0,0) = -0.25;
	dNloc(1,0) =  0.25;
	dNloc(2,0) =  0.25;
	dNloc(3,0) = -0.25;
	dNloc(0,1) = -0.25;
	dNloc(1,1) = -0.25;
	dNloc(2,1) =  0.25;
	dNloc(3,1) =  0.25;

	// jacobian matrix
	Jmat = mNodeCrd*dNloc;
	// inverse of the jacobian matrix
	Jmat.Invert(Jinv);

	// shape function derivatives (global crd)
	dN = dNloc*Jinv;

	// define hourglass stabilization vector  gamma = 0.25*(h - (h^x)*bx - (h^y)*by);
	double hx = mNodeCrd(0,0) - mNodeCrd(0,1) + mNodeCrd(0,2) - mNodeCrd(0,3);
	double hy = mNodeCrd(1,0) - mNodeCrd(1,1) + mNodeCrd(1,2) - mNodeCrd(1,3);
	double gamma[4];
	gamma[0] = 0.25*( 1.0 - hx*dN(0,0) - hy*dN(0,1));
	gamma[1] = 0.25*(-1.0 - hx*dN(1,0) - hy*dN(1,1));
	gamma[2] = 0.25*( 1.0 - hx*dN(2,0) - hy*dN(2,1));
	gamma[3] = 0.25*(-1.0 - hx*dN(3,0) - hy*dN(3,1));

	// define mapping matrices
	Mmem.Zero();
	Mben.Zero();
	for (int i = 0; i < 4; i++) {
		Mmem(0,2*i)   = dN(i,0);
		Mmem(1,2*i+1) = dN(i,1);
		Mmem(2,2*i)   = dN(i,1);
		Mmem(2,2*i+1) = dN(i,0);

		Mben(0,2*i)   = gamma[i];
		Mben(1,2*i+1) = gamma[i];
	}

	// base vectors
	g1(0) = Jmat(0,0);
	g1(1) = Jmat(1,0);
	g2(0) = Jmat(0,1);
	g2(1) = Jmat(1,1);
	// normalize base vectors
	g1.Normalize();
	g2.Normalize();
	
	// compute second moment of area tensor
	double fourThree = 4.0/3.0;
	I = fourThree*mThickness*J0*(DyadicProd(g1,g1) + DyadicProd(g2,g2));

	// stabilization terms
	Hss = ( I(0,0)*Jinv(1,0)*Jinv(1,0) + I(0,1)*Jinv(0,0)*Jinv(1,0) + I(1,1)*Jinv(0,0)*Jinv(0,0) )*0.25;
	Htt = ( I(0,0)*Jinv(1,1)*Jinv(1,1) + I(0,1)*Jinv(0,1)*Jinv(1,1) + I(1,1)*Jinv(0,1)*Jinv(0,1) )*0.25;
	Hst = ( I(0,0)*Jinv(1,1)*Jinv(1,0) + I(0,1)*(Jinv(1,0)*Jinv(0,1) + Jinv(1,1)*Jinv(0,0)) + I(1,1)*Jinv(0,1)*Jinv(0,0) )*0.25;

	// get material tangent
	const Matrix &CmatI = theMaterial->getInitialTangent();

	// compute stabilization matrix
	FCF(0,0) = (CmatI(0,0) - (CmatI(0,1) + CmatI(1,0)) + CmatI(1,1))*Hss;
	FCF(0,1) = (CmatI(0,1) - (CmatI(0,0) + CmatI(1,1)) + CmatI(1,0))*Hst;
	FCF(1,0) = (CmatI(1,0) - (CmatI(0,0) + CmatI(1,1)) + CmatI(0,1))*Hst;
	FCF(1,1) = (CmatI(1,1) - (CmatI(0,1) + CmatI(1,0)) + CmatI(0,0))*Htt;
	
	// compute stiffness matrix for stabilization terms
	Kstab.Zero();
	Kstab.addMatrixTripleProduct(1.0, Mben, FCF, 1.0);

	return;
}
예제 #28
0
 int g2(int a1, int a2) const { g1(a1); g1(a2); return 0; }
예제 #29
0
파일: Varbind_Test.cpp 프로젝트: CCJY/ACE
static void VbTest()
{
#if !defined (ACE_WIN32)

  Vb v1;
  ACE_ASSERT(v1.valid() == 0);
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v1(\"/\") [%s]\n",
    v1.to_string()));

  // purpose of this routine??
  set_exception_status( &v1, 10);

  Vb v2(v1);
  ACE_ASSERT(v2.valid() == 0);
  Oid o1("1.2.3"), o2;
  v2.set_oid(o1);
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v2(\"1.2.3/\") [%s]\n",
    v2.to_string()));

  v2.get_oid(o2);
  ACE_ASSERT(o2 == o1);
  ACE_ASSERT(v2.valid() == 0);
  v2.set_null();
  ACE_ASSERT(v2.valid() == 0);
  v2.get_oid(o2);

  Vb v3;
  TimeTicks t(0), t1;
  v3.set_oid(o1);
  v3.set_value(t);
  ACE_ASSERT(v3.valid() == 1);
  v3.get_value(t1);
  ACE_ASSERT(t == t1);

  Vb v4;
  v4.set_oid(o1);
  v4.set_value(o1);
  ACE_ASSERT(v4.valid() == 1);
  v4.get_value(o2);
  ACE_ASSERT(o1 == o2);

  Vb v5;
  Counter32 c1(12), c2;
  v5.set_oid(o1);
  v5.set_value(c1);
  ACE_ASSERT(v5.valid() == 1);
  v5.get_value(c2);
  ACE_ASSERT(c1 == c2);

  Vb v6;
  Counter64 c3(12345678901234ULL), c4;
  v6.set_oid(o1);
  v6.set_value(c3);
  ACE_ASSERT(v6.valid() == 1);
  v6.get_value(c4);
  ACE_ASSERT(c3 == c4);

  Vb v7;
  Gauge32 g1(0123456), g2;
  v7.set_oid(o1);
  v7.set_value(g1);
  ACE_ASSERT(v7.valid() == 1);
  v7.get_value(g2);
  ACE_ASSERT(g1 == g2);

  Vb v8;
  SnmpInt32 i1(0123456), i2;
  v8.set_oid(o1);
  v8.set_value(i1);
  ACE_ASSERT(v8.valid() == 1);
  v8.get_value(i2);
  ACE_ASSERT(i1 == i2);

  Vb v9;
  SnmpUInt32 u1(0123456), u2;
  v9.set_oid(o1);
  v9.set_value(u1);
  ACE_ASSERT(v9.valid() == 1);
  v9.get_value(u2);
  ACE_ASSERT(u1 == u2);

  Vb v10;
  OctetStr s1(" abcdefghighlmnopqrstuvwxyz!@#$%^&*()"), s2;
  v10.set_oid(o1);
  v10.set_value(s1);
  ACE_ASSERT(v10.valid() == 1);
  v10.get_value(s2);
  ACE_ASSERT(s1 == s2);
  ACE_ASSERT(s1.length() == s2.length());

  // test assignment over all datatypes
  v10 = v5;
  ACE_ASSERT(v10 == v5);


  Vb v11(o1, s1, SNMP_CLASS_SUCCESS);
  ACE_ASSERT(v11.valid() == 1);
  v11.get_oid(o2);
  ACE_ASSERT(o1 == o2);
  v11.get_value(s2);
  ACE_ASSERT(s1 == s2);
#endif /*if ACE_WIN32*/
}
예제 #30
0
TEST(McmcDiagEMetric, gradients) {
  
  rng_t base_rng(0);
  
  Eigen::VectorXd q = Eigen::VectorXd::Ones(11);
  
  stan::mcmc::diag_e_point z(q.size());
  z.q = q;
  z.p.setOnes();
  
  std::fstream data_stream(std::string("").c_str(), std::fstream::in);
  stan::io::dump data_var_context(data_stream);
  data_stream.close();
  
  funnel_namespace::funnel model(data_var_context, &std::cout);
  
  stan::mcmc::diag_e_metric<funnel_namespace::funnel, rng_t> metric(model, &std::cout);
  
  double epsilon = 1e-6;
  
  metric.update(z);
  
  Eigen::VectorXd g1 = metric.dtau_dq(z);
  
  for (int i = 0; i < z.q.size(); ++i) {
    
    double delta = 0;
    
    z.q(i) += epsilon;
    metric.update(z);
    delta += metric.tau(z);
    
    z.q(i) -= 2 * epsilon;
    metric.update(z);
    delta -= metric.tau(z);
    
    z.q(i) += epsilon;
    metric.update(z);
    
    delta /= 2 * epsilon;
    
    EXPECT_NEAR(delta, g1(i), epsilon);
    
  }
  
  Eigen::VectorXd g2 = metric.dtau_dp(z);
  
  for (int i = 0; i < z.q.size(); ++i) {
    
    double delta = 0;
    
    z.p(i) += epsilon;
    delta += metric.tau(z);
    
    z.p(i) -= 2 * epsilon;
    delta -= metric.tau(z);
    
    z.p(i) += epsilon;
    
    delta /= 2 * epsilon;
    
    EXPECT_NEAR(delta, g2(i), epsilon);
    
  }
  
  Eigen::VectorXd g3 = metric.dphi_dq(z);
  
  for (int i = 0; i < z.q.size(); ++i) {
    
    double delta = 0;
    
    z.q(i) += epsilon;
    metric.update(z);
    delta += metric.phi(z);
    
    z.q(i) -= 2 * epsilon;
    metric.update(z);
    delta -= metric.phi(z);
    
    z.q(i) += epsilon;
    metric.update(z);
    
    delta /= 2 * epsilon;
    
    EXPECT_NEAR(delta, g3(i), epsilon);
    
  }
  
}