Пример #1
0
int ElementsProperties::if_pile_boundary(ti_ndx_t ndx, double contour_height)
{
    int ineigh;

    ASSERT3(state_vars_[0][ndx] >= 0.0);

    if(state_vars_[0][ndx] >= contour_height)
    {
        for(int ineigh = 0; ineigh < 8; ineigh++)
        {
            if(neigh_proc_[ineigh][ndx] >= 0)
            {
                //don't check outside map boundary or duplicate neighbor
                ASSERT3(ti_ndx_not_negative(ElemTable->lookup_ndx(ElemTable->neighbors_[ineigh][ndx])));
                if(state_vars_[0][neighbor_ndx_[ineigh][ndx]] < contour_height)
                    return 2; //inside of pileheight contour line
            }
        }
    }
    else
    {
        for(int ineigh = 0; ineigh < 8; ineigh++)
        {
            if(neigh_proc_[ineigh][ndx] >= 0)
            {
                //don't check outside map boundary or duplicate neighbor
                ASSERT3(ti_ndx_not_negative(ElemTable->lookup_ndx(ElemTable->neighbors_[ineigh][ndx])));
                ASSERT3(ElemTable->state_vars_[0][ElemTable->neighbor_ndx_[ineigh][ndx]] >= 0.0);
                if(state_vars_[0][neighbor_ndx_[ineigh][ndx]] >= contour_height)
                    return 1; //outside of pileheight contour line
            }
        }
    }
    return 0; //not on pileheight contour line
}
Пример #2
0
void ElementsProperties::calc_flux_balance(ti_ndx_t ndx)
{
    int i, j;
    double flux[3] ={ 0.0, 0.0, 0.0 };
    int xp, xm, yp, ym; //x plus, x minus, y plus, y minus
    xp = positive_x_side_[ndx];
    xm = (2 + xp) % 4;
    yp = (1 + xp) % 4;
    ym = (3 + xp) % 4;

    ti_ndx_t nd_xp, nd_xn, nd_yp, nd_yn;
    nd_xp = node_key_ndx_[xp + 4][ndx];
    nd_xn = node_key_ndx_[xm + 4][ndx];
    nd_yp = node_key_ndx_[yp + 4][ndx];
    nd_yn = node_key_ndx_[ym + 4][ndx];
    ASSERT3(ti_ndx_not_negative(nd_xp));
    ASSERT3(ti_ndx_not_negative(nd_xn));
    ASSERT3(ti_ndx_not_negative(nd_yp));
    ASSERT3(ti_ndx_not_negative(nd_yn));

    for(j = 0; j < 3; j++)
        flux[j] = dabs(node_refinementflux_[j][nd_xp] - node_refinementflux_[j][nd_xn])
                + dabs(node_refinementflux_[j][nd_yp] - node_refinementflux_[j][nd_yn]);

    double el_error=0.0;
    for(j = 0; j < 3; j++)
        el_error+=flux[j];

    el_error= 2.0 * el_error * el_error / (dx_[0][ndx] + dx_[1][ndx]) + WEIGHT_ADJUSTER; //W_A is so that elements with pile height = 0 have some weight.
    el_error_[0][ndx]=el_error;
    return;
}
Пример #3
0
int ElementsProperties::if_first_buffer_boundary(ti_ndx_t ndx, double contour_height) const
{

    int ineigh;
    int iffirstbuffer = 0;
    ti_ndx_t neig_ndx;

    if(ElemTable->adapted_[ndx] <= 0)
        return (ElemTable->adapted_[ndx] - 1);

    ASSERT3(ElemTable->state_vars_[0][ndx] >= 0.0);
    ASSERT3(ElemTable->Influx_[0][ndx] >= 0.0);

    if((ElemTable->state_vars_[0][ndx] < contour_height) && (ElemTable->Influx_[0][ndx] == 0.0))
    {
        for(ineigh = 0; ineigh < 8; ineigh++)
            if(ElemTable->neigh_proc_[ineigh][ndx]  >= 0)
            {
                //don't check outside map boundary or duplicate neighbor
                neig_ndx=ElemTable->neighbor_ndx_[ineigh][ndx];
                ASSERT3(ti_ndx_not_negative(ElemTable->lookup_ndx(ElemTable->neighbors_[ineigh][ndx])));

                if((ElemTable->state_vars_[0][neig_ndx] >= contour_height) || (ElemTable->Influx_[0][neig_ndx] > 0.0))
                {
                    iffirstbuffer = 1;
                    break;
                }
            }
    }
    else
    {
        for(ineigh = 0; ineigh < 8; ineigh++)
            if(ElemTable->neigh_proc_[ineigh][ndx] >= 0)
            {
                //don't check outside map boundary or duplicate neighbor
                neig_ndx=ElemTable->neighbor_ndx_[ineigh][ndx];
                ASSERT3(ti_ndx_not_negative(ElemTable->lookup_ndx(ElemTable->neighbors_[ineigh][ndx])));

                if((ElemTable->state_vars_[0][neig_ndx] < contour_height) && (ElemTable->Influx_[0][neig_ndx] == 0.0))
                {
                    iffirstbuffer = 1;
                    break;
                }
            }
    }

    if(iffirstbuffer)
    {
        if((ElemTable->adapted_[ndx] >= NEWSON) || (ElemTable->generation_[ndx] == REFINE_LEVEL))
            return 2; //is a member of the buffer but doesn't need to be refined
        else
            return 1; //needs to be refined and some of its sons will be members
    }

    return 0;
}
Пример #4
0
int ElementsProperties::if_source_boundary(ti_ndx_t ndx)
{
    ASSERT3(Influx_[0][ndx] >= 0.0); //currently mass sinks are not allowed

    if(Influx_[0][ndx] > 0.0)
    {
        for(int ineigh = 0; ineigh < 8; ineigh++)
            if(neigh_proc_[ineigh][ndx] >= 0)
            {
                //don't check outside map boundary or duplicate neighbor
                ASSERT3(ti_ndx_not_negative(ElemTable->lookup_ndx(ElemTable->neighbors_[ineigh][ndx])));
                if(Influx_[0][ neighbor_ndx_[ineigh][ndx] ] <= 0.0)
                    return 2; //inside of line bounding area with a mass source
            }
    }

    else if(Influx_[0][ndx] == 0.0)
    {
        for(int ineigh = 0; ineigh < 8; ineigh++)
            if(neigh_proc_[ineigh][ndx] >= 0.0)
            {
                //don't check outside map boundary or duplicate neighbor
                ASSERT3(ti_ndx_not_negative(ElemTable->lookup_ndx(ElemTable->neighbors_[ineigh][ndx])));
                ASSERT3(ElemTable->Influx_[0][ ElemTable->neighbor_ndx_[ineigh][ndx] ] >= 0.0);
                if(Influx_[0][ neighbor_ndx_[ineigh][ndx] ] != 0.0)
                    return 1; //outside of line bounding area with a mass source/sink
            }
    }
    else if(Influx_[0][ndx] < 0.0)
    {
        for(int ineigh = 0; ineigh < 8; ineigh++)
            if(neigh_proc_[ineigh][ndx] >= 0.0)
            {
                //don't check outside map boundary or duplicate neighbor
                ASSERT3(ti_ndx_not_negative(ElemTable->lookup_ndx(ElemTable->neighbors_[ineigh][ndx])));
                if(Influx_[0][ neighbor_ndx_[ineigh][ndx] ] >= 0.0)
                    return -1; //inside of line bounding area with a mass sink
            }
    }

    return 0; //not on line bounding area with mass source/sink
}
Пример #5
0
int ElementsProperties::if_next_buffer_boundary(ti_ndx_t ndx,  double contour_height)
{

    int ineigh;
    ti_ndx_t neigh_ndx;
    int ifnextbuffer = 0;

    if(adapted_[ndx] <= 0)
        //GHOST element or element that should be deleted soon
        return (adapted_[ndx] - 1);

    if((adapted_[ndx] != BUFFER) && //this element is not in the buffer
            ((Influx_[0][ndx] == 0.0)/*&&(state_vars[0]<contour_height)*/) //&& //this element is OUTSIDE the buffer layer "circle"
    //(state_vars[0]>=GEOFLOW_TINY)
    )
    {
        for(ineigh = 0; ineigh < 8; ineigh++)
        {
            if(neigh_proc_[ineigh][ndx] >= 0)
            { //don't check outside map boundary or duplicate neighbor
                ASSERT3(ti_ndx_not_negative(ElemTable->lookup_ndx(ElemTable->neighbors_[ineigh][ndx])));
                neigh_ndx=neighbor_ndx_[ineigh][ndx];

                if((abs(adapted_[neigh_ndx]) == BUFFER) && (state_vars_[0][ndx]
                        <= state_vars_[0][neigh_ndx]))
                { //this element is next to a member of the old buffer layer
                  //if((ElemNeigh->get_adapted_flag())==BUFFER){ //this element is next to a member of the old buffer layer
                    ifnextbuffer = 1; //which means this element is a member of the next outer boundary of the buffer layer
                    break;
                }
            }
        }
    }

    if(ifnextbuffer == 1)
    {
        if((adapted_[ndx] >= NEWSON) || (generation_[ndx] == REFINE_LEVEL))
            return 2; //is a member of the buffer but doesn't need to be refined
        else
            return 1; //needs to be refined and some of its sons will be members
    }

    return 0;
}
int main(int argc,char * argv[])
{

	if (argc!=3)
	{
		printf("OldUbm2NewUbm.exe oldubm newubm\n");
		exit(0);
	}
	
	GaussMixModel * m_pGmmModel;
	GMMFileHeaderOld  ModelHeaderOld;					// Header *header; 模型文件的文件头
	GMMFileHeaderNew  ModelHeaderNew;
	FILE *fpModel;
	ReadOpen(fpModel,argv[1]);

	fread(&ModelHeaderOld,sizeof(GMMFileHeaderOld),1,fpModel);
	ASSERT3(ModelHeaderOld.nDim>0, "Error in model file %s : nDim<0!",argv[1]);
	ASSERT3(ModelHeaderOld.nMixNum>0, "Error in model file %s : nMixNum<0!",argv[1]);
	ASSERT3(ModelHeaderOld.nModelNum>0, "Error in model file %s : nModelNum<0!",argv[1]);

	int m_nVecSize = ModelHeaderOld.nDim;
	int m_nVecSize4 = ALIGN_4F(m_nVecSize);
	int m_nMixNum  = ModelHeaderOld.nMixNum;		
	int m_nModelNum  = ModelHeaderOld.nModelNum;

	ASSERT3(m_nModelNum==1,"m_nModelNum=%d\n",m_nModelNum);

	m_pGmmModel = (GaussMixModel *)Malloc(m_nModelNum,sizeof(GaussMixModel),false);

	for(int i=0;i<m_nModelNum;i++)
	{
		// 分配 GMM 模型
		AllocGaussMixModel(&m_pGmmModel[i],m_nMixNum,m_nVecSize4);

		m_pGmmModel[i].nMixNum = m_nMixNum;

		// 读出weight
		fread(m_pGmmModel[i].pfWeight,sizeof(float),m_nMixNum,fpModel);

		// 读出均值,斜方差,mat
		for(int m=0;m<m_nMixNum;m++)
		{
			m_pGmmModel[i].pGauss[m].nDim = m_nVecSize;

			fread(m_pGmmModel[i].pGauss[m].pfMean,sizeof(float),m_nVecSize4,fpModel);
			fread(m_pGmmModel[i].pGauss[m].pfDiagCov,sizeof(float),m_nVecSize4,fpModel);
			fread(&m_pGmmModel[i].pGauss[m].dMat,sizeof(double),1,fpModel);
		
			// 如果mat值大于零,可能模型有问题,报警
			if (m_pGmmModel[i].pGauss[m].dMat>=0.0)
				printf("Warning : m_pGmmModel[%d].pGauss[%d].dMat=%.3f!\n",i,m,m_pGmmModel[i].pGauss[m].dMat);
		}
	}
	fclose(fpModel);


	ModelHeaderNew.nMixNum=m_nMixNum;
	ModelHeaderNew.nVecSize=m_nVecSize;
	ModelHeaderNew.nVecSizeStore=m_nVecSize4;
	ModelHeaderNew.nFeatKind=ModelHeaderOld.nMfccKind;
	ModelHeaderNew.nTotalParamSize=sizeof(float)*m_nMixNum*(m_nVecSize4*2+2);

	WriteOpen(fpModel,argv[2]);
	fwrite(&ModelHeaderNew,sizeof(GMMFileHeaderNew),1,fpModel);
	fseek(fpModel,FILE_HEADER_SIZE,SEEK_SET);
	int nNumRead;
	nNumRead=fwrite(m_pGmmModel[0].pfWeight,sizeof(float),m_nMixNum,fpModel);
	if (nNumRead!=m_nMixNum)
	{
		fclose(fpModel);	
		exit(1);
	}
	nNumRead=fwrite(m_pGmmModel[0].pfMeanBuf,sizeof(float),m_nVecSize4*m_nMixNum,fpModel);
	if (nNumRead!=m_nVecSize4*m_nMixNum)
	{
		fclose(fpModel);	
		exit(1);
	}
	nNumRead=fwrite(m_pGmmModel[0].pfDiagCovBuf,sizeof(float),m_nVecSize4*m_nMixNum,fpModel);
	if (nNumRead!=m_nVecSize4*m_nMixNum)
	{
		fclose(fpModel);	
		exit(1);
	}
	float temp;
	for (int i=0;i<m_nMixNum;i++){
		temp=float(m_pGmmModel[0].pGauss[i].dMat);
		fwrite(&temp,sizeof(float),1,fpModel);
	}
	fclose(fpModel);
	FreeGaussMixModel(m_pGmmModel,1);
	
}
Пример #7
0
void ElementsProperties::get_slopes(ti_ndx_t ndx, double gamma)
{
    int j = 0, bc = 0;
    /* check to see if this is a boundary */
    while (j < 4 && bc == 0)
    {
        if(neigh_proc_[j][ndx] == INIT)
            bc = 1;
        j++;
    }
    if(bc == 1)
    {
        for(j = 0; j < NUM_STATE_VARS * DIMENSION; j++)
            d_state_vars_[j][ndx]=0.0;
        return;
    }

    int xp, xm, yp, ym; //x plus, x minus, y plus, y minus
    xp = positive_x_side_[ndx];
    xm = (2 + xp) % 4;
    yp = (1 + xp) % 4;
    ym = (3 + xp) % 4;

    /* x direction */
    ti_ndx_t ep = neighbor_ndx_[xp][ndx]; //(Element*) (ElemTable->lookup(&neighbor(xp)[0]));
    ti_ndx_t em = neighbor_ndx_[xm][ndx]; //(Element*) (ElemTable->lookup(&neighbor(xm)[0]));
    ti_ndx_t ep2 = ti_ndx_doesnt_exist;
    ti_ndx_t em2 = ti_ndx_doesnt_exist;
    //check if element has 2 neighbors on either side
    ti_ndx_t ndtemp = node_key_ndx_[xp + 4][ndx]; //(Node*) NodeTable->lookup(&node_key[xp + 4][0]);
    if(node_info_[ndtemp] == S_C_CON)
    {
        ep2 = neighbor_ndx_[xp + 4][ndx]; //(Element*) (ElemTable->lookup(&neighbor[xp + 4][0]));
        ASSERT3(neigh_proc_[xp + 4][ndx] >= 0 && ti_ndx_not_negative(ep2));
    }
    ndtemp = node_key_ndx_[xm + 4][ndx]; //(Node*) NodeTable->lookup(&node_key[xm + 4][0]);
    if(node_info_[ndtemp] == S_C_CON)
    {
        em2 = neighbor_ndx_[xm + 4][ndx]; //(Element*) (ElemTable->lookup(&neighbor[xm + 4][0]));
        ASSERT3(neigh_proc_[xm + 4][ndx] >= 0 && ti_ndx_not_negative(em2));
    }

    double dp, dm, dc, dxp, dxm;
    dxp = coord_[0][ep] - coord_[0][ndx];
    dxm = coord_[0][ndx] - coord_[0][em];
    for(j = 0; j < NUM_STATE_VARS; j++)
    {
        dp = (state_vars_[j][ep] - state_vars_[j][ndx]) / dxp;
        if(ti_ndx_not_negative(ep2))
            dp = .5 * (dp + (state_vars_[j][ep2] - state_vars_[j][ndx]) / dxp);
        dm = (state_vars_[j][ndx] - state_vars_[j][em]) / dxm;
        if(ti_ndx_not_negative(em2))
            dm = .5 * (dm + (state_vars_[j][ndx] - state_vars_[j][em2]) / dxm);

        dc = (dp * dxm + dm * dxp) / (dxm + dxp);  // weighted average
        //do slope limiting
        d_state_vars_[j][ndx]=0.5 * (c_sgn(dp) + c_sgn(dm)) * c_dmin1(gamma * dabs(dp), gamma * dabs(dm), dabs(dc));
    }

    /* y direction */
    ep = neighbor_ndx_[yp][ndx];        //(Element*) (ElemTable->lookup(&neighbor(yp)[0]));
    em = neighbor_ndx_[ym][ndx];        //(Element*) (ElemTable->lookup(&neighbor(ym)[0]));
    ep2 = ti_ndx_doesnt_exist;
    em2 = ti_ndx_doesnt_exist;
    //check if element has 2 neighbors on either side
    ndtemp = node_key_ndx_[yp + 4][ndx];        //(Node*) NodeTable->lookup(&node_key[yp + 4][0]);
    if(node_info_[ndtemp] == S_C_CON)
    {
        ep2 = neighbor_ndx_[yp + 4][ndx];       //(Element*) (ElemTable->lookup(&neighbor[yp + 4][0]));
        ASSERT3(neigh_proc_[yp + 4][ndx] >= 0 && ti_ndx_not_negative(ep2));
    }
    ndtemp = node_key_ndx_[ym + 4][ndx];        //(Node*) NodeTable->lookup(&node_key[ym + 4][0]);
    if(node_info_[ndtemp] == S_C_CON)
    {
        em2 = neighbor_ndx_[ym + 4][ndx];       //(Element*) (ElemTable->lookup(&neighbor[ym + 4][0]));
        ASSERT3(neigh_proc_[ym + 4][ndx] >= 0 && ti_ndx_not_negative(em2));
    }

    dxp = coord_[1][ep] - coord_[1][ndx];
    dxm = coord_[1][ndx] - coord_[1][em];
    for(j = 0; j < NUM_STATE_VARS; j++)
    {
        dp = (state_vars_[j][ep] - state_vars_[j][ndx]) / dxp;
        if(ti_ndx_not_negative(ep2))
            dp = .5 * (dp + (state_vars_[j][ep2] - state_vars_[j][ndx]) / dxp);
        dm = (state_vars_[j][ndx] - state_vars_[j][em]) / dxm;
        if(ti_ndx_not_negative(em2))
            dm = .5 * (dm + (state_vars_[j][ndx] - state_vars_[j][em2]) / dxm);

        dc = (dp * dxm + dm * dxp) / (dxm + dxp);  // weighted average
        //do slope limiting
        d_state_vars_[j + NUM_STATE_VARS][ndx]=0.5 * (c_sgn(dp) + c_sgn(dm))
                                           * c_dmin1(gamma * dabs(dp), gamma * dabs(dm), dabs(dc));
    }

    return;
}