예제 #1
0
int numLevels(BinTree* root) {
  if (root == NULL) {
    return 0;
  } else {
    return 1 + fmax(numLevels(root->left), numLevels(root->right));
  }
}
예제 #2
0
MCMultiGrid::MCMultiGrid (MCLinOp &_lp)
    :
    initialsolution(0),
    Lp(_lp)
{
    Initialize();

    maxiter = def_maxiter;
    numiter = def_numiter;
    nu_0 = def_nu_0;
    nu_1 = def_nu_1;
    nu_2 = def_nu_2;
    nu_f = def_nu_f;
    usecg = def_usecg;
    verbose = def_verbose;
    rtol_b = def_rtol_b;
    atol_b = def_atol_b;
    nu_b = def_nu_b;
    numLevelsMAX = def_numLevelsMAX;
    numlevels = numLevels();
    numcomps = _lp.numberComponents();
    if ( ParallelDescriptor::IOProcessor() && (verbose > 2) )
    {
	BoxArray tmp = Lp.boxArray();
	std::cout << "MCMultiGrid: numlevels = " << numlevels 
		  << ": ngrid = " << tmp.size() << ", npts = [";
	for ( int i = 0; i < numlevels; ++i ) 
        {
	    if ( i > 0 ) tmp.coarsen(2);
	    std::cout << tmp.d_numPts() << " ";
        }
	std::cout << "]" << '\n';

	std::cout << "MCMultiGrid: " << numlevels
	     << " multigrid levels created for this solve" << '\n';
    }

    if ( ParallelDescriptor::IOProcessor() && (verbose > 4) )
    {
	std::cout << "Grids: " << '\n';
	BoxArray tmp = Lp.boxArray();
	for (int i = 0; i < numlevels; ++i)
	{
            Orientation face(0, Orientation::low);
            const DistributionMapping& map = Lp.bndryData().bndryValues(face).DistributionMap();
	    if (i > 0)
		tmp.coarsen(2);
	    std::cout << " Level: " << i << '\n';
	    for (int k = 0; k < tmp.size(); k++)
	    {
		const Box& b = tmp[k];
		std::cout << "  [" << k << "]: " << b << "   ";
		for (int j = 0; j < BL_SPACEDIM; j++)
		    std::cout << b.length(j) << ' ';
                std::cout << ":: " << map[k] << '\n';
	    }
	}
    }
}
예제 #3
0
int
MultiGrid::getNumLevels (int _numlevels)
{
    BL_ASSERT(_numlevels >= 0);
    int oldnumlevels = numlevels;
    numlevels = std::min(_numlevels, numLevels());
    return oldnumlevels;
}
예제 #4
0
파일: MCLinOp.cpp 프로젝트: dwillcox/BoxLib
void
MCLinOp::clearToLevel (int level)
{
    for (int i = level+1; i < numLevels(); ++i)
    {
	gbox[i].clear();
    }
    h.resize(level+1);
    gbox.resize(level+1);
    undrrelxr.resize(level+1);
    tangderiv.resize(level+1);
}
예제 #5
0
bsl::ostream& NetworkDescription::print(bsl::ostream& stream,
                                        int           level,
                                        int           spacesPerLevel) const
{
    bslim::Printer printer(&stream, level, spacesPerLevel);
    printer.start();
    for (bsl::size_t level = 0, endLevel = numLevels();
            level < endLevel;
            level++) {
        bsl::ostringstream label;
        label << "level " << level;
        printer.printAttribute(label.str().c_str(), d_proxies[level]);
    }
    printer.end();

    return stream;
}
예제 #6
0
int main() {
  countdown(10);
  countdownEven(10);

  printf("%s %s a palindrome\n", "MADAM", isPalindrome("MADAM", strlen("MADAM")) ? "is" : "is not");

  LinkedList a = {3, NULL};
  LinkedList b = {-4, &a};
  LinkedList c = {2, &b};
  LinkedList d = {1, &c};

  printf("Sum: %d\n", sum(&d));
  printf("isAllPositive: %d\n", isAllPositive(&d));
  printf( isAllPositiveLessReadableButShorterWithALongerFunctionName(&d) ? "All positive!\n" : "Not all positive!\n");
  
  printList(&d);
  printf("\n");
  printListReverse(&d);
  printf("\n");
  //1 -> 2 -> -4 -> 3 ->
  //3 -> -4 -> 2 -> 1 -> 


  // BinTree* bt1 = NULL;
  // BinTree bt = NULL; // can't assign NULL to struct

  BinTree jean = {"Jean", 24, NULL, NULL}; 
  BinTree jeane = {"Jeane", 27, NULL, NULL}; 
  BinTree icel = {"Icel", 10, NULL, NULL}; 
  BinTree candace = {"Candace", 48, &jean, &jeane}; 
  BinTree lovely = {"Lovely", 9, &icel, NULL}; 
  BinTree honey = {"Honey", 40, &lovely, NULL}; 
  BinTree jj = {"JJ", 3, &honey, &candace}; 

  printf("Population: %d\n", pop(&jj));
  printf("Max sales: %d\n", maxSales(&jj));
  printf("Num levels: %d\n", numLevels(&jj));


  
  return 0;
}
예제 #7
0
파일: LinOp.cpp 프로젝트: suhasjains/BoxLib
void
LinOp::applyBC (MultiFab&      inout,
                int            src_comp,
                int            num_comp,
                int            level,
                LinOp::BC_Mode bc_mode,
                bool           local,
		int            bndry_comp)
{
    BL_PROFILE("LinOp::applyBC()");
    //
    // The inout MultiFab needs at least LinOp_grow ghost cells for applyBC.
    //
    BL_ASSERT(inout.nGrow() >= LinOp_grow);
    //
    // No coarsened boundary values, cannot apply inhomog at lev>0.
    //
    BL_ASSERT(level < numLevels());
    BL_ASSERT(!(level > 0 && bc_mode == Inhomogeneous_BC));

    int flagden = 1; // Fill in undrrelxr.
    int flagbc  = 1; // Fill boundary data.

    if (bc_mode == LinOp::Homogeneous_BC)
        //
        // No data if homogeneous.
        //
        flagbc = 0;

    const bool cross = true;

    inout.FillBoundary(src_comp,num_comp,local,cross);

    prepareForLevel(level);
    //
    // Do periodic fixup.
    //
    BL_ASSERT(level<geomarray.size());
    geomarray[level].FillPeriodicBoundary(inout,src_comp,num_comp,false,local);
    //
    // Fill boundary cells.
    //
    // OMP over boxes
#ifdef _OPENMP
#pragma omp parallel
#endif
    for (MFIter mfi(inout); mfi.isValid(); ++mfi)
    {
        const int gn = mfi.index();

        BL_ASSERT(gbox[level][gn] == inout.box(gn));

        BL_ASSERT(level<maskvals.size() && maskvals[level].local_index(gn)>=0);
        BL_ASSERT(level<lmaskvals.size() && lmaskvals[level].local_index(gn)>=0);
        BL_ASSERT(level<undrrelxr.size());

        const MaskTuple&                 ma  =  maskvals[level][gn];
        const MaskTuple&                 lma = lmaskvals[level][gn];
        const BndryData::RealTuple&      bdl = bgb->bndryLocs(gn);
        const Array< Array<BoundCond> >& bdc = bgb->bndryConds(gn);

        for (OrientationIter oitr; oitr; ++oitr)
        {
            const Orientation o = oitr();

            FabSet&       f   = (*undrrelxr[level])[o];
            int           cdr = o;
            const FabSet& fs  = bgb->bndryValues(o);
            const Mask&   m   = local ? (*lma[o]) : (*ma[o]);
            Real          bcl = bdl[o];
            BL_ASSERT(bdc[o].size()>bndry_comp);
            int           bct = bdc[o][bndry_comp];

            const Box&       vbx   = inout.box(gn);
            FArrayBox&       iofab = inout[mfi];
            BL_ASSERT(f.size()>gn);
            BL_ASSERT(fs.size()>gn);

            FArrayBox&       ffab  = f[mfi];
            const FArrayBox& fsfab = fs[mfi];

            FORT_APPLYBC(&flagden, &flagbc, &maxorder,
                         iofab.dataPtr(src_comp),
                         ARLIM(iofab.loVect()), ARLIM(iofab.hiVect()),
                         &cdr, &bct, &bcl,
                         fsfab.dataPtr(bndry_comp), 
                         ARLIM(fsfab.loVect()), ARLIM(fsfab.hiVect()),
                         m.dataPtr(),
                         ARLIM(m.loVect()), ARLIM(m.hiVect()),
                         ffab.dataPtr(),
                         ARLIM(ffab.loVect()), ARLIM(ffab.hiVect()),
                         vbx.loVect(),
                         vbx.hiVect(), &num_comp, h[level]);
        }
    }
}