/[escript]/trunk-mpi-branch/finley/src/Mesh_joinFaces.c
ViewVC logotype

Contents of /trunk-mpi-branch/finley/src/Mesh_joinFaces.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1226 - (show annotations)
Fri Aug 3 08:00:07 2007 UTC (11 years, 8 months ago) by gross
File MIME type: text/plain
File size: 6522 byte(s)
hook for ParaMetis added. still needs some work
1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 /**************************************************************/
14
15 /* Finley: Mesh */
16
17 /* detects faces in the mesh that match and replaces it by step elements */
18
19 /**************************************************************/
20
21 /* Author: gross@access.edu.au */
22 /* Version: $Id$ */
23
24 /**************************************************************/
25
26 #include "Mesh.h"
27
28 /**************************************************************/
29
30 void Finley_Mesh_joinFaces(Finley_Mesh* self,double safety_factor,double tolerance, bool_t optimize) {
31
32 char error_msg[LenErrorMsg_MAX];
33 index_t e0,e1,*elem1=NULL,*elem0=NULL,*elem_mask=NULL,*matching_nodes_in_elem1=NULL;
34 Finley_ElementFile *newFaceElementsFile=NULL,*newContactElementsFile=NULL;
35 dim_t e,i,numPairs, NN, NN_Contact,c, new_numFaceElements;
36
37 if (self->MPIInfo->size>1) {
38 Finley_setError(TYPE_ERROR,"Finley_Mesh_joinFaces: MPI is not supported yet.");
39 return;
40 }
41 if (self->FaceElements==NULL) return;
42
43 if (self->FaceElements->ReferenceElement->Type->numNodesOnFace<=0) {
44 sprintf(error_msg,"Finley_Mesh_joinFaces:joining faces cannot be applied to face elements of type %s",self->FaceElements->ReferenceElement->Type->Name);
45 Finley_setError(TYPE_ERROR,error_msg);
46 return;
47 }
48 if (self->ContactElements==NULL) {
49 Finley_setError(TYPE_ERROR,"Finley_Mesh_joinFaces: no contact element file present.");
50 return;
51 }
52
53 NN=self->FaceElements->ReferenceElement->Type->numNodes;
54 NN_Contact=self->ContactElements->ReferenceElement->Type->numNodes;
55
56 if (2*NN!=NN_Contact) {
57 sprintf(error_msg,"Finley_Mesh_joinFaces:contact element file for %s cannot hold elements created from face elements %s",
58 self->ContactElements->ReferenceElement->Type->Name,self->FaceElements->ReferenceElement->Type->Name);
59 Finley_setError(TYPE_ERROR,error_msg);
60 return;
61 }
62
63 /* allocate work arrays */
64 elem1=TMPMEMALLOC(self->FaceElements->numElements,index_t);
65 elem0=TMPMEMALLOC(self->FaceElements->numElements,index_t);
66 elem_mask=TMPMEMALLOC(self->FaceElements->numElements,index_t);
67 matching_nodes_in_elem1=TMPMEMALLOC(self->FaceElements->numElements*NN,index_t);
68
69 if (!(Finley_checkPtr(elem1) || Finley_checkPtr(elem0) || Finley_checkPtr(elem_mask) || Finley_checkPtr(matching_nodes_in_elem1))) {
70 /* find the matching face elements */
71 Finley_Mesh_findMatchingFaces(self->Nodes,self->FaceElements,safety_factor,tolerance,&numPairs,elem0,elem1,matching_nodes_in_elem1);
72 if (Finley_noError()) {
73 /* get a list of the face elements to be kept */
74 #pragma omp parallel for private(e) schedule(static)
75 for(e=0;e<self->FaceElements->numElements;e++) elem_mask[e]=1;
76 for(e=0;e<numPairs;e++) {
77 elem_mask[elem0[e]]=0;
78 elem_mask[elem1[e]]=0;
79 }
80 new_numFaceElements=0;
81 /* OMP */
82 for(e=0;e<self->FaceElements->numElements;e++) {
83 if (elem_mask[e]>0) {
84 elem_mask[new_numFaceElements]=e;
85 new_numFaceElements++;
86 }
87 }
88 /* allocate new face element and Contact element files */
89 newContactElementsFile=Finley_ElementFile_alloc(self->ContactElements->ReferenceElement->Type->TypeId,self->ContactElements->order,self->ContactElements->reduced_order, self->MPIInfo);
90 newFaceElementsFile=Finley_ElementFile_alloc(self->FaceElements->ReferenceElement->Type->TypeId,self->FaceElements->order,self->FaceElements->reduced_order, self->MPIInfo);
91 if (Finley_noError()) {
92 Finley_ElementFile_allocTable(newContactElementsFile,numPairs+self->ContactElements->numElements);
93 Finley_ElementFile_allocTable(newFaceElementsFile,new_numFaceElements);
94 }
95 /* copy the old elements over */
96 if (Finley_noError()) {
97 /* get the face elements which are still in use:*/
98 Finley_ElementFile_gather(elem_mask,self->FaceElements,newFaceElementsFile);
99 /* get the Contact elements which are still in use:*/
100 Finley_ElementFile_copyTable(0,newContactElementsFile,0,0,self->ContactElements);
101 c=self->ContactElements->numElements;
102 /* OMP */
103 for (e=0;e<numPairs;e++) {
104 e0=elem0[e];
105 e1=elem1[e];
106 newContactElementsFile->Id[c]=MIN(self->FaceElements->Id[e0],self->FaceElements->Id[e1]);
107 newContactElementsFile->Tag[c]=MIN(self->FaceElements->Tag[e0],self->FaceElements->Tag[e1]);
108 newContactElementsFile->Color[c]=e;
109 for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i,c,NN_Contact)]=self->FaceElements->Nodes[INDEX2(i,e0,NN)];
110 for (i=0;i<NN;i++) newContactElementsFile->Nodes[INDEX2(i+NN,c,NN_Contact)]=matching_nodes_in_elem1[INDEX2(i,e,NN)];
111 c++;
112 }
113 newContactElementsFile->minColor=0;
114 newContactElementsFile->maxColor=numPairs-1;
115 newContactElementsFile->isPrepared=self->FaceElements->isPrepared;
116 }
117 /* set new face and Contact elements */
118 if (Finley_noError()) {
119
120 Finley_ElementFile_free(self->FaceElements);
121 self->FaceElements=newFaceElementsFile;
122 Finley_ElementFile_free(self->ContactElements);
123 self->ContactElements=newContactElementsFile;
124 Finley_Mesh_prepare(self, optimize);
125
126 } else {
127 Finley_ElementFile_free(newFaceElementsFile);
128 Finley_ElementFile_free(newContactElementsFile);
129 }
130 }
131 }
132 TMPMEMFREE(elem1);
133 TMPMEMFREE(elem0);
134 TMPMEMFREE(matching_nodes_in_elem1);
135 TMPMEMFREE(elem_mask);
136 if (Finley_noError()) {
137 if ( ! Finley_Mesh_isPrepared(self) ) {
138 Finley_setError(SYSTEM_ERROR,"Mesh is not prepared for calculation. Contact the programmers.");
139 }
140 }
141 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26