Ejemplo n.º 1
0
Datum
hstore_out(PG_FUNCTION_ARGS)
{
	HStore	   *in = PG_GETARG_HS(0);
	int			buflen,
				i;
	char	   *out,
			   *ptr;
	char	   *base = STRPTR(in);
	HEntry	   *entries = ARRPTR(in);

	if (in->size == 0)
	{
		out = palloc(1);
		*out = '\0';
		PG_FREE_IF_COPY(in, 0);
		PG_RETURN_CSTRING(out);
	}

	buflen = (4 /* " */ + 2 /* => */ + 2 /* , */ ) * in->size +
		2 /* esc */ * (in->len - CALCDATASIZE(in->size, 0));

	out = ptr = palloc(buflen);
	for (i = 0; i < in->size; i++)
	{
		*ptr++ = '"';
		ptr = cpw(ptr, base + entries[i].pos, entries[i].keylen);
		*ptr++ = '"';
		*ptr++ = '=';
		*ptr++ = '>';
		if (entries[i].valisnull)
		{
			*ptr++ = 'N';
			*ptr++ = 'U';
			*ptr++ = 'L';
			*ptr++ = 'L';
		}
		else
		{
			*ptr++ = '"';
			ptr = cpw(ptr, base + entries[i].pos + entries[i].keylen, entries[i].vallen);
			*ptr++ = '"';
		}

		if (i + 1 != in->size)
		{
			*ptr++ = ',';
			*ptr++ = ' ';
		}
	}
	*ptr = '\0';

	PG_FREE_IF_COPY(in, 0);
	PG_RETURN_CSTRING(out);
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{

  bem2d::freqtype k={10,0};
        int n=3*k.re;




        std::vector<bem2d::Point> triangle;
        triangle.push_back(bem2d::Point(0,0));
        triangle.push_back(bem2d::Point(1,0));
        triangle.push_back(bem2d::Point(.5,.5*sqrt(3)));
        bem2d::Polygon poly(triangle,n);
        bem2d::pGeometry pgeom=poly.GetGeometry();



        bem2d::PolBasis::AddBasis(0,pgeom);


        bem2d::Point direction=bem2d::normalize(bem2d::Point(1,1));
        bem2d::PlaneWave pw(direction,k);
        bem2d::CombinedPlaneWave cpw(direction,k);

        bem2d::SoundSoftScattering<bem2d::PlaneWave,bem2d::CombinedPlaneWave> soundsoft(pgeom,k,pw,cpw);
        soundsoft.SetQuadOption(5,5,0.15);
        soundsoft.set_polygons(pgeom);
        soundsoft.set_plotInterior();



        std::cout << "Discretizing with k=" << bem2d::complex(k.re,k.im) << " and n=" << pgeom->size() << std::endl;
        clock_t start, finish;
        double time;

        start=clock();
        soundsoft.Discretize();
        finish=clock();
        time=(double(finish)-double(start))/CLOCKS_PER_SEC;
        std::cout << "Computing time (minutes): " << time/60 << std::endl;



        int xpts=300;
        int ypts=300;
        bem2d::pOutputHandler pout(new bem2d::GplotOutput(xpts,ypts,-4,8,-4,8,"wedge"));
        soundsoft.SetOutput(pout);
        soundsoft.WriteAll();


}
Ejemplo n.º 3
0
//********************************************************************************
void CGuiHeaderCtrl::DrawArrow(CDC* pDC,CRect rc,BOOL bUp)
{
	CPen cp(PS_SOLID,1, m_clrFace);
	CPen cps(PS_SOLID,1, m_clrShadow);
	CPen cpw(PS_SOLID,1, m_clrLight);
	CPen *pOld;
	
	rc.left=rc.right-12;
	rc.right=rc.left+8;
	rc.bottom=rc.top+12;
	rc.top+=2;	
	int m_mitad=rc.left+4;
	
	if (bUp == TRUE)
	{
			//linea izquierda
			pOld=pDC->SelectObject(&cps);
			pDC->MoveTo(rc.left,rc.bottom);
			pDC->LineTo(m_mitad,rc.top);
			//linea derecha
			pDC->SelectObject(&cpw);
			pDC->MoveTo(rc.right,rc.bottom);
			pDC->LineTo(m_mitad,rc.top);
			//linea de abajo
			pDC->MoveTo(rc.left,rc.bottom);
			pDC->LineTo(rc.right,rc.bottom);
	}
	else
	{
			rc.bottom=rc.top+12;
			rc.top+=4;	
			//linea izquierda
			pOld=pDC->SelectObject(&cps);
			pDC->MoveTo(rc.left,rc.top);
			pDC->LineTo(m_mitad,rc.bottom);
			//linea superior
			pDC->MoveTo(rc.left,rc.top);
			pDC->LineTo(rc.right,rc.top);
			//linea derecha
				pDC->SelectObject(&cpw);
			pDC->MoveTo(rc.right,rc.top);
			pDC->LineTo(m_mitad,rc.bottom);

	}

	pDC->SelectObject(pOld);
}
Ejemplo n.º 4
0
//************************************************************************
void CGuiHeaderCtrl::BiselaBoton(CRect rcWin,CDC* pDC)
{
	CPen cp(PS_SOLID,1, m_clrFace);
	CPen cps(PS_SOLID,1, m_clrShadow);
	CPen cpw(PS_SOLID,1, m_clrLight);

	//***************************************************
	pDC->Draw3dRect(rcWin,m_clrLight,m_clrShadow);
	rcWin.DeflateRect(1,1);
	pDC->Draw3dRect(rcWin,m_clrFace,m_clrFace);
	//***************************************************

	CPen* cpold=pDC->SelectObject(&cp);	
	int iNumItems=GetItemCount();
	int iContx=0;
	HDITEM m_hditems;
	
	for (int i =0; i < iNumItems; i++)
	{
		CRect recItem;
		GetItem(i,&m_hditems);
		GetItemRect(i, recItem);
		iContx+=recItem.Width();
		//quitamos todas las lineas
		recItem.DeflateRect(1,1);
		pDC->SelectObject(&cp);
		pDC->MoveTo(iContx-2,rcWin.top+1);
		pDC->LineTo(iContx-2,rcWin.bottom-1);
		pDC->MoveTo(iContx-1,rcWin.top+1);
		pDC->LineTo(iContx-1,rcWin.bottom-1);
		pDC->MoveTo(iContx,rcWin.top+1);
		pDC->LineTo(iContx,rcWin.bottom-1);
		pDC->MoveTo(iContx+1,rcWin.top+1);
		pDC->LineTo(iContx+1,rcWin.bottom-1);
		//ponemos dos para dar el efecto
		pDC->SelectObject(&cps);
		pDC->MoveTo(iContx-1,rcWin.top+2);
		pDC->LineTo(iContx-1,rcWin.bottom-2);
		pDC->SelectObject(&cpw);
		pDC->MoveTo(iContx,rcWin.top+2);
		pDC->LineTo(iContx,rcWin.bottom-2);
	
	}
	pDC->SelectObject(cpold);

}
Ejemplo n.º 5
0
Archivo: hstore_io.c Proyecto: d/gpdb
Datum
hstore_out(PG_FUNCTION_ARGS)
{
	HStore	   *in = PG_GETARG_HS(0);
	int			buflen,
				i;
	int			count = HS_COUNT(in);
	char	   *out,
			   *ptr;
	char	   *base = STRPTR(in);
	HEntry	   *entries = ARRPTR(in);

	if (count == 0)
	{
		out = palloc(1);
		*out = '\0';
		PG_RETURN_CSTRING(out);
	}

	buflen = 0;

	/*
	 * this loop overestimates due to pessimistic assumptions about escaping,
	 * so very large hstore values can't be output. this could be fixed, but
	 * many other data types probably have the same issue. This replaced code
	 * that used the original varlena size for calculations, which was wrong
	 * in some subtle ways.
	 */

	for (i = 0; i < count; i++)
	{
		/* include "" and => and comma-space */
		buflen += 6 + 2 * HS_KEYLEN(entries, i);
		/* include "" only if nonnull */
		buflen += 2 + (HS_VALISNULL(entries, i)
					   ? 2
					   : 2 * HS_VALLEN(entries, i));
	}

	out = ptr = palloc(buflen);

	for (i = 0; i < count; i++)
	{
		*ptr++ = '"';
		ptr = cpw(ptr, HS_KEY(entries, base, i), HS_KEYLEN(entries, i));
		*ptr++ = '"';
		*ptr++ = '=';
		*ptr++ = '>';
		if (HS_VALISNULL(entries, i))
		{
			*ptr++ = 'N';
			*ptr++ = 'U';
			*ptr++ = 'L';
			*ptr++ = 'L';
		}
		else
		{
			*ptr++ = '"';
			ptr = cpw(ptr, HS_VAL(entries, base, i), HS_VALLEN(entries, i));
			*ptr++ = '"';
		}

		if (i + 1 != count)
		{
			*ptr++ = ',';
			*ptr++ = ' ';
		}
	}
	*ptr = '\0';

	PG_RETURN_CSTRING(out);
}
Ejemplo n.º 6
0
bool Foam::solidParticle::move(solidParticle::trackData& td)
{
    td.switchProcessor = false;
    td.keepParticle = true;

    const polyMesh& mesh = cloud().pMesh();
    const polyBoundaryMesh& pbMesh = mesh.boundaryMesh();

    scalar deltaT = mesh.time().deltaT().value();
    scalar tEnd = (1.0 - stepFraction())*deltaT;
    scalar dtMax = tEnd;

    while (td.keepParticle && !td.switchProcessor && tEnd > SMALL)
    {
        if (debug)
        {
            Info<< "Time = " << mesh.time().timeName()
                << " deltaT = " << deltaT
                << " tEnd = " << tEnd
                << " steptFraction() = " << stepFraction() << endl;
        }

        // set the lagrangian time-step
        scalar dt = min(dtMax, tEnd);

        // remember which cell the parcel is in
        // since this will change if a face is hit
        label celli = cell();

        dt *= trackToFace(position() + dt*U_, td);

        tEnd -= dt;
        stepFraction() = 1.0 - tEnd/deltaT;

        cellPointWeight cpw(mesh, position(), celli, face());
        scalar rhoc = td.rhoInterp().interpolate(cpw);
        vector Uc = td.UInterp().interpolate(cpw);
        scalar nuc = td.nuInterp().interpolate(cpw);

        scalar rhop = td.spc().rhop();
        scalar magUr = mag(Uc - U_);

        scalar ReFunc = 1.0;
        scalar Re = magUr*d_/nuc;

        if (Re > 0.01)
        {
            ReFunc += 0.15*pow(Re, 0.687);
        }

        scalar Dc = (24.0*nuc/d_)*ReFunc*(3.0/4.0)*(rhoc/(d_*rhop));

        U_ = (U_ + dt*(Dc*Uc + (1.0 - rhoc/rhop)*td.g()))/(1.0 + dt*Dc);

        if (onBoundary() && td.keepParticle)
        {
            // Bug fix.  HJ, 25/Aug/2010
            if (face() > -1)
            {
                if (isType<processorPolyPatch>(pbMesh[patch(face())]))
                {
                    td.switchProcessor = true;
                }
            }
        }
    }

    return td.keepParticle;
}
Ejemplo n.º 7
0
int main(int argc, char** argv)
{

#ifdef BEM2DMPI
        MPI_Init(&argc, &argv);


        int nprow=2;
        int npcol=1;
        int mb=100;
        int nb=100;
        bem2d::BlacsSystem* b=bem2d::BlacsSystem::Initialize(nprow,npcol,mb,nb);

        if (!b) {
                std::cout <<  "Could not create Blacs context" << std::endl;
                MPI_Finalize();
                exit(1);
        }
        if ((b->get_myrow()==-1)&&(b->get_mycol()==-1)) {
                MPI_Finalize();
                exit(0);
        }



        int myrow=b->get_myrow();
        int mycol=b->get_mycol();
#endif


        int m=4;
        bem2d::freqtype k={5*m,0};
        int n=20*m;

        double a=0.31;
        double c=1;
        double l=c-a;



        std::vector<bem2d::Point> trapping;
        trapping.push_back(bem2d::Point(0,0));
        trapping.push_back(bem2d::Point(-c,0));
        trapping.push_back(bem2d::Point(-c,-l));
        trapping.push_back(bem2d::Point(l,-l));
        trapping.push_back(bem2d::Point(l,2*c-l));
        trapping.push_back(bem2d::Point(-c,2*c-l));
        trapping.push_back(bem2d::Point(-c,2*a));
        trapping.push_back(bem2d::Point(0,2*a));
        bem2d::Polygon poly(trapping,n);
        bem2d::pGeometry pgeom=poly.GetGeometry();



        bem2d::PolBasis::AddBasis(0,pgeom);


        bem2d::Point direction=bem2d::normalize(bem2d::Point(1,0));
        bem2d::PlaneWave pw(direction,k);
        bem2d::CombinedPlaneWave cpw(direction,k);

        bem2d::SoundSoftScattering<bem2d::PlaneWave,bem2d::CombinedPlaneWave> soundsoft(pgeom,k,pw,cpw);
        soundsoft.SetQuadOption(5,5,0.15);
        soundsoft.set_polygons(pgeom);
        soundsoft.set_plotInterior();



        std::cout << "Discretizing with k=" << bem2d::complex(k.re,k.im) << " and n=" << pgeom->size() << std::endl;
        clock_t start, finish;
        double time;

        start=clock();
        soundsoft.Discretize();
        soundsoft.Solve();
        finish=clock();
        time=(double(finish)-double(start))/CLOCKS_PER_SEC;

#ifdef BEM2DMPI
        if (b->IsRoot()) {
#endif
                std::cout << "Computing time (minutes): " << time/60 << std::endl;
#ifdef BEM2DMPI
        }
#endif
        double cond;
        double norm;
        soundsoft.NormCond(norm,cond);

#ifdef BEM2DMPI
        if (b->IsRoot()) {
#endif
                std::cout << "Condition Number: " << cond << std::endl;
                std::cout << "Norm: " << norm << std::endl;
#ifdef BEM2DMPI
        }
#endif

        int xpts=200;
        int ypts=200;
        bem2d::pOutputHandler pout(new bem2d::GplotOutput(xpts,ypts,-2,3,-2,2,"trapping"));
        soundsoft.SetOutput(pout);
        soundsoft.WriteAll();



#ifdef BEM2DMPI
        bem2d::BlacsSystem::Release();
        MPI_Finalize();
#endif



        return 0;
}
Ejemplo n.º 8
0
int main(int argc, char** argv)
{

#ifdef BEM2DMPI
        MPI_Init(&argc, &argv);


        int nprow=2;
        int npcol=1;
        int mb=100;
        int nb=100;
        bem2d::BlacsSystem* b=bem2d::BlacsSystem::Initialize(nprow,npcol,mb,nb);

        if (!b) {
                std::cout <<  "Could not create Blacs context" << std::endl;
                MPI_Finalize();
                exit(1);
        }
        if ((b->get_myrow()==-1)&&(b->get_mycol()==-1)) {
                MPI_Finalize();
                exit(0);
        }



        int myrow=b->get_myrow();
        int mycol=b->get_mycol();
#endif



	bem2d::freqtype k={10,0};
	int ppw=10;
        bem2d::pCurve cobj(new bem2d::InvEllipse(0.8));
	int n=(int)(cobj->Length()*k.re*ppw/2.0/bem2d::PI);
        bem2d::AnalyticCurve invellipse(n,cobj);
        bem2d::pGeometry pgeom=invellipse.GetGeometry();

        bem2d::PolBasis::AddBasis(0,pgeom);


        bem2d::Point direction=bem2d::normalize(bem2d::Point(1,0));
        bem2d::PlaneWave pw(direction,k);
        bem2d::CombinedPlaneWave cpw(direction,k);

        bem2d::SoundSoftScattering<bem2d::PlaneWave,bem2d::CombinedPlaneWave> soundsoft(pgeom,k,pw,cpw);
        soundsoft.SetQuadOption(5,5,0.15);
        soundsoft.set_polygons(pgeom);
        soundsoft.set_plotInterior();



        std::cout << "Discretizing with k=" << bem2d::complex(k.re,k.im) << " and n=" << pgeom->size() << std::endl;
        clock_t start, finish;
        double time;

        start=clock();
        soundsoft.Discretize();
        soundsoft.Solve();
        finish=clock();
        time=(double(finish)-double(start))/CLOCKS_PER_SEC;

#ifdef BEM2DMPI
        if (b->IsRoot()) {
#endif
                std::cout << "Computing time (minutes): " << time/60 << std::endl;
#ifdef BEM2DMPI
        }
#endif
        double cond;
        double norm;
        soundsoft.NormCond(norm,cond);

#ifdef BEM2DMPI
        if (b->IsRoot()) {
#endif
                std::cout << "Condition Number: " << cond << std::endl;
                std::cout << "Norm: " << norm << std::endl;
#ifdef BEM2DMPI
        }
#endif

        int xpts=200;
        int ypts=200;
        bem2d::pOutputHandler pout(new bem2d::GplotOutput(xpts,ypts,-2,2,-2,2,"invellipse"));
        soundsoft.SetOutput(pout);
        soundsoft.WriteAll();



#ifdef BEM2DMPI
        bem2d::BlacsSystem::Release();
        MPI_Finalize();
#endif



        return 0;
}