Skip to content

Commit

Permalink
Fix Triangle input
Browse files Browse the repository at this point in the history
  • Loading branch information
raback committed Mar 13, 2023
1 parent 0d617f5 commit 92170b6
Showing 1 changed file with 48 additions and 50 deletions.
98 changes: 48 additions & 50 deletions elmergrid/src/egconvert.c
Expand Up @@ -2651,8 +2651,8 @@ int LoadTriangleInput(struct FemType *data,struct BoundaryType *bound,
*/
{
int noknots,noelements,maxnodes,elematts,nodeatts,dim;
int elementtype,bcmarkers,sideelemtype,offset;
int i,j,k,jmin,jmax,kmin,kmax,*boundnodes;
int elementtype,bcmarkers,sideelemtype,offset,bcinds;
int i,ii,j,k,jmin,jmax,kmin,kmax,*boundnodes;
FILE *in;
char *cp,line[MAXLINESIZE],elemfile[MAXFILESIZE],nodefile[MAXFILESIZE],
polyfile[MAXLINESIZE];
Expand Down Expand Up @@ -2697,7 +2697,8 @@ int LoadTriangleInput(struct FemType *data,struct BoundaryType *bound,
data->noelements = noelements;
data->noknots = noknots;
elementtype = 300 + maxnodes;

bcinds = FALSE;

if(info) printf("Allocating for %d knots and %d elements.\n",noknots,noelements);
AllocateKnots(data);

Expand Down Expand Up @@ -2776,7 +2777,7 @@ int LoadTriangleInput(struct FemType *data,struct BoundaryType *bound,
}


sprintf(polyfile,"%s.poly",prefix);
sprintf(polyfile,"%s.edge",prefix);
if ((in = fopen(polyfile,"r")) == NULL) {
printf("LoadTriangleInput: The opening of the poly file %s failed!\n",polyfile);
return(1);
Expand All @@ -2792,54 +2793,42 @@ int LoadTriangleInput(struct FemType *data,struct BoundaryType *bound,
elemsides = 3;
hit = FALSE;

GETLINE;
GETLINE;
sscanf(line,"%d %d",&bcelems,&markers);

if(bcelems == 0) goto finish;

if(info) printf("Allocating for %d boundary elements.\n",bcelems);

CreateInverseTopology(data,info);
invrow = data->invtopo.rows;
invcol = data->invtopo.cols;

AllocateBoundary(bound,bcelems);

jmin = noknots;
jmax = 0;
for(i=1;i<=bcelems;i++) {


i = 0;
for(ii=1;ii<=bcelems;ii++) {
GETLINE;
if(markers)
sscanf(line,"%d %d %d %d",&j,&ind1,&ind2,&bctype);
else
sscanf(line,"%d %d %d",&j,&ind1,&ind2);

if(!bctype) continue;
i += 1;

bctype = abs(bctype);

ind1 += offset;
ind2 += offset;

jmin = MIN(jmin,MIN(ind1,ind2));
jmax = MAX(jmax,MAX(ind1,ind2));

/* find an element which owns both the nodes */
#if 0
for(j=1;j<=data->maxinvtopo;j++) {
hit = FALSE;
k = data->invtopo[j][ind1];
if(!k) break;

for(j2=1;j2<=data->maxinvtopo;j2++) {
k2 = data->invtopo[j2][ind2];
if(!k2) break;
if(k == k2) {
hit = TRUE;
elemind = k;
break;
}
}
if(hit) break;
}
#else
for(j=invrow[ind1-1];j<invrow[ind1];j++) {
k = invcol[j]+1;
hit = FALSE;
Expand All @@ -2854,39 +2843,48 @@ int LoadTriangleInput(struct FemType *data,struct BoundaryType *bound,
}
if(hit) break;
}
#endif


if(!hit) return(1);



/* Find the correct side of the triangular element */
k = 0;
for(side=0;side<elemsides;side++) {
GetElementSide(elemind,side,1,data,&sideind[0],&sideelemtype);
if(hit) {
k = 0;
for(side=0;side<elemsides;side++) {
GetElementSide(elemind,side,1,data,&sideind[0],&sideelemtype);

hit = FALSE;
if(sideind[0] == ind1 && sideind[1] == ind2) hit = TRUE;
if(sideind[0] == ind2 && sideind[1] == ind1) hit = TRUE;

if(hit) break;
}
}

hit = FALSE;
if(sideind[0] == ind1 && sideind[1] == ind2) hit = TRUE;
if(sideind[0] == ind2 && sideind[1] == ind1) hit = TRUE;

if(hit) {
bound->parent[i] = elemind;
bound->side[i] = side;
bound->parent2[i] = 0;
bound->side2[i] = 0;
bound->types[i] = bctype;
k++;
if(hit) {
bound->parent[i] = elemind;
bound->side[i] = side;
} else {
bound->parent[i] = 0;
bound->side[i] = 0;
if(!bcinds) {
bound->topology = Imatrix(1,bcelems,0,1);
bcinds = TRUE;
}
bound->topology[i][0] = ind1;
bound->topology[i][1] = ind2;
}
printf("LoadTriangleInput: %d boundary elements found correctly out of %d\n",k,elemsides);
bound->parent2[i] = 0;
bound->side2[i] = 0;
bound->types[i] = bctype;
k++;

if(0) printf("LoadTriangleInput: %d boundary elements found correctly out of %d\n",k,elemsides);

}
bound->nosides = i;
printf("LoadTriangleInput: Node indexes in boundary range [%d %d] (with offset)\n",jmin,jmax);

}



finish:
printf("Successfully read the mesh from the Triangle input file.\n");

return(0);
Expand Down

2 comments on commit 92170b6

@richb2k
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit works nicely for the boundaries, reading and numbering seems to work well. Just a suggestion, in order to read the body numbers (material numbers based on regions), change line 2770 in egconvert.c from data->material[i] = 1; to data->material[i] = next_int(&cp); This change probably needs a guard, where if 'elematts' is zero, skip the assignment. Thanks, Rich.

@raback
Copy link
Contributor Author

@raback raback commented on 92170b6 Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanx for the suggestion Rich! Did that just.

Please sign in to comment.