Ejemplo n.º 1
0
void DUAL_ELLIPTIC_SOLVER::set_solver_domain(void)
{
	static boolean first = YES;
	RECT_GRID *rgr = &topological_grid(front->grid_intfc);
	RECT_GRID *crgr = &topological_grid(front->comp_grid_intfc);
	struct Table *T = table_of_interface(front->grid_intfc);
        struct Table *cT = table_of_interface(front->comp_grid_intfc);
        int *lbuf = front->rect_grid->lbuf;
        int *ubuf = front->rect_grid->ubuf;
	int i;

	dim = Dimension(front->interf);
	top_comp = T->components;
	top_gmax = rgr->gmax;
        top_h = rgr->h;
        ctop_comp = cT->components;
        ctop_gmax = crgr->gmax;
	ctop_L = crgr->L;

	if (first)
	{
	    first = NO;
	    cimin = (lbuf[0] == 0) ? 1 : lbuf[0] + 1;
	    cjmin = (lbuf[1] == 0) ? 1 : lbuf[1] + 1;
	    ckmin = (lbuf[2] == 0) ? 1 : lbuf[2] + 1;
	    cimax = (ubuf[0] == 0) ? ctop_gmax[0] - 1 : ctop_gmax[0] - ubuf[0];
            cjmax = (ubuf[1] == 0) ? ctop_gmax[1] - 1 : ctop_gmax[1] - ubuf[1];
            ckmax = (ubuf[2] == 0) ? ctop_gmax[2] - 1 : ctop_gmax[2] - ubuf[2];
	    array_size = 1;
	    for (i = 0; i < dim; ++i)
	    {
		array_size *= (ctop_gmax[i] + 1);
		offset[i] = (lbuf[i] == 0) ? 1 : 0;
	    }
	    FT_VectorMemoryAlloc((POINTER*)&array,array_size,FLOAT);
	}
}	/* end set_solver_domain */
Ejemplo n.º 2
0
EXPORT bool make_point_comp_lists(
	INTERFACE	*intfc)
{
	int		ix, ix0, ix1;
	int		zp;
	POINT		**p;
	struct Table	*T;
	COMPONENT	icomp;
        RECT_GRID       *grid;

	if (DEBUG)
	    (void) printf("Entered make_point_comp_lists()\n");

	if ((T = table_of_interface(intfc)) == NULL) 
	{
	    (void) printf("WARNING in make_point_comp_lists(), "
	                  "table_of_interface = NULL\n");
	    return FUNCTION_FAILED;
	}

	if (no_topology_lists(intfc) == YES)
	{
	    screen("ERROR in make_point_comp_lists(), "
		   "illegal attempt to construct interface topology\n"
		   "no_topology_lists(intfc) == YES\n");
	    clean_up(ERROR);
	}

	grid = &T->rect_grid;

			/* Free old storage if necessary */

	if (T->num_of_points != NULL)
	    free(T->num_of_points);
	if (T->pts_in_zone != NULL)
	    free(T->pts_in_zone);
	if (T->compon1d != NULL)
	    free(T->compon1d);

			/* Create a Grid if Needed: */

	if (!T->fixed_grid)
	    set_topological_grid(intfc,(RECT_GRID *)NULL);


			/* Allocate new storage if necessary */

	uni_array(&T->num_of_points,grid->gmax[0],INT);
	if (T->num_of_points == NULL)
	{
	    (void) printf("WARNING in make_point_complist(), "
	                  "can't allocate T->num_of_points\n");
	    return FUNCTION_FAILED;
	}
	if (DEBUG)
	    (void) printf("T->num_of_points allocated\n");

	/* NOTE: vector returns integer values initalized to zero */
	uni_array(&T->compon1d,grid->gmax[0],sizeof(COMPONENT));
	if (T->compon1d == NULL)
	{
	    (void) printf("WARNING in make_point_complist(), "
	                  "can't allocate T->compon1d\n");
	    return FUNCTION_FAILED;
	}
	if (DEBUG)
	    (void) printf("T->compon1d allocated\n");

	for (ix = 0; ix < grid->gmax[0]; ++ix)
	    T->compon1d[ix] = NO_COMP;
	uni_array(&T->pts_in_zone,grid->gmax[0],sizeof(POINT **));
	/* NOTE: vector returns pointer values initalized to NULL */
	if (T->pts_in_zone == NULL)
	{
	    (void) printf("WARNING in make_point_complist(), "
	                  "can't allocate T->pts_in_zone\n");
	    return FUNCTION_FAILED;
	}

	start_clock("make_point_comp_lists");
	if ((intfc->modified)  && (intfc->num_points > 0))
	    sort_point_list(intfc->points,intfc->num_points);

		/* Default setting */
	ix0 = 0;
	if (intfc->num_points != 0)
	{
	    p = intfc->points;
	    icomp = negative_component(*p);
	    ix1 = -1;
	    for (p = intfc->points; p && *p; ++p)
	    {
	    	if (rect_in_which(Coords(*p),&zp,&T->rect_grid) ==
							FUNCTION_FAILED)
	    	    continue;
	    	++T->num_of_points[zp];
	    	if ((p == intfc->points) || (zp != ix1))
	    	{
	    	    T->pts_in_zone[zp] = p;
	    	}

	    	T->compon1d[zp] = ONFRONT;
	    	ix1 = zp;
	    	for (ix = ix0; ix < ix1; ++ix)
	    	    T->compon1d[ix] = icomp;
	    	icomp = positive_component(*p);
	    	ix0 = zp + 1;
	    }
	    for (ix = ix0; ix < grid->gmax[0]; ++ix)
	    	T->compon1d[ix] = icomp;
	}
	stop_clock("make_point_comp_lists");

	intfc->modified = NO;
	intfc->table->new_grid = NO;

	if (DEBUG) (void) printf("Leaving make_point_comp_lists()\n\n");
	return FUNCTION_SUCCEEDED;
}		/*end make_point_comp_lists*/
Ejemplo n.º 3
0
LOCAL void collect_cell_ptst(
	INTRP_CELL *blk_cell,
	int *icoords,
	COMPONENT comp,
	Front *front,
	float *grid_array,
	float (*get_state)(Locstate))
{
	INTERFACE *grid_intfc = front->grid_intfc;
	Table *T = table_of_interface(grid_intfc);
	RECT_GRID *gr = &topological_grid(grid_intfc);
	int dim = gr->dim;
	int *gmax = gr->gmax;
	float *L = gr->L;
	float *h = gr->h;
	COMPONENT *gr_comp = T->components;
	static COMPONENT cell_comp1d[2];
	static COMPONENT cell_comp2d[2][2];
	static COMPONENT cell_comp3d[2][2][2];
	int i,j,k,index,nv,nc;
	CRXING *crx,*crxs[MAX_NUM_CRX];
	GRID_DIRECTION dir;
	int ic[MAXD];
	bool fr_crx_grid_seg;
	float state_at_crx;
	float crx_coords[MAXD];
	
	blk_cell->is_bilinear = YES;
	blk_cell->dim = dim;
	nv = 0;
	switch (dim)
	{
	case 1:
	    for (i = 0; i < 2; ++i)
	    {
	    	ic[0] = icoords[0] + i;
	    	index = d_index1d(ic[0],gmax);
	    	cell_comp1d[i] = gr_comp[index];
	    	if (gr_comp[index] == comp)
	    	{
	    	    blk_cell->coords[nv][0] = L[0] + ic[0]*h[0];
		    blk_cell->var[nv] = grid_array[index];
		    nv++;
	    	}
	    	else
	    	    blk_cell->is_bilinear = NO;
	    }
	    break;
	case 2:
	    for (i = 0; i < 2; ++i)
	    for (j = 0; j < 2; ++j)
	    {
	    	ic[0] = icoords[0] + i;
	    	ic[1] = icoords[1] + j;
	    	index = d_index2d(ic[0],ic[1],gmax);
	    	cell_comp2d[i][j] = gr_comp[index];
	    	if (gr_comp[index] == comp)
	    	{
	    	    blk_cell->coords[nv][0] = L[0] + ic[0]*h[0];
	    	    blk_cell->coords[nv][1] = L[1] + ic[1]*h[1];
		    blk_cell->var[nv] = grid_array[index];
		    nv++;
	    	}
	    	else
	    	    blk_cell->is_bilinear = NO;
	    }
	    break;
	case 3:
	    for (i = 0; i < 2; ++i)
	    for (j = 0; j < 2; ++j)
	    for (k = 0; k < 2; ++k)
	    {
	    	ic[0] = icoords[0] + i;
	    	ic[1] = icoords[1] + j;
	    	ic[2] = icoords[2] + k;
	    	index = d_index3d(ic[0],ic[1],ic[2],gmax);
	    	cell_comp3d[i][j][k] = gr_comp[index];
	    	if (gr_comp[index] == comp)
	    	{
	    	    blk_cell->coords[nv][0] = L[0] + ic[0]*h[0];
	    	    blk_cell->coords[nv][1] = L[1] + ic[1]*h[1];
	    	    blk_cell->coords[nv][2] = L[2] + ic[2]*h[2];
		    blk_cell->var[nv] = grid_array[index];
		    nv++;
	    	}
	    	else
	    	    blk_cell->is_bilinear = NO;
	    }
	    break;
	}
	if (blk_cell->is_bilinear == YES) 
	{
	    blk_cell->nv = nv;
	    return;
	}
	switch (dim)
	{
	case 1:
	    for (i = 0; i < 2; ++i)
	    {
	    	ic[0] = icoords[0] + i;
	    	if (cell_comp1d[i] == comp)
		{
	    	    if (cell_comp1d[(i+1)%2] != comp)
		    {
		    	dir = (i < (i+1)%2) ? EAST : WEST;
			fr_crx_grid_seg = FrontStateAtGridCrossing(front,ic,dir,
				comp,get_state,&state_at_crx,crx_coords);
		    	if (!fr_crx_grid_seg)
		    	{
		    	    screen("ERROR: no crxing between (%d) and (%d)\n",
			    		icoords[0]+i,icoords[0]+(i+1)%2);
		    	}
		    	blk_cell->var[nv] = state_at_crx;
		    	blk_cell->coords[nv][0] = crx_coords[0];
		    	nv++;
		    }
		}
	    }
	    break;
	case 2:
	    for (i = 0; i < 2; ++i)
	    for (j = 0; j < 2; ++j)
	    {
	    	ic[0] = icoords[0] + i;
	    	ic[1] = icoords[1] + j;
	    	if (cell_comp2d[i][j] == comp)
	    	{
	    	    if (cell_comp2d[(i+1)%2][j] != comp)
	    	    {
		    	dir = (i < (i+1)%2) ? EAST : WEST;
			fr_crx_grid_seg = FrontStateAtGridCrossing(front,ic,dir,
				comp,get_state,&state_at_crx,crx_coords);
		    	if (!fr_crx_grid_seg)
		    	{
		    	    screen("ERROR: no crxing between (%d %d) "
			           "and (%d %d)\n",icoords[0]+i,icoords[1]+j,
					icoords[0]+(i+1)%2,icoords[1]+j);
		    	}
		    	blk_cell->var[nv] = state_at_crx;
		    	blk_cell->coords[nv][0] = crx_coords[0];
		    	blk_cell->coords[nv][1] = crx_coords[1];
		    	nv++;
	    	    }
	    	    if (cell_comp2d[i][(j+1)%2] != comp)
	    	    {
		    	dir = (j < (j+1)%2) ? NORTH : SOUTH;
			fr_crx_grid_seg = FrontStateAtGridCrossing(front,ic,dir,
				comp,get_state,&state_at_crx,crx_coords);
		    	if (!fr_crx_grid_seg)
		    	{
		    	    screen("ERROR: no crxing between (%d %d) "
			           "and (%d %d)\n",icoords[0]+i,icoords[1]+j,
					icoords[0]+i,icoords[1]+(j+1)%2);
		    	}
		    	blk_cell->var[nv] = state_at_crx;
		    	blk_cell->coords[nv][0] = crx_coords[0];
		    	blk_cell->coords[nv][1] = crx_coords[1];
		    	nv++;
	    	    }
	    	}
	    }
	    break;
	case 3:
	    for (i = 0; i < 2; ++i)
	    for (j = 0; j < 2; ++j)
	    for (k = 0; k < 2; ++k)
	    {
	    	ic[0] = icoords[0] + i;
	    	ic[1] = icoords[1] + j;
	    	ic[2] = icoords[2] + k;
	    	if (cell_comp3d[i][j][k] == comp)
	    	{
	    	    if (cell_comp3d[(i+1)%2][j][k] != comp)
	    	    {
		    	dir = (i < (i+1)%2) ? EAST : WEST;
			fr_crx_grid_seg = FrontStateAtGridCrossing(front,ic,dir,
				comp,get_state,&state_at_crx,crx_coords);
		    	if (!fr_crx_grid_seg)
		    	{
		    	    screen("ERROR: no crxing between (%d %d %d) "
			           "and (%d %d %d)\n",icoords[0]+i,icoords[1]+j,
				   icoords[2]+k,icoords[0]+(i+1)%2,icoords[1]+j,
				   icoords[2]+k);
		    	}
		    	blk_cell->var[nv] = state_at_crx;
		    	blk_cell->coords[nv][0] = crx_coords[0];
		    	blk_cell->coords[nv][1] = crx_coords[1];
		    	blk_cell->coords[nv][2] = crx_coords[2];
		    	nv++;
	    	    }
	    	    if (cell_comp3d[i][(j+1)%2][k] != comp)
	    	    {
		    	dir = (j < (j+1)%2) ? NORTH : SOUTH;
			fr_crx_grid_seg = FrontStateAtGridCrossing(front,ic,dir,
				comp,get_state,&state_at_crx,crx_coords);
		    	if (!fr_crx_grid_seg)
		    	{
		    	    screen("ERROR: no crxing between (%d %d %d) "
			           "and (%d %d %d)\n",icoords[0]+i,icoords[1]+j,
				   icoords[2]+k,icoords[0]+i,icoords[1]+(j+1)%2,
				   icoords[2]+k);
		    	}
		    	blk_cell->var[nv] = state_at_crx;
		    	blk_cell->coords[nv][0] = crx_coords[0];
		    	blk_cell->coords[nv][1] = crx_coords[1];
		    	blk_cell->coords[nv][2] = crx_coords[2];
		    	nv++;
	    	    }
	    	    if (cell_comp3d[i][j][(k+1)%2] != comp)
	    	    {
		    	dir = (k < (k+1)%2) ? UPPER : LOWER;
			fr_crx_grid_seg = FrontStateAtGridCrossing(front,ic,dir,
				comp,get_state,&state_at_crx,crx_coords);
		    	if (!fr_crx_grid_seg)
		    	{
		    	    screen("ERROR: no crxing between (%d %d %d) "
			           "and (%d %d %d)\n",icoords[0]+i,icoords[1]+j,
				   icoords[2]+k,icoords[0]+i,icoords[1]+j,
				   icoords[2]+(k+1)%2);
		    	}
		    	blk_cell->var[nv] = state_at_crx;
		    	blk_cell->coords[nv][0] = crx_coords[0];
		    	blk_cell->coords[nv][1] = crx_coords[1];
		    	blk_cell->coords[nv][2] = crx_coords[2];
		    	nv++;
	    	    }
	    	}
	    }
	    break;
	}
	blk_cell->nv = nv;
}	/* end collect_cell_ptst */
Ejemplo n.º 4
0
EXPORT	int collect_pcs_in_mesh3d(TRI_GRID *ntg)
{
	struct Table	*T;
	P_LINK		*hash_table;
	Locstate	 *states;
	COMPONENT	 *comp;
	TG_PT		 *node_pts;
	BLK_EL0		*blk_el0;
	TRI		**tris;
	SURFACE		**surfs;
	POINT_COMP_ST	*pcs;
	int		ix, iy, iz, l, nt, ***num_tris;;
	int		*offset = ntg->offset;
	int		num_pcs = 0;
	int		h_size;
	int		xmax, ymax, zmax;

        xmax = ntg->rect_grid.gmax[0];
       	ymax = ntg->rect_grid.gmax[1];
       	zmax = ntg->rect_grid.gmax[2];

	ntg->_locate_on_trigrid = tg_build;
	set_tri3d_tolerances(ntg);

	T = table_of_interface(ntg->grid_intfc);

	//orig_construct_tri_grid
	//reconstruct_intfc_and_tri_grid
	//    init_triangulation_storage
	//        components, states
	//        set_crx_structure_storage3dv0
	//            ntg->n_bilin_els = xmax*ymax*zmax;    //expanded_topological_grid
	//	      ntg->n_node_points = (xmax+1)*(ymax+1)*(zmax+1);
	//	      
	//	      alloc_node_points(ntg,ntg->n_node_points);
	//	          node_points
	//	      alloc_blk_els0(ntg,ntg->n_bilin_els);
	//	          blk_els0
	//    set_interpolation_storage3dv0
	//        count_num_pcs3d
	//        n_pcs, pcs, front_points
	
		/* Allocate space for hashing table */

	h_size = (ntg->grid_intfc->num_points)*4+1; 
	uni_array(&hash_table,h_size,sizeof(P_LINK)); 

	copy_tg_pts_from_intfc(ntg,hash_table,h_size);
	//front_points
	copy_tg_pts_from_regular_grid(ntg);
	//node_points

		/* Triangulate each mesh block */

	comp = T->components;
	states = ntg->states;
	node_pts = ntg->node_points;
	blk_el0 = ntg->blk_els0;
	num_tris = T->num_of_tris;
	for (iz = 0; iz < zmax; ++iz)
	{
	    for (iy = 0; iy < ymax; ++iy)
	    {
		for (ix = 0; ix < xmax; ++ix)
		{
		    //debug with tg_build  line_pj
		    remove_from_debug("pcs_cell");
		    //if((ix == 3  && iy == 5 && iz == 0 && pp_mynode() == 0) || 
		    //     (ix == 33 && iy == 5 && iz == 0 && pp_mynode() == 2) )
		    //    add_to_debug("pcs_cell");
		    
		    nt = num_tris[iz][iy][ix];
		    pcs = blk_el0_pcs_els(blk_el0) = &(ntg->pcs[num_pcs]);
		    if (nt != 0)
		    {
			tris  = T->tris[iz][iy][ix];
			surfs = T->surfaces[iz][iy][ix];
			
			if(debugging("pcs_cell"))
			{
			    int nd;
			    printf("#pcs_cell  %d\n", nt);

			    for(nd = 0; nd < nt; nd++)
			    {
			        print_tri(tris[nd], surfs[nd]->interface);
				printf("%d  (%d %d)\n", surfs[nd], 
						negative_component(surfs[nd]), 
						positive_component(surfs[nd]));
			    }
			}
		    	for (l = 0; l < 8; ++l)
		    	{
			    pcs[l].p = node_pts + offset[l];
			    pcs[l].comp[0] = comp[offset[l]];
			    pcs[l].s[0] = states[offset[l]];
			    pcs[l].comp[1] = NO_COMP;
			    pcs[l].s[1] = NULL;
		    	}
		        num_pcs_els_in_blk(blk_el0) = 8;
		    	add_intfc_blk_pcs3d(nt,tris,surfs,blk_el0,
				hash_table,h_size);
		        num_pcs += num_pcs_els_in_blk(blk_el0);
		    }
		    else
		    {
		        set_bilinear_blk_el0(blk_el0);
			pcs[0].p = node_pts;
			pcs[0].comp[0] = comp[0];
			pcs[0].s[0] = states[0];
			pcs[0].comp[1] = NO_COMP;
			pcs[0].s[1] = NULL;
			++num_pcs;
		    }
		    ++node_pts;
		    ++states;
		    ++comp;
		    ++blk_el0;
		}
		++node_pts;
		++states;
		++comp;
	    }
	    if (iz < zmax-1)
	    {   //node_pts, states, comp are defined on the nodes of the topological grid.
		node_pts += xmax+1;
		states += xmax+1;
		comp += xmax+1;
	    }
	}

	//printf("#collect_pcs_in_mesh3d af: num_pcs = %d  ntg->n_pcs=%d\n", 
	//		num_pcs, ntg->n_pcs);
	if(num_pcs != ntg->n_pcs)
	{
	    printf("ERROR: num_pcs != ntg->n_pcs\n");
	    clean_up(ERROR);
	}
	
	free(hash_table);
	return GOOD_STEP;
}		/*end collect_pcs_in_mesh3d*/
Ejemplo n.º 5
0
LOCAL int count_num_pcs2d(TRI_GRID *ntg)
{
        int	xmax;
        int	ymax;
	int	ix, iy, l;
        int	nbyx;
	BOND    *b;
        BOND    **byx;
        struct Table *T;
	int	n_pcs = 0;

#if defined(DEBUG_TRI_GRID)
	debug_print("count_num_pcs2d", "Entered count_num_pcs2d");
#endif /* defined(DEBUG_TRI_GRID) */


	T = table_of_interface(ntg->grid_intfc);

        xmax = ntg->rect_grid.gmax[0];
        ymax = ntg->rect_grid.gmax[1];

	for (iy = 0; iy < ymax;++iy)
	{
	    for (ix = 0; ix < xmax;++ix)
	    {
		nbyx = T->num_of_bonds[iy][ix];
		byx  = T->bonds[iy][ix];
		if (nbyx == 0)
		{
		    n_pcs += 1;
#if defined(DEBUG_TRI_GRID)
	            if (debugging("count_num_pcs2d"))
	            {
	                (void) printf("n_pcs (%d, %d) = 1\n", ix, iy);
	            }
#endif /* defined(DEBUG_TRI_GRID) */

		}
		else
		{
		    n_pcs += 4;
		    for (l=0; l < nbyx;++l)
		    {
			b = byx[l];
			sorted(b->start) = NO;
			sorted(b->end) = NO;
		    }
		    for (l=0; l < nbyx;++l)
		    {
			b = byx[l];
			if (sorted(b->start) == NO)
			{
			    sorted(b->start) = YES;
			    n_pcs += 1;
			}

			if (sorted(b->end) == NO)
			{
			    sorted(b->end) = YES;
			    n_pcs += 1;
			}

		    }
#if defined(DEBUG_TRI_GRID)
	            if (debugging("count_num_pcs2d"))
	            {
	                (void) printf("n_pcs (%d, %d) = %d\n", ix, iy, n_pcs);
	            }
#endif /* defined(DEBUG_TRI_GRID) */

		    
		}
	    }
	}

#if defined(DEBUG_TRI_GRID)
	debug_print("count_num_pcs2d", "Finished count_num_pcs2d");
#endif /* defined(DEBUG_TRI_GRID) */
      
	return n_pcs;
	    
}    /* end count_num_pcs2d */
Ejemplo n.º 6
0
EXPORT	int collect_pcs_in_mesh2d(TRI_GRID *ntg)
{
        int		xmax;
        int		ymax;
        struct Table	*T;
        P_LINK		*hash_table;
        Locstate	*states;
        COMPONENT	*comp;
        TG_PT		*node_pts;
        BLK_EL0		*blk_el0;
        BOND    	****by;
        BOND    	***byx;
        CURVE   	****cy,***cyx;
        POINT_COMP_ST	*pcs;
	int		ix, iy, l;
        int		**nby, *nbyx; 
	int		*offset = ntg->offset;
	int		num_pcs = 0;
	int		h_size;
	
#if defined(DEBUG_TRI_GRID)
	debug_print("collect_pcs_in_mesh2d", "make_bond_comp_list");
#endif /* defined(DEBUG_TRI_GRID) */

	set_dual_interface_topology(ntg);
	ntg->_locate_on_trigrid = tg_build;

#if defined(DEBUG_TRI_GRID)
	debug_print("collect_pcs_in_mesh2d", "to count_num_pcs2d");
#endif /* defined(DEBUG_TRI_GRID) */

	ntg->n_pcs = count_num_pcs2d(ntg);
	VECTOR(ntg,pcs,ntg->n_pcs,sizeof(POINT_COMP_ST));


	T = table_of_interface(ntg->grid_intfc);


        xmax = ntg->rect_grid.gmax[0];
       	ymax = ntg->rect_grid.gmax[1];


		/* Allocate space for hashing table */

	/*P_LINK (int.h) pair of left and right states */

	h_size = (ntg->grid_intfc->num_points)*4+1; 
	uni_array(&hash_table,h_size,sizeof(P_LINK)); 

#if defined(DEBUG_TRI_GRID)
	debug_print("collect_pcs_in_mesh2d", "to copy_tg_pts_from_intfc");
#endif /* defined(DEBUG_TRI_GRID) */

	copy_tg_pts_from_intfc(ntg,hash_table,h_size);

		/* set the pcs's */

	comp = T->components;
	states = ntg->states;
	node_pts = ntg->node_points;
	blk_el0 = ntg->blk_els0;

#if defined(DEBUG_TRI_GRID)
	debug_print("collect_pcs_in_mesh2d", "to set the pcs's");
#endif /* defined(DEBUG_TRI_GRID) */

	for (iy = 0, nby = T->num_of_bonds, by  = T->bonds, cy  = T->curves;
	     iy < ymax; ++iy, ++nby, ++by, ++cy)
	{
	    for (ix = 0, nbyx = *nby, byx = *by, cyx = *cy;
		 ix < xmax; 
		 ++ix, ++nbyx, ++byx, ++cyx)
	    {
		pcs = blk_el0_pcs_els(blk_el0) = &(ntg->pcs[num_pcs]);
		if (*nbyx != 0)
		{
		    for (l = 0; l < 4; ++l)
		    {
			pcs[l].p = node_pts + offset[l];
			pcs[l].comp[0] = comp[offset[l]];
			pcs[l].s[0] = states[offset[l]];
			pcs[l].comp[1] = NO_COMP;
			pcs[l].s[1] = NULL;
		    }
		    num_pcs_els_in_blk(blk_el0) = 4;

		    add_intfc_blk_pcs2d(*nbyx,*byx,*cyx,blk_el0,
				hash_table,h_size);
		    num_pcs += num_pcs_els_in_blk(blk_el0);
		}
		else
		{
		    set_bilinear_blk_el0(blk_el0);
		    pcs[0].p = node_pts;
		    pcs[0].comp[0] = comp[0];
		    pcs[0].s[0] = states[0];
		    pcs[0].comp[1] = NO_COMP;
		    pcs[0].s[1] = NULL;
		    ++num_pcs;
		}
		++node_pts;
		++states;
		++comp;
		++blk_el0;
	    }
	    ++node_pts;
	    ++states;
	    ++comp;
	    
	    /*
	    if (iy < ymax -1)
	    {
		  node_pts += xmax+1;
		  states += xmax+1;
		  comp += xmax+1;
	    }
	    */
	}

	free(hash_table);
#if defined(DEBUG_TRI_GRID)
	if (debugging("collect_pcs_in_mesh2d"))
	{
	    int i;
	    int icoords[MAXD];
	    float *coords;

	    (void) printf("\t\t PRINTING PCS:\n");

	    for (i=0;i<ntg->n_pcs ;++i)
	    {   
		coords = (float*)(ntg->pcs[i].p);
		if (rect_in_which(coords,icoords,&(ntg->rect_grid)))
		{
		    (void) printf("%d: icoords[%d,%d] ",
				  i,icoords[0],icoords[1]);
		    (void) printf("comp[0] = %d, comp[1] = %d \n",
				  ntg->pcs[i].comp[0],ntg->pcs[i].comp[1]);
		}
		else
		{
		    (void) printf("rect_in_which failed for this pcs\n");
		    (void) printf("%d: comp[0] = %d, comp[1] = %d \n",
				  i,ntg->pcs[i].comp[0],ntg->pcs[i].comp[1]);
		}
		(void) printf("(%g,%g)\n", coords[0],coords[1]);
	    }
	    (void) printf("\t\n\n PRINTING BLK_EL0:\n");
	    for (icoords[0] = 0; icoords[0] < ntg->rect_grid.gmax[0];
		++icoords[0])
	    {
		for (icoords[1] = 0; icoords[1] < ntg->rect_grid.gmax[1];
		     ++icoords[1])
		{
		    blk_el0 = &Blk_el0(icoords,ntg);
		    (void) printf("blk_el0[%d,%d] = %llu\n",
				  icoords[0],icoords[1],
				  ptr2ull(blk_el0));
		    (void) printf("num_pcs_els_in_blk = %d\n",
				  num_pcs_els_in_blk(blk_el0));
		    for (i = 0; i < num_pcs_els_in_blk(blk_el0); ++i)
		    {
			(void) printf("%d: (%g, %g)\n",i,
				      Coords(blk_el0_pcs_els(blk_el0)[i].p)[0],
				      Coords(blk_el0_pcs_els(blk_el0)[i].p)[1]);
		    }
		}
	    }
	    
	}
	if (debugging("tri_grid"))
	{
	       (void) printf("Grid interface AFTER collect_pcs_in_mesh2d()\n");
	       print_interface(ntg->grid_intfc);
	}
#endif /* defined(DEBUG_TRI_GRID) */
	return GOOD_STEP;
	    
}		/*end collect_pcs_in_mesh2d*/