/[escript]/branches/arrayview_from_1695_trunk/finley/src/Mesh_write.c
ViewVC logotype

Annotation of /branches/arrayview_from_1695_trunk/finley/src/Mesh_write.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1781 - (hide annotations)
Thu Sep 11 05:03:14 2008 UTC (10 years, 8 months ago) by jfenwick
File MIME type: text/plain
File size: 9752 byte(s)
Branch commit

Merged changes from trunk version 1695 up to and including version 1779.


1 jgs 150
2 ksteube 1312 /* $Id$ */
3 jgs 82
4 ksteube 1312 /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15 jgs 82
16     /**************************************************************/
17    
18 ksteube 1312 /* Finley: write Mesh */
19 jgs 82
20     /**************************************************************/
21    
22     #include "Mesh.h"
23    
24     /**************************************************************/
25    
26     /* writes the mesh to the external file fname unsing the Finley file format: */
27    
28     void Finley_Mesh_write(Finley_Mesh *in,char* fname) {
29 jgs 150 char error_msg[LenErrorMsg_MAX];
30 jgs 82 FILE *f;
31     int NN,i,j,numDim;
32 gross 1044 Finley_TagMap* tag_map=in->TagMap;
33 jgs 82
34 ksteube 1312 if (in->MPIInfo->size >1 ) {
35     Finley_setError(IO_ERROR,"Mesh_write: only single processor runs are supported.");
36     return;
37    
38     }
39 jgs 82 /* open file */
40     f=fopen(fname,"w");
41     if (f==NULL) {
42 ksteube 1312 sprintf(error_msg,"Mesh_write: Opening file %s for writing failed.",fname);
43 jgs 150 Finley_setError(IO_ERROR,error_msg);
44 jgs 82 return;
45     }
46    
47     /* write header */
48    
49     fprintf(f,"%s\n",in->Name);
50    
51     /* write nodes: */
52    
53     if (in->Nodes!=NULL) {
54     numDim=Finley_Mesh_getDim(in);
55     fprintf(f,"%1dD-Nodes %d\n", numDim, in->Nodes->numNodes);
56     for (i=0;i<in->Nodes->numNodes;i++) {
57 ksteube 1312 fprintf(f,"%d %d %d",in->Nodes->Id[i],in->Nodes->globalDegreesOfFreedom[i],in->Nodes->Tag[i]);
58 jgs 82 for (j=0;j<numDim;j++) fprintf(f," %20.15e",in->Nodes->Coordinates[INDEX2(j,i,numDim)]);
59     fprintf(f,"\n");
60     }
61     } else {
62     fprintf(f,"0D-Nodes 0\n");
63     }
64    
65     /* write elements: */
66    
67     if (in->Elements!=NULL) {
68     fprintf(f, "%s %d\n",in->Elements->ReferenceElement->Type->Name,in->Elements->numElements);
69 ksteube 1312 NN=in->Elements->numNodes;
70 jgs 82 for (i=0;i<in->Elements->numElements;i++) {
71     fprintf(f,"%d %d",in->Elements->Id[i],in->Elements->Tag[i]);
72     for (j=0;j<NN;j++) fprintf(f," %d",in->Nodes->Id[in->Elements->Nodes[INDEX2(j,i,NN)]]);
73     fprintf(f,"\n");
74     }
75     } else {
76     fprintf(f,"Tet4 0\n");
77     }
78    
79     /* write face elements: */
80     if (in->FaceElements!=NULL) {
81     fprintf(f, "%s %d\n", in->FaceElements->ReferenceElement->Type->Name,in->FaceElements->numElements);
82 ksteube 1312 NN=in->FaceElements->numNodes;
83 jgs 82 for (i=0;i<in->FaceElements->numElements;i++) {
84     fprintf(f,"%d %d",in->FaceElements->Id[i],in->FaceElements->Tag[i]);
85     for (j=0;j<NN;j++) fprintf(f," %d",in->Nodes->Id[in->FaceElements->Nodes[INDEX2(j,i,NN)]]);
86     fprintf(f,"\n");
87     }
88     } else {
89     fprintf(f,"Tri3 0\n");
90     }
91    
92     /* write Contact elements : */
93     if (in->ContactElements!=NULL) {
94     fprintf(f, "%s %d\n",in->ContactElements->ReferenceElement->Type->Name,in->ContactElements->numElements);
95 ksteube 1312 NN=in->ContactElements->numNodes;
96 jgs 82 for (i=0;i<in->ContactElements->numElements;i++) {
97     fprintf(f,"%d %d",in->ContactElements->Id[i],in->ContactElements->Tag[i]);
98     for (j=0;j<NN;j++) fprintf(f," %d",in->Nodes->Id[in->ContactElements->Nodes[INDEX2(j,i,NN)]]);
99     fprintf(f,"\n");
100     }
101     } else {
102     fprintf(f,"Tri3_Contact 0\n");
103     }
104    
105     /* write points: */
106     if (in->Points!=NULL) {
107     fprintf(f, "%s %d\n",in->Points->ReferenceElement->Type->Name,in->Points->numElements);
108     for (i=0;i<in->Points->numElements;i++) {
109     fprintf(f,"%d %d %d\n",in->Points->Id[i],in->Points->Tag[i],in->Nodes->Id[in->Points->Nodes[INDEX2(0,i,1)]]);
110     }
111     } else {
112     fprintf(f,"Point1 0\n");
113     }
114 gross 1044
115     /* write tags:*/
116     if (tag_map) {
117     fprintf(f,"Tags\n");
118     while (tag_map) {
119     fprintf(f,"%s %d\n",tag_map->name,tag_map->tag_key);
120     tag_map=tag_map->next;
121     }
122     }
123 jgs 82 fclose(f);
124     #ifdef Finley_TRACE
125     printf("mesh %s has been written to file %s\n",in->Name,fname);
126     #endif
127     }
128    
129 ksteube 1339 void Finley_PrintMesh_Info(Finley_Mesh *in, bool_t full) {
130 ksteube 1326 int NN,i,j,numDim;
131     Finley_TagMap* tag_map=in->TagMap;
132    
133     fprintf(stdout, "Finley_PrintMesh_Info running on CPU %d of %d\n",in->MPIInfo->rank, in->MPIInfo->size);
134     fprintf(stdout, "\tMesh name '%s'\n",in->Name);
135     fprintf(stdout, "\tOrder %d\n",in->order);
136     fprintf(stdout, "\tReduced order %d\n",in->reduced_order);
137    
138     /* write nodes: */
139     if (in->Nodes!=NULL) {
140     numDim=Finley_Mesh_getDim(in);
141 ksteube 1345 if (in->Nodes->degreesOfFreedomDistribution != NULL) {
142     fprintf(stdout, "\tNodes->degreesOfFreedomDistribution:");
143     for (j=0;j<in->MPIInfo->size+1;j++) fprintf(stdout," %d",in->Nodes->degreesOfFreedomDistribution->first_component[j]);
144     fprintf(stdout, "\n");
145     }
146 ksteube 1326 fprintf(stdout, "\tNodes: %1dD-Nodes %d\n", numDim, in->Nodes->numNodes);
147 ksteube 1339 if (full) {
148 ksteube 1343 fprintf(stdout, "\t Id Tag gDOF gNI grDfI grNI: Coordinates\n");
149 ksteube 1339 for (i=0;i<in->Nodes->numNodes;i++) {
150     fprintf(stdout, "\t %5d %5d %5d %5d %5d %5d: ", in->Nodes->Id[i], in->Nodes->Tag[i], in->Nodes->globalDegreesOfFreedom[i], in->Nodes->globalNodesIndex[i], in->Nodes->globalReducedDOFIndex[i], in->Nodes->globalReducedNodesIndex[i]);
151     for (j=0;j<numDim;j++) fprintf(stdout," %20.15e",in->Nodes->Coordinates[INDEX2(j,i,numDim)]);
152     fprintf(stdout,"\n");
153     }
154 ksteube 1326 }
155     } else {
156     fprintf(stdout, "\tNodes: 0D-Nodes 0\n");
157     }
158    
159     /* write elements: */
160     if (in->Elements!=NULL) {
161 jfenwick 1781 int mine=0, overlap=0;
162     for (i=0;i<in->Elements->numElements;i++) {
163     if (in->Elements->Owner[i] == in->MPIInfo->rank) mine++;
164     else overlap++;
165     }
166     fprintf(stdout, "\tElements: %s %d (TypeId=%d) owner=%d overlap=%d\n",in->Elements->ReferenceElement->Type->Name,in->Elements->numElements,in->Elements->ReferenceElement->Type->TypeId, mine, overlap);
167 ksteube 1326 NN=in->Elements->numNodes;
168 ksteube 1339 if (full) {
169     fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
170     for (i=0;i<in->Elements->numElements;i++) {
171     fprintf(stdout, "\t %5d %5d %5d %5d: ",in->Elements->Id[i],in->Elements->Tag[i],in->Elements->Owner[i],in->Elements->Color[i]);
172     for (j=0;j<NN;j++) fprintf(stdout," %5d",in->Nodes->Id[in->Elements->Nodes[INDEX2(j,i,NN)]]);
173     fprintf(stdout,"\n");
174     }
175 ksteube 1326 }
176     } else {
177     fprintf(stdout, "\tElements: Tet4 0\n");
178     }
179    
180     /* write face elements: */
181     if (in->FaceElements!=NULL) {
182 jfenwick 1781 int mine=0, overlap=0;
183     for (i=0;i<in->FaceElements->numElements;i++) {
184     if (in->FaceElements->Owner[i] == in->MPIInfo->rank) mine++;
185     else overlap++;
186     }
187     fprintf(stdout, "\tFace elements: %s %d (TypeId=%d) owner=%d overlap=%d\n", in->FaceElements->ReferenceElement->Type->Name,in->FaceElements->numElements,in->FaceElements->ReferenceElement->Type->TypeId, mine, overlap);
188 ksteube 1326 NN=in->FaceElements->numNodes;
189 ksteube 1339 if (full) {
190     fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
191     for (i=0;i<in->FaceElements->numElements;i++) {
192     fprintf(stdout, "\t %5d %5d %5d %5d: ",in->FaceElements->Id[i],in->FaceElements->Tag[i],in->FaceElements->Owner[i],in->FaceElements->Color[i]);
193     for (j=0;j<NN;j++) fprintf(stdout," %5d",in->Nodes->Id[in->FaceElements->Nodes[INDEX2(j,i,NN)]]);
194     fprintf(stdout,"\n");
195     }
196 ksteube 1326 }
197     } else {
198     fprintf(stdout, "\tFace elements: Tri3 0\n");
199     }
200    
201     /* write Contact elements : */
202     if (in->ContactElements!=NULL) {
203 jfenwick 1781 int mine=0, overlap=0;
204     for (i=0;i<in->ContactElements->numElements;i++) {
205     if (in->ContactElements->Owner[i] == in->MPIInfo->rank) mine++;
206     else overlap++;
207     }
208     fprintf(stdout, "\tContact elements: %s %d (TypeId=%d) owner=%d overlap=%d\n",in->ContactElements->ReferenceElement->Type->Name,in->ContactElements->numElements,in->ContactElements->ReferenceElement->Type->TypeId, mine, overlap);
209 ksteube 1326 NN=in->ContactElements->numNodes;
210 ksteube 1339 if (full) {
211     fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
212     for (i=0;i<in->ContactElements->numElements;i++) {
213     fprintf(stdout, "\t %5d %5d %5d %5d: ",in->ContactElements->Id[i],in->ContactElements->Tag[i],in->ContactElements->Owner[i],in->ContactElements->Color[i]);
214     for (j=0;j<NN;j++) fprintf(stdout," %5d",in->Nodes->Id[in->ContactElements->Nodes[INDEX2(j,i,NN)]]);
215     fprintf(stdout,"\n");
216     }
217 ksteube 1326 }
218     } else {
219 ksteube 1346 fprintf(stdout, "\tContact elements: Tri3_Contact 0\n");
220 ksteube 1326 }
221    
222     /* write points: */
223     if (in->Points!=NULL) {
224 jfenwick 1781 int mine=0, overlap=0;
225     for (i=0;i<in->Points->numElements;i++) {
226     if (in->Points->Owner[i] == in->MPIInfo->rank) mine++;
227     else overlap++;
228     }
229     fprintf(stdout, "\tPoints: %s %d (TypeId=%d) owner=%d overlap=%d\n",in->Points->ReferenceElement->Type->Name,in->Points->numElements,in->Points->ReferenceElement->Type->TypeId, mine, overlap);
230 ksteube 1339 if (full) {
231     fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
232     for (i=0;i<in->Points->numElements;i++) {
233     fprintf(stdout, "\t %5d %5d %5d %5d %5d\n",in->Points->Id[i],in->Points->Tag[i],in->Points->Owner[i],in->Points->Color[i],in->Nodes->Id[in->Points->Nodes[INDEX2(0,i,1)]]);
234     }
235 ksteube 1326 }
236     } else {
237     fprintf(stdout, "\tPoints: Point1 0\n");
238     }
239    
240     /* write tags:*/
241     if (tag_map) {
242     fprintf(stdout, "\tTags:\n");
243     while (tag_map) {
244     fprintf(stdout, "\t %5d %s\n", tag_map->tag_key, tag_map->name);
245     tag_map=tag_map->next;
246     }
247     }
248     }
249    
250 jgs 82 /*
251     * $Log$
252 jgs 150 * Revision 1.2 2005/09/15 03:44:23 jgs
253     * Merge of development branch dev-02 back to main trunk on 2005-09-15
254 jgs 82 *
255 jgs 150 * Revision 1.1.1.1.6.1 2005/09/07 06:26:20 gross
256     * the solver from finley are put into the standalone package paso now
257     *
258     * Revision 1.1.1.1 2004/10/26 06:53:57 jgs
259     * initial import of project esys2
260     *
261 jgs 82 * Revision 1.1.1.1 2004/06/24 04:00:40 johng
262     * Initial version of eys using boost-python.
263     *
264     *
265     */
266    

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26