コード例 #1
0
ファイル: fcollsn3d.c プロジェクト: antdvid/FronTier
LOCAL void fabric_rigid_collision(
	Front *front,
	C_CURVE *cc)
{
	int i,j,k,num_trs,num_tfs,num_pfs;
	TRI **tr_list,**tf_list,*tri_on;
	POINT *p,**pf_list;
	double scaled_gap_tol = 0.05;
	double **newpts;
	SIDE status;
	SURFACE *sr = NULL;
	SURFACE *sf = NULL;
	double nearest_pt[MAXD],nor[MAXD];
	double hdir,*h = front->rect_grid->h;
	COMPONENT int_comp,ext_comp;
	POINT **pr_list;
	int num_prs,max_num_prs;
	int id;
	char dirname[200];

	if (debugging("collision"))
	    (void) printf("Entering fabric_rigid_collision()\n");

	for (i = 0; i < 2; ++i)
	{
	    if (wave_type(cc->s[i]) == NEUMANN_BOUNDARY ||
		wave_type(cc->s[i]) == MOVABLE_BODY_BOUNDARY)
		sr = cc->s[i];
	    if (wave_type(cc->s[i]) == ELASTIC_BOUNDARY)
		sf = cc->s[i];
	}
	if (sr == NULL)
	{
	    (void) printf("In fabric_rigid_collision(): ");
	    (void) printf("cannot find rigid body surface!\n");
	    clean_up(ERROR);
	}
	ext_comp = exterior_component(front->interf);
	int_comp = (positive_component(sr) == ext_comp) ? 
		    negative_component(sr) : positive_component(sr);

	set_tr_tf_pf_list(front,cc,&tr_list,&num_trs,&tf_list,&num_tfs,
				&pf_list,&num_pfs);

	FT_MatrixMemoryAlloc((POINTER*)&newpts,num_pfs,MAXD,sizeof(double));
	for (i = 0; i < num_pfs; ++i)
	{
	    status = nearest_point_to_tri_cluster(Coords(pf_list[i]),int_comp,
                            sr,tr_list,num_trs,&tri_on,&id,nearest_pt,nor);
	    hdir = grid_size_in_direction(nor,h,3);
	    for (k = 0; k < 3; ++k)
                newpts[i][k] = nearest_pt[k] + scaled_gap_tol*hdir*nor[k];
	}
	for (i = 0; i < num_pfs; ++i)
	{
	    for (k = 0; k < 3; ++k)
		Coords(pf_list[i])[k] = newpts[i][k];
	}
	if (debugging("collision"))
	{
	    sprintf(dirname,"cross-tris/after-lifting-%d",front->step);
	    gview_plot_crossing_tris(dirname,tr_list,num_trs,tf_list,num_tfs);
	}
	for (i = 0; i < num_pfs; ++i)
	{
	    COMPONENT comp;
	    p = pf_list[i];
	    comp = component_wrt_tri_cluster(Coords(p),sr,tr_list,
				num_trs);
	}
	num_prs = max_num_prs = 0;
	pr_list = NULL;
	for (i = 0; i < num_trs; ++i)
	{
	    double v[MAXD];
	    for (k = 0; k < 3; ++k)
	    {
		p = Point_of_tri(tr_list[i])[k];
	    	status = nearest_point_to_tri_cluster(Coords(p),int_comp,
                            sf,tf_list,num_tfs,&tri_on,&id,nearest_pt,nor);
		for (j = 0; j < 3; ++j)
		{
		    v[j] = Coords(p)[j] - nearest_pt[j];
		}
		if (Dot3d(v,nor) > 0.0)
		    check_add_pt(&pr_list,p,&num_prs,&max_num_prs);
	    }
	}
	add_to_debug("tri_cluster");
	for (i = 0; i < num_prs; ++i)
	{
	    p = pr_list[i];
	    status = nearest_point_to_tri_cluster(Coords(p),int_comp,
                            sf,tf_list,num_tfs,&tri_on,&id,nearest_pt,nor);
	    if (status == ONEDGE)
		printf("ie = %d\n",id);
	    else
		printf("\n");
	}
	remove_from_debug("tri_cluster");
	if (debugging("collision"))
	{
	    sprintf(dirname,"cross-tris/before-leaving-%d",front->step);
	    gview_plot_crossing_tris(dirname,tr_list,num_trs,tf_list,num_tfs);
	}
	free_these(4,tr_list,tf_list,pf_list,newpts);
}	/* end fabric_rigid_collision */
コード例 #2
0
ファイル: tripcs.c プロジェクト: irisvogon/fulldomain
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*/