/[escript]/trunk/finley/src/Mesh_write.cpp
ViewVC logotype

Annotation of /trunk/finley/src/Mesh_write.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4408 - (hide annotations)
Tue May 14 06:58:43 2013 UTC (6 years, 4 months ago) by caltinay
File size: 10103 byte(s)
Mostly no-op - trying to get some consistency in style while going through a
few files.
Also some minor changes related to C->C++ (e.g. no need to copy vector to pass
to functions etc.)

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

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/lapack2681/finley/src/Mesh_write.cpp:2682-2741 /branches/pasowrap/finley/src/Mesh_write.cpp:3661-3674 /branches/py3_attempt2/finley/src/Mesh_write.cpp:3871-3891 /branches/restext/finley/src/Mesh_write.cpp:2610-2624 /branches/ripleygmg_from_3668/finley/src/Mesh_write.cpp:3669-3791 /branches/stage3.0/finley/src/Mesh_write.cpp:2569-2590 /branches/symbolic_from_3470/finley/src/Mesh_write.cpp:3471-3974 /release/3.0/finley/src/Mesh_write.cpp:2591-2601 /trunk/finley/src/Mesh_write.cpp:4257-4344

  ViewVC Help
Powered by ViewVC 1.1.26