コード例 #1
0
ファイル: popbase.hpp プロジェクト: molpopgen/fwdpp
 //! Constructor
 explicit popbase(
     const uint_t &initial_gamete_count,
     typename gamete_t::mutation_container::size_type reserve_size
     = 100)
     : // No muts in the population
       mutations(mcont_t()), mcounts(mcount_t()),
       mcounts_from_preserved_nodes(mcount_t()),
       gametes(gcont(1, gamete_t(initial_gamete_count))),
       neutral(typename gamete_t::mutation_container()),
       selected(typename gamete_t::mutation_container()),
       mut_lookup(lookup_table_type()), fixations(mvector()),
       fixation_times(ftvector())
 {
     // This is a good number for reserving,
     // allowing for extra allocations when recycling is doing its
     // thing
     gametes.reserve(2 * initial_gamete_count);
     // Reserve memory
     neutral.reserve(reserve_size);
     selected.reserve(reserve_size);
 }
コード例 #2
0
ファイル: Tri.C プロジェクト: Holygitzdq/ElVis
void Tri_setup_iprodlap()
{

	int qa = QGmax;
	int qb;

	if(LZero) // use extra points if have Legendre zeros in 'b' direction
		qb = QGmax;
	else
		qb = QGmax-1;

	int qc = 0;
	int L  = LGmax;

	// Set up dummy element with maximum quadrature/edge order

	Coord X;
	X.x = dvector(0,NTri_verts-1);
	X.y = dvector(0,NTri_verts-1);

	X.x[0] = 0.0;
	X.x[1] = 1.0;
	X.x[2] = 0.0;
	X.y[0] = 0.0;
	X.y[1] = 0.0;
	X.y[2] = 1.0;

	Tri *T = (Tri*) new Tri(0,'T', L, qa, qb, qc, &X);

	free(X.x);
	free(X.y);

	int i,j,k,n;
	int facs = Tri_DIM*Tri_DIM;
	Tri_ipmodes = T->Nmodes;
	Tri_iplap = (double***) calloc(facs,sizeof(double**));

	for(i = 0; i < facs; ++i)
	{
		Tri_iplap[i] = dmatrix(0, T->Nmodes-1, 0, T->Nmodes-1);
		dzero(T->Nmodes*T->Nmodes, Tri_iplap[i][0], 1);
	}

	// Set up gradient basis

	Basis   *B,*DB;
	Mode    *w,*m,*m1,*md,*md1,**gb,**gb1,*fac;
	double  *z;

	B      = T->getbasis();
	DB     = T->derbasis();

	fac    = B->vert;
	w      = mvector(0,0);
	gb     = (Mode **) malloc(T->Nmodes*sizeof(Mode *));
	gb[0]  = mvecset(0,Tri_DIM*T->Nmodes,qa, qb, qc);
	gb1    = (Mode **) malloc(T->Nmodes*sizeof(Mode *));
	gb1[0] = mvecset(0,Tri_DIM*T->Nmodes,qa, qb, qc);

	for(i = 1; i < T->Nmodes; ++i)
		gb[i]  = gb[i-1]+Tri_DIM;
	for(i = 1; i < T->Nmodes; ++i)
		gb1[i] = gb1[i-1]+Tri_DIM;

	getzw(qa,&z,&w[0].a,'a');
	getzw(qb,&z,&w[0].b,'b');

	/* fill gb with basis info for laplacian calculation */

	// vertex modes
	m  =  B->vert;
	md = DB->vert;
	for(i = 0,n=0; i < T->Nverts; ++i,++n)
		T->fill_gradbase(gb[n],m+i,md+i,fac);

	// edge modes
	for(i = 0; i < T->Nedges; ++i)
	{
		m1  = B ->edge[i];
		md1 = DB->edge[i];
		for(j = 0; j < T->edge[i].l; ++j,++n)
			T->fill_gradbase(gb[n],m1+j,md1+j,fac);
	}

	// face modes
	for(i = 0; i < T->Nfaces; ++i)
		for(j = 0; j < T->face[0].l; ++j)
		{
			m1  = B ->face[i][j];
			md1 = DB->face[i][j];
			for(k = 0; k < T->face[0].l-j; ++k,++n)
				T->fill_gradbase(gb[n],m1+k,md1+k,fac);
		}

	/* multiply by weights */
	for(i = 0; i < T->Nmodes; ++i)
	{
		Tri_mvmul2d(qa,qb,qc,gb[i]  ,w,gb1[i]);
		Tri_mvmul2d(qa,qb,qc,gb[i]+1,w,gb1[i]+1);
	}

	// Calculate Laplacian inner products

	double s1, s2, s3, s4, s5, s6, s7, s8;
	double *tmp = dvector(0, QGmax-1);

	fac = B->vert+1;

	for(i = 0; i < T->Nmodes; ++i)
		for(j = 0; j < T->Nmodes; ++j)
		{

			s1  = ddot(qa,gb[i][0].a,1,gb1[j][0].a,1);
			s1 *= ddot(qb,gb[i][0].b,1,gb1[j][0].b,1);

			dvmul(qa, fac->a, 1, gb[i][0].a, 1, tmp, 1);

			s2  = ddot(qa,       tmp,1,gb1[j][0].a,1);
			s2 *= ddot(qb,gb[i][0].b,1,gb1[j][0].b,1);

			s3  = ddot(qa,       tmp,1,gb1[j][1].a,1);
			s3 *= ddot(qb,gb[i][0].b,1,gb1[j][1].b,1);

			dvmul(qa, fac->a, 1, tmp, 1, tmp, 1);

			s4  = ddot(qa,       tmp,1,gb1[j][0].a,1);
			s4 *= ddot(qb,gb[i][0].b,1,gb1[j][0].b,1);

			s5  = ddot(qa,gb[i][0].a,1,gb1[j][1].a,1);
			s5 *= ddot(qb,gb[i][0].b,1,gb1[j][1].b,1);

			s6  = ddot(qa,gb[i][1].a,1,gb1[j][0].a,1);
			s6 *= ddot(qb,gb[i][1].b,1,gb1[j][0].b,1);

			dvmul(qa, fac->a, 1, gb[i][1].a, 1, tmp, 1);

			s7  = ddot(qa,       tmp,1,gb1[j][0].a,1);
			s7 *= ddot(qb,gb[i][1].b,1,gb1[j][0].b,1);

			s8  = ddot(qa,gb[i][1].a,1,gb1[j][1].a,1);
			s8 *= ddot(qb,gb[i][1].b,1,gb1[j][1].b,1);

			Tri_iplap[0][i][j] = s1;
			Tri_iplap[1][i][j] = s5 + 2*s2 + s6;
			Tri_iplap[2][i][j] = s3 + s4 + s7 + s8;
		}

	/* fill gb with basis info for mass matrix calculation */
	// vertex modes
	m  = B->vert;
	for(i = 0,n=0; i < T->Nverts; ++i,++n)
	{
		dcopy(qa, m[i].a, 1, gb[n]->a, 1);
		dcopy(qb, m[i].b, 1, gb[n]->b, 1);
	}

	// edge modes
	for(i = 0; i < T->Nedges; ++i)
	{
		m1 = B ->edge[i];
		for(j = 0; j < T->edge[i].l; ++j,++n)
		{
			dcopy(qa, m1[j].a, 1, gb[n]->a, 1);
			dcopy(qb, m1[j].b, 1, gb[n]->b, 1);
		}
	}

	// face modes
	for(i = 0; i < T->Nfaces; ++i)
		for(j = 0; j < T->face[i].l; ++j)
		{
			m1  = B ->face[i][j];
			for(k = 0; k < T->face[i].l-j; ++k,++n)
			{
				dcopy(qa, m1[k].a, 1, gb[n]->a, 1);
				dcopy(qb, m1[k].b, 1, gb[n]->b, 1);
			}
		}

	/* multiply by weights */
	for(i = 0; i < T->Nmodes; ++i)
		Tri_mvmul2d(qa,qb,qc,gb[i]  ,w,gb1[i]);

	for(i = 0; i < T->Nmodes; ++i)
		for(j = 0; j < T->Nmodes; ++j)
		{

			s1  = ddot(qa,gb[i][0].a,1,gb1[j][0].a,1);
			s1 *= ddot(qb,gb[i][0].b,1,gb1[j][0].b,1);

			Tri_iplap[3][i][j] = s1;
		}

	free_mvec(gb[0]) ;
	free((char *) gb);
	free_mvec(gb1[0]);
	free((char *) gb1);
	free((char*)w);

	free(tmp);

	delete (T);
}