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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4496 - (show annotations)
Mon Jul 15 06:53:44 2013 UTC (6 years ago) by caltinay
File size: 9157 byte(s)
finley (WIP):
-moved all of finley into its namespace
-introduced some shared pointers
-Mesh is now a class
-other bits and pieces...

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
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 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 /************************************************************************************/
18
19 /* Finley: write Mesh in finley file format */
20
21 /************************************************************************************/
22
23 #include "Mesh.h"
24
25 namespace finley {
26
27 /// writes the mesh to the external file fname using the Finley file format
28 void Mesh::write(const std::string fname) const
29 {
30 char error_msg[LenErrorMsg_MAX];
31 FILE *f;
32 int NN,i,j,numDim;
33
34 if (MPIInfo->size >1 ) {
35 setError(IO_ERROR,"Mesh_write: only single processor runs are supported.");
36 return;
37
38 }
39 /* open file */
40 f=fopen(fname.c_str(), "w");
41 if (f==NULL) {
42 sprintf(error_msg,"Mesh_write: Opening file %s for writing failed.",fname.c_str());
43 setError(IO_ERROR,error_msg);
44 return;
45 }
46
47 /* write header */
48
49 fprintf(f, "%s\n", m_name.c_str());
50
51 /* write nodes: */
52
53 if (Nodes!=NULL) {
54 numDim=getDim();
55 fprintf(f,"%1dD-Nodes %d\n", numDim, Nodes->numNodes);
56 for (i=0;i<Nodes->numNodes;i++) {
57 fprintf(f,"%d %d %d",Nodes->Id[i],Nodes->globalDegreesOfFreedom[i],Nodes->Tag[i]);
58 for (j=0;j<numDim;j++) fprintf(f," %20.15e",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 (Elements!=NULL) {
68 fprintf(f, "%s %d\n",Elements->referenceElementSet->referenceElement->Type->Name,Elements->numElements);
69 NN=Elements->numNodes;
70 for (i=0;i<Elements->numElements;i++) {
71 fprintf(f,"%d %d",Elements->Id[i],Elements->Tag[i]);
72 for (j=0;j<NN;j++) fprintf(f," %d",Nodes->Id[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 (FaceElements!=NULL) {
81 fprintf(f, "%s %d\n", FaceElements->referenceElementSet->referenceElement->Type->Name,FaceElements->numElements);
82 NN=FaceElements->numNodes;
83 for (i=0;i<FaceElements->numElements;i++) {
84 fprintf(f,"%d %d",FaceElements->Id[i],FaceElements->Tag[i]);
85 for (j=0;j<NN;j++) fprintf(f," %d",Nodes->Id[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 (ContactElements!=NULL) {
94 fprintf(f, "%s %d\n",ContactElements->referenceElementSet->referenceElement->Type->Name,ContactElements->numElements);
95 NN=ContactElements->numNodes;
96 for (i=0;i<ContactElements->numElements;i++) {
97 fprintf(f,"%d %d",ContactElements->Id[i],ContactElements->Tag[i]);
98 for (j=0;j<NN;j++) fprintf(f," %d",Nodes->Id[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 (Points!=NULL) {
107 fprintf(f, "%s %d\n",Points->referenceElementSet->referenceElement->Type->Name,Points->numElements);
108 for (i=0;i<Points->numElements;i++) {
109 fprintf(f,"%d %d %d\n",Points->Id[i],Points->Tag[i],Nodes->Id[Points->Nodes[INDEX2(0,i,1)]]);
110 }
111 } else {
112 fprintf(f,"Point1 0\n");
113 }
114
115 /* write tags:*/
116 if (tagMap.size()>0) {
117 fprintf(f, "Tags\n");
118 TagMap::const_iterator it;
119 for (it=tagMap.begin(); it!=tagMap.end(); it++) {
120 fprintf(f, "%s %d\n", it->first.c_str(), it->second);
121 }
122 }
123 fclose(f);
124 #ifdef Finley_TRACE
125 printf("mesh %s has been written to file %s\n", m_name, fname.c_str());
126 #endif
127 }
128
129 void Mesh::printInfo(bool full)
130 {
131 int NN,i,j,numDim;
132
133 fprintf(stdout, "PrintMesh_Info running on CPU %d of %d\n",MPIInfo->rank, MPIInfo->size);
134 fprintf(stdout, "\tMesh name '%s'\n", m_name.c_str());
135 fprintf(stdout, "\tApproximation order %d\n",approximationOrder);
136 fprintf(stdout, "\tReduced Approximation order %d\n",reducedApproximationOrder);
137 fprintf(stdout, "\tIntegration order %d\n",integrationOrder);
138 fprintf(stdout, "\tReduced Integration order %d\n",reducedIntegrationOrder);
139
140 /* write nodes: */
141 if (Nodes!=NULL) {
142 numDim=getDim();
143 fprintf(stdout, "\tNodes: %1dD-Nodes %d\n", numDim, Nodes->numNodes);
144 if (full) {
145 fprintf(stdout, "\t Id Tag gDOF gNI grDfI grNI: Coordinates\n");
146 for (i=0;i<Nodes->numNodes;i++) {
147 fprintf(stdout, "\t %5d %5d %5d %5d %5d %5d: ", Nodes->Id[i], Nodes->Tag[i], Nodes->globalDegreesOfFreedom[i], Nodes->globalNodesIndex[i], Nodes->globalReducedDOFIndex[i], Nodes->globalReducedNodesIndex[i]);
148 for (j=0;j<numDim;j++) fprintf(stdout," %20.15e",Nodes->Coordinates[INDEX2(j,i,numDim)]);
149 fprintf(stdout,"\n");
150 }
151 }
152 } else {
153 fprintf(stdout, "\tNodes: 0D-Nodes 0\n");
154 }
155
156 /* write elements: */
157 if (Elements!=NULL) {
158 int mine=0, overlap=0;
159 for (i=0;i<Elements->numElements;i++) {
160 if (Elements->Owner[i] == MPIInfo->rank) mine++;
161 else overlap++;
162 }
163 fprintf(stdout, "\tElements: %s %d (TypeId=%d) owner=%d overlap=%d\n",Elements->referenceElementSet->referenceElement->Type->Name,Elements->numElements,Elements->referenceElementSet->referenceElement->Type->TypeId, mine, overlap);
164 NN=Elements->numNodes;
165 if (full) {
166 fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
167 for (i=0;i<Elements->numElements;i++) {
168 fprintf(stdout, "\t %5d %5d %5d %5d: ",Elements->Id[i],Elements->Tag[i],Elements->Owner[i],Elements->Color[i]);
169 for (j=0;j<NN;j++) fprintf(stdout," %5d",Nodes->Id[Elements->Nodes[INDEX2(j,i,NN)]]);
170 fprintf(stdout,"\n");
171 }
172 }
173 } else {
174 fprintf(stdout, "\tElements: Tet4 0\n");
175 }
176
177 /* write face elements: */
178 if (FaceElements!=NULL) {
179 int mine=0, overlap=0;
180 for (i=0;i<FaceElements->numElements;i++) {
181 if (FaceElements->Owner[i] == MPIInfo->rank) mine++;
182 else overlap++;
183 }
184 fprintf(stdout, "\tFace elements: %s %d (TypeId=%d) owner=%d overlap=%d\n", FaceElements->referenceElementSet->referenceElement->Type->Name,FaceElements->numElements,FaceElements->referenceElementSet->referenceElement->Type->TypeId, mine, overlap);
185 NN=FaceElements->numNodes;
186 if (full) {
187 fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
188 for (i=0;i<FaceElements->numElements;i++) {
189 fprintf(stdout, "\t %5d %5d %5d %5d: ",FaceElements->Id[i],FaceElements->Tag[i],FaceElements->Owner[i],FaceElements->Color[i]);
190 for (j=0;j<NN;j++) fprintf(stdout," %5d",Nodes->Id[FaceElements->Nodes[INDEX2(j,i,NN)]]);
191 fprintf(stdout,"\n");
192 }
193 }
194 } else {
195 fprintf(stdout, "\tFace elements: Tri3 0\n");
196 }
197
198 /* write Contact elements : */
199 if (ContactElements!=NULL) {
200 int mine=0, overlap=0;
201 for (i=0;i<ContactElements->numElements;i++) {
202 if (ContactElements->Owner[i] == MPIInfo->rank) mine++;
203 else overlap++;
204 }
205 fprintf(stdout, "\tContact elements: %s %d (TypeId=%d) owner=%d overlap=%d\n",ContactElements->referenceElementSet->referenceElement->Type->Name,ContactElements->numElements,ContactElements->referenceElementSet->referenceElement->Type->TypeId, mine, overlap);
206 NN=ContactElements->numNodes;
207 if (full) {
208 fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
209 for (i=0;i<ContactElements->numElements;i++) {
210 fprintf(stdout, "\t %5d %5d %5d %5d: ",ContactElements->Id[i],ContactElements->Tag[i],ContactElements->Owner[i],ContactElements->Color[i]);
211 for (j=0;j<NN;j++) fprintf(stdout," %5d",Nodes->Id[ContactElements->Nodes[INDEX2(j,i,NN)]]);
212 fprintf(stdout,"\n");
213 }
214 }
215 } else {
216 fprintf(stdout, "\tContact elements: Tri3_Contact 0\n");
217 }
218
219 /* write points: */
220 if (Points!=NULL) {
221 int mine=0, overlap=0;
222 for (i=0;i<Points->numElements;i++) {
223 if (Points->Owner[i] == MPIInfo->rank) mine++;
224 else overlap++;
225 }
226 fprintf(stdout, "\tPoints: %s %d (TypeId=%d) owner=%d overlap=%d\n",Points->referenceElementSet->referenceElement->Type->Name,Points->numElements,Points->referenceElementSet->referenceElement->Type->TypeId, mine, overlap);
227 if (full) {
228 fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
229 for (i=0;i<Points->numElements;i++) {
230 fprintf(stdout, "\t %5d %5d %5d %5d %5d\n",Points->Id[i],Points->Tag[i],Points->Owner[i],Points->Color[i],Nodes->Id[Points->Nodes[INDEX2(0,i,1)]]);
231 }
232 }
233 } else {
234 fprintf(stdout, "\tPoints: Point1 0\n");
235 }
236
237 // write tags
238 if (tagMap.size()>0) {
239 fprintf(stdout, "\tTags:\n");
240 TagMap::const_iterator it;
241 for (it=tagMap.begin(); it!=tagMap.end(); it++) {
242 fprintf(stdout, "\t %5d %s\n", it->second, it->first.c_str());
243 }
244 }
245 }
246
247 } // namespace finley
248

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