int MarkOuterElements( void ) { int ext; int loops; int external=0; float *xe, *ye; float xm,ym; Elem_type *pe; Line_type *pl; ResetHashTable(HLI); while( (pl = VisitHashTableL(HLI)) != NULL ) { if( !IsLtype(pl,L_EXTERNAL_REF) && !IsLtype(pl,L_INTERNAL_REF) ) continue; MakeCoordsFromLine(pl,&xe,&ye); ResetHashTable(HEL); while( (pe=VisitHashTableE(HEL)) != NULL ) { if( IsEtype(pe, E_EXTERNAL ) ) continue; MakeCM(pe,&xm,&ym); loops = InClosedLine(pl->vertex,xe,ye,xm,ym); ext = 0; if( IsLtype(pl,L_EXTERNAL_REF) ) { if( loops == 0 ) ext = 1; } else { if( loops != 0 ) ext = 1; } if( ext ) { SetEtype(pe, E_EXTERNAL ); external++; } } free(xe); free(ye); } return external; }
void WriteFile( char *file , NodeList list , int all ) { int i,j; int count; int linetype; FILE *fp; Node_type *pn; Elem_type *pe; Line_type *pl; if( file == NULL ) { fp=fopen("new.grd","w"); } else { fp=fopen(file,"w"); } /* comments */ fprintf(fp,"\n"); fprintf(fp,"0 (mesh) automatic generated grid\n"); fprintf(fp,"\n"); /* nodes */ ResetHashTable(HNN); while( (pn=VisitHashTableN(HNN)) != NULL ) { if( !all && IsNtype(pn, N_EXTERNAL ) ) continue; fprintf(fp,"1 %d %d %f %f" ,pn->number ,(int) pn->type ,pn->coord.x ,pn->coord.y ); if( pn->depth != NULLDEPTH ) fprintf(fp," %f\n",pn->depth); else fprintf(fp,"\n"); } fprintf(fp,"\n"); /* elements */ for(i=1;i<=NTotElems;i++) { if( (pe=RetrieveByElemNumber(HEL,i)) != NULL ) { if( !all && IsEtype(pe, E_EXTERNAL ) ) continue; fprintf(fp,"2 %d %d %d" ,pe->number ,(int) pe->type ,pe->vertex ); for(j=0;j<pe->vertex;j++) { if( j%10 == 0 && pe->vertex > 3 ) fprintf(fp,"\n"); fprintf(fp," %d",pe->index[j]); } fprintf(fp,"\n"); } } fprintf(fp,"\n"); /* lines */ for(i=1;i<=NTotLines;i++) { if( (pl=RetrieveByLineNumber(HLI,i)) != NULL ) { if( IsLtype(pl,L_EXTERNAL_REF) || IsLtype(pl,L_INTERNAL_REF) || IsLtype(pl,L_FAULT_REF) || EqualsLtype(pl,L_NONE) ) { if( IsLtype(pl,L_EXTERNAL_REF) ) { linetype = L_EXTERNAL; } else if( IsLtype(pl,L_INTERNAL_REF) ) { linetype = L_INTERNAL; } else if( IsLtype(pl,L_FAULT_REF) ) { linetype = L_FAULT; } else { linetype = 0; } fprintf(fp,"3 %d %d %d" ,pl->number ,linetype ,pl->vertex ); for(j=0;j<pl->vertex;j++) { if( j%10 == 0 ) fprintf(fp,"\n"); fprintf(fp," %d",pl->index[j]); } fprintf(fp,"\n"); } } } fprintf(fp,"\n"); /* list */ if( list ) { count = list->count; fprintf(fp,"3 1 1 %d",count+1); for(j=0;j<=count;j++) { if( j%10 == 0 ) fprintf(fp,"\n"); fprintf(fp," %d",list->index[j%count]); } fprintf(fp,"\n"); } fclose(fp); }
int CheckInput( void ) /*\ * here we should also check for : * - counter-clockwise line turning * - no nodes out of external line * - internal lines are really internal of external line * - lines closed * ... \*/ { int i; int ntot=0; int next=0; int nint=0; int nbound=0; int turn; int ndim; int error; Node_type *pn; Elem_type *pe; Line_type *pl; StackTable backg; float *xe, *ye; float area; float areamax = 0.; Line_type *plmax = NULL; /* biggest line */ Line_type *plext = NULL; /* external line */ /* set all nodes to NONE */ ResetHashTable(HNN); while( (pn=VisitHashTableN(HNN)) != NULL ) { SetNtype(pn, N_NONE ); } /* look for lines */ ResetHashTable(HLI); while( (pl=VisitHashTableL(HLI)) != NULL ) { area = ABS( AreaLine(HNN,pl) ); if( area > areamax ) { areamax = area; plmax = pl; } if( pl->type == L_EXTERNAL ) { /* HACK *//* FIXME */ plext = pl; SetLtype(pl, L_EXTERNAL ); } else if( pl->type == L_INTERNAL ) { SetLtype(pl, L_INTERNAL ); } else if( pl->type == L_FAULT ) { SetLtype(pl, L_FAULT ); } else if( pl->type == L_NONE ) { if( IsLineClosed(pl) ) { SetLtype(pl, L_INTERNAL ); } else { SetLtype(pl, L_FAULT ); } } else { Error2("Unknown line type in line ",itos(pl->number)); } ntot++; if( IsLtype(pl, L_EXTERNAL ) ) next++; if( IsLtype(pl, L_INTERNAL ) ) nint++; } /* look for boundary lines */ if( next > 1 ) { Error("More than one line marked external"); } else if( ntot == 0 ) { Warning("No line found: using hull as boundary"); ResetHashTable(HNN); while( (pn=VisitHashTableN(HNN)) != NULL ) { SetNtype(pn, N_BOUNDARY ); } } else if( next == 0 ) { Warning("No external line found... using biggest one"); Warning2(" external line is ",itos(plmax->number)); plext = plmax; SetLtype(plmax, L_EXTERNAL ); next++; } /* check if external line is closed and all other lines are inside */ if( plext != NULL ) { if( ! IsLineClosed(plext) ) { Error2("External line is not closed: ",itos(plext->number)); } ResetHashTable(HLI); while( (pl=VisitHashTableL(HLI)) != NULL ) { if( pl == plext ) continue; if( ! IsLineInLine(plext,pl) ) { Error2("Line not inside external line: ",itos(pl->number)); } } } /* check lines and set node type */ error = 0; ResetHashTable(HLI); while( (pl=VisitHashTableL(HLI)) != NULL ) { if( IsLtype(pl, L_EXTERNAL ) || IsLtype(pl, L_INTERNAL ) ) { /* check for closed line */ /* FIXME */ /* -> close line */ if( ! IsLineClosed(pl) ) { Error2("Line is not closed: ",itos(pl->number)); } ndim = pl->vertex; MakeCoordsFromLine(pl,&xe,&ye); /* check for not unique coordinates */ for(i=1;i<ndim;i++) { if( pl->index[i-1] == pl->index[i] ) { printf("*** Line %d: identical node %d\n" ,pl->number,pl->index[i]); error++; } else if( xe[i-1] == xe[i] && ye[i-1] == ye[i] ) { printf("*** Line %d: Identical coordinates - ",pl->number); printf("nodes %d and %d\n",pl->index[i-1],pl->index[i]); error++; } } /* check for counter-clockwise turning */ turn = TurnClosedLine(pl->vertex,xe,ye); if( turn == 1 ) { /* ok */; } else if( turn == -1 ) { printf("Line %d in clockwise sense -> inverting\n" ,pl->number); InvertIndex(pl->index,pl->vertex); } else { printf("*** Line %d: turning number %d\n", pl->number,turn); printf(" (the line might turn on itself)\n"); error++; } free(xe); free(ye); /* set node type for nodes on boundary */ for(i=0;i<pl->vertex;i++) { pn = RetrieveByNodeNumber(HNN,pl->index[i]); SetNtype(pn, N_BOUNDARY ); } } } if( error ) { Error("Errors found in lines"); } /* look for background grid */ if( OpBackGround >= 0 ) { backg = MakeStackTable(); BCK = MakeListTable(); ResetHashTable(HEL); while( (pe=VisitHashTableE(HEL)) != NULL ) { if( pe->type == OpBackGround ) { Push(backg,(void *)pe); } else { SetEtype(pe, E_EXTERNAL ); /* tentativly... */ } } while( (pe=(Elem_type *)Pop(backg)) != NULL ) { DeleteHashByNumber(HEL,pe->number); InsertListTable(BCK,(void *)pe); for(i=0;i<3;i++) { pn = RetrieveByNodeNumber(HNN,pe->index[i]); SetNtype(pn, N_EXTERNAL ); if( pn->depth == NULLDEPTH ) { Error2("Null resolution in background grid at node : ", itos(pn->number)); } } } FreeStackTable(backg); } /* count all nodes of boundary type */ ResetHashTable(HNN); while( (pn=VisitHashTableN(HNN)) != NULL ) { if( IsNtype(pn, N_BOUNDARY ) ) nbound++; } return nbound; }