/[escript]/branches/domexper/dudley/src/Mesh_write.c
ViewVC logotype

Contents of /branches/domexper/dudley/src/Mesh_write.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3126 - (show annotations)
Wed Sep 1 00:37:53 2010 UTC (8 years, 8 months ago) by jfenwick
File MIME type: text/plain
File size: 7813 byte(s)
Updated referenceElements and enums
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 /**************************************************************/
16
17 /* Dudley: write Mesh */
18
19 /**************************************************************/
20
21 #include "Mesh.h"
22
23 /**************************************************************/
24
25 /* writes the mesh to the external file fname unsing the Dudley file format: */
26
27 void Dudley_Mesh_write(Dudley_Mesh *in,char* fname) {
28 char error_msg[LenErrorMsg_MAX];
29 FILE *f;
30 int NN,i,j,numDim;
31 Dudley_TagMap* tag_map=in->TagMap;
32
33 if (in->MPIInfo->size >1 ) {
34 Dudley_setError(IO_ERROR,"Mesh_write: only single processor runs are supported.");
35 return;
36
37 }
38 /* open file */
39 f=fopen(fname,"w");
40 if (f==NULL) {
41 sprintf(error_msg,"Mesh_write: Opening file %s for writing failed.",fname);
42 Dudley_setError(IO_ERROR,error_msg);
43 return;
44 }
45
46 /* write header */
47
48 fprintf(f,"%s\n",in->Name);
49
50 /* write nodes: */
51
52 if (in->Nodes!=NULL) {
53 numDim=Dudley_Mesh_getDim(in);
54 fprintf(f,"%1dD-Nodes %d\n", numDim, in->Nodes->numNodes);
55 for (i=0;i<in->Nodes->numNodes;i++) {
56 fprintf(f,"%d %d %d",in->Nodes->Id[i],in->Nodes->globalDegreesOfFreedom[i],in->Nodes->Tag[i]);
57 for (j=0;j<numDim;j++) fprintf(f," %20.15e",in->Nodes->Coordinates[INDEX2(j,i,numDim)]);
58 fprintf(f,"\n");
59 }
60 } else {
61 fprintf(f,"0D-Nodes 0\n");
62 }
63
64 /* write elements: */
65
66 if (in->Elements!=NULL) {
67 fprintf(f, "%s %d\n",in->Elements->referenceElementSet->referenceElement->Type->Name,in->Elements->numElements);
68 NN=in->Elements->numNodes;
69 for (i=0;i<in->Elements->numElements;i++) {
70 fprintf(f,"%d %d",in->Elements->Id[i],in->Elements->Tag[i]);
71 for (j=0;j<NN;j++) fprintf(f," %d",in->Nodes->Id[in->Elements->Nodes[INDEX2(j,i,NN)]]);
72 fprintf(f,"\n");
73 }
74 } else {
75 fprintf(f,"Tet4 0\n");
76 }
77
78 /* write face elements: */
79 if (in->FaceElements!=NULL) {
80 fprintf(f, "%s %d\n", in->FaceElements->referenceElementSet->referenceElement->Type->Name,in->FaceElements->numElements);
81 NN=in->FaceElements->numNodes;
82 for (i=0;i<in->FaceElements->numElements;i++) {
83 fprintf(f,"%d %d",in->FaceElements->Id[i],in->FaceElements->Tag[i]);
84 for (j=0;j<NN;j++) fprintf(f," %d",in->Nodes->Id[in->FaceElements->Nodes[INDEX2(j,i,NN)]]);
85 fprintf(f,"\n");
86 }
87 } else {
88 fprintf(f,"Tri3 0\n");
89 }
90
91 /* write points: */
92 if (in->Points!=NULL) {
93 fprintf(f, "%s %d\n",in->Points->referenceElementSet->referenceElement->Type->Name,in->Points->numElements);
94 for (i=0;i<in->Points->numElements;i++) {
95 fprintf(f,"%d %d %d\n",in->Points->Id[i],in->Points->Tag[i],in->Nodes->Id[in->Points->Nodes[INDEX2(0,i,1)]]);
96 }
97 } else {
98 fprintf(f,"Point1 0\n");
99 }
100
101 /* write tags:*/
102 if (tag_map) {
103 fprintf(f,"Tags\n");
104 while (tag_map) {
105 fprintf(f,"%s %d\n",tag_map->name,tag_map->tag_key);
106 tag_map=tag_map->next;
107 }
108 }
109 fclose(f);
110 #ifdef Dudley_TRACE
111 printf("mesh %s has been written to file %s\n",in->Name,fname);
112 #endif
113 }
114
115 void Dudley_PrintMesh_Info(Dudley_Mesh *in, bool_t full) {
116 int NN,i,j,numDim;
117 Dudley_TagMap* tag_map=in->TagMap;
118
119 fprintf(stdout, "Dudley_PrintMesh_Info running on CPU %d of %d\n",in->MPIInfo->rank, in->MPIInfo->size);
120 fprintf(stdout, "\tMesh name '%s'\n",in->Name);
121 fprintf(stdout, "\tApproximation order %d\n",in->approximationOrder);
122 fprintf(stdout, "\tReduced Approximation order %d\n",in->reducedApproximationOrder);
123 fprintf(stdout, "\tIntegration order %d\n",in->integrationOrder);
124 fprintf(stdout, "\tReduced Integration order %d\n",in->reducedIntegrationOrder);
125
126 /* write nodes: */
127 if (in->Nodes!=NULL) {
128 numDim=Dudley_Mesh_getDim(in);
129 fprintf(stdout, "\tNodes: %1dD-Nodes %d\n", numDim, in->Nodes->numNodes);
130 if (full) {
131 fprintf(stdout, "\t Id Tag gDOF gNI grDfI grNI: Coordinates\n");
132 for (i=0;i<in->Nodes->numNodes;i++) {
133 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]);
134 for (j=0;j<numDim;j++) fprintf(stdout," %20.15e",in->Nodes->Coordinates[INDEX2(j,i,numDim)]);
135 fprintf(stdout,"\n");
136 }
137 }
138 } else {
139 fprintf(stdout, "\tNodes: 0D-Nodes 0\n");
140 }
141
142 /* write elements: */
143 if (in->Elements!=NULL) {
144 int mine=0, overlap=0;
145 for (i=0;i<in->Elements->numElements;i++) {
146 if (in->Elements->Owner[i] == in->MPIInfo->rank) mine++;
147 else overlap++;
148 }
149 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);
150 NN=in->Elements->numNodes;
151 if (full) {
152 fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
153 for (i=0;i<in->Elements->numElements;i++) {
154 fprintf(stdout, "\t %5d %5d %5d %5d: ",in->Elements->Id[i],in->Elements->Tag[i],in->Elements->Owner[i],in->Elements->Color[i]);
155 for (j=0;j<NN;j++) fprintf(stdout," %5d",in->Nodes->Id[in->Elements->Nodes[INDEX2(j,i,NN)]]);
156 fprintf(stdout,"\n");
157 }
158 }
159 } else {
160 fprintf(stdout, "\tElements: Tet4 0\n");
161 }
162
163 /* write face elements: */
164 if (in->FaceElements!=NULL) {
165 int mine=0, overlap=0;
166 for (i=0;i<in->FaceElements->numElements;i++) {
167 if (in->FaceElements->Owner[i] == in->MPIInfo->rank) mine++;
168 else overlap++;
169 }
170 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);
171 NN=in->FaceElements->numNodes;
172 if (full) {
173 fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
174 for (i=0;i<in->FaceElements->numElements;i++) {
175 fprintf(stdout, "\t %5d %5d %5d %5d: ",in->FaceElements->Id[i],in->FaceElements->Tag[i],in->FaceElements->Owner[i],in->FaceElements->Color[i]);
176 for (j=0;j<NN;j++) fprintf(stdout," %5d",in->Nodes->Id[in->FaceElements->Nodes[INDEX2(j,i,NN)]]);
177 fprintf(stdout,"\n");
178 }
179 }
180 } else {
181 fprintf(stdout, "\tFace elements: Tri3 0\n");
182 }
183
184 /* write points: */
185 if (in->Points!=NULL) {
186 int mine=0, overlap=0;
187 for (i=0;i<in->Points->numElements;i++) {
188 if (in->Points->Owner[i] == in->MPIInfo->rank) mine++;
189 else overlap++;
190 }
191 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);
192 if (full) {
193 fprintf(stdout, "\t Id Tag Owner Color: Nodes\n");
194 for (i=0;i<in->Points->numElements;i++) {
195 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)]]);
196 }
197 }
198 } else {
199 fprintf(stdout, "\tPoints: Point1 0\n");
200 }
201
202 /* write tags:*/
203 if (tag_map) {
204 fprintf(stdout, "\tTags:\n");
205 while (tag_map) {
206 fprintf(stdout, "\t %5d %s\n", tag_map->tag_key, tag_map->name);
207 tag_map=tag_map->next;
208 }
209 }
210 }
211
212
213

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26