/[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 6939 - (show annotations)
Mon Jan 20 03:37:18 2020 UTC (4 months, 2 weeks ago) by uqaeller
File size: 6970 byte(s)
Updated the copyright header.


1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2020 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14 * Development from 2019 by School of Earth and Environmental Sciences
15 **
16 *****************************************************************************/
17
18 #include "FinleyDomain.h"
19
20 #include <escript/index.h>
21
22 #include <iomanip>
23 #include <iostream>
24
25 using std::cout;
26 using std::endl;
27 using std::ios;
28 using std::setw;
29 using std::string;
30
31 namespace finley {
32
33 // private
34 void FinleyDomain::writeElementInfo(std::ostream& stream, const ElementFile* e,
35 const string& defaultType) const
36 {
37 if (e != NULL) {
38 stream << e->referenceElementSet->referenceElement->Type->Name
39 << " " << e->numElements << endl;
40 const int NN = e->numNodes;
41 for (index_t i = 0; i < e->numElements; i++) {
42 stream << e->Id[i] << " " << e->Tag[i];
43 for (int j = 0; j < NN; j++)
44 stream << " " << m_nodes->Id[e->Nodes[INDEX2(j,i,NN)]];
45 stream << endl;
46 }
47 } else {
48 stream << defaultType << " 0" << endl;
49 }
50 }
51
52 // private
53 void FinleyDomain::printElementInfo(const ElementFile* e, const string& title,
54 const string& defaultType, bool full) const
55 {
56 if (e != NULL) {
57 dim_t mine = 0, overlap = 0;
58 for (index_t i = 0; i < e->numElements; i++) {
59 if (e->Owner[i] == m_mpiInfo->rank)
60 mine++;
61 else
62 overlap++;
63 }
64 cout << "\t" << title << ": "
65 << e->referenceElementSet->referenceElement->Type->Name
66 << " " << e->numElements << " (TypeId="
67 << e->referenceElementSet->referenceElement->Type->TypeId
68 << ") owner=" << mine << " overlap=" << overlap << endl;
69 if (full) {
70 const int NN = e->numNodes;
71 cout << "\t Id Tag Owner Color: Nodes" << endl;
72 for (index_t i = 0; i < e->numElements; i++) {
73 cout << "\t" << setw(7) << e->Id[i]
74 << setw(6) << e->Tag[i]
75 << setw(6) << e->Owner[i]
76 << setw(6) << e->Color[i] << ": ";
77 for (int j = 0; j < NN; j++)
78 cout << setw(6) << m_nodes->Id[e->Nodes[INDEX2(j,i,NN)]];
79 cout << endl;
80 }
81 }
82 } else {
83 cout << "\t" << title << ": " << defaultType << " 0" << endl;
84 }
85 }
86
87
88 void FinleyDomain::write(const string& filename) const
89 {
90 if (m_mpiInfo->size > 1)
91 throw escript::NotImplementedError("FinleyDomain::write: only single rank "
92 "runs are supported.");
93
94 std::ofstream f(filename.c_str());
95 if (!f.is_open()) {
96 std::stringstream ss;
97 ss << "FinleyDomain::write: Opening file " << filename << " for writing failed";
98 throw escript::IOError(ss.str());
99 }
100
101 // write header
102 f << m_name << endl;
103
104 // write nodes
105 if (m_nodes != NULL) {
106 const int numDim = getDim();
107 f << numDim << "D-Nodes " << m_nodes->getNumNodes() << endl;
108 for (index_t i = 0; i < m_nodes->getNumNodes(); i++) {
109 f << m_nodes->Id[i] << " " << m_nodes->globalDegreesOfFreedom[i]
110 << " " << m_nodes->Tag[i];
111 f.setf(ios::scientific, ios::floatfield);
112 f.precision(15);
113 for (int j = 0; j < numDim; j++)
114 f << " " << m_nodes->Coordinates[INDEX2(j,i,numDim)];
115 f << endl;
116 }
117 } else {
118 f << "0D-Nodes 0" << endl;
119 }
120
121 // write elements
122 writeElementInfo(f, m_elements, "Tet4");
123
124 // write face elements
125 writeElementInfo(f, m_faceElements, "Tri3");
126
127 // write contact elements
128 writeElementInfo(f, m_contactElements, "Tri3_Contact");
129
130 // write points
131 writeElementInfo(f, m_points, "Point1");
132
133 // write tags
134 if (m_tagMap.size() > 0) {
135 f << "Tags" << endl;
136 TagMap::const_iterator it;
137 for (it = m_tagMap.begin(); it != m_tagMap.end(); it++) {
138 f << it->first << " " << it->second << endl;
139 }
140 }
141 f << endl;
142 f.close();
143 #ifdef Finley_TRACE
144 cout << "mesh " << m_name << " has been written to file " << filename << endl;
145 #endif
146 }
147
148 void FinleyDomain::Print_Mesh_Info(bool full) const
149 {
150 cout << "PrintMeshInfo running on CPU " << m_mpiInfo->rank << " of "
151 << m_mpiInfo->size << endl;
152 cout << "\tMesh name '" << m_name << "'\n";
153 cout << "\tApproximation order " << approximationOrder << endl;
154 cout << "\tReduced Approximation order " <<reducedApproximationOrder << endl;
155 cout << "\tIntegration order " << integrationOrder << endl;
156 cout << "\tReduced Integration order " << reducedIntegrationOrder << endl;
157
158 // write nodes
159 if (m_nodes != NULL) {
160 const int numDim = getDim();
161 cout << "\tNodes: " << numDim << "D-Nodes " << m_nodes->getNumNodes() << endl;
162 if (full) {
163 cout << "\t Id Tag gDOF gNI grDfI grNI: Coordinates\n";
164 for (index_t i = 0; i < m_nodes->getNumNodes(); i++) {
165 cout << "\t" << setw(7) << m_nodes->Id[i]
166 << setw(6) << m_nodes->Tag[i]
167 << setw(6) << m_nodes->globalDegreesOfFreedom[i]
168 << setw(6) << m_nodes->globalNodesIndex[i]
169 << setw(6) << m_nodes->globalReducedDOFIndex[i]
170 << setw(6) << m_nodes->globalReducedNodesIndex[i] << ": ";
171 cout.setf(ios::scientific, ios::floatfield);
172 cout.precision(15);
173 for (int j = 0; j < numDim; j++)
174 cout << " " << m_nodes->Coordinates[INDEX2(j,i,numDim)];
175 cout << endl;
176 }
177 }
178 } else {
179 cout << "\tNodes: 0D-Nodes 0\n";
180 }
181
182 // write elements
183 printElementInfo(m_elements, "Elements", "Tet4", full);
184
185 // write face elements
186 printElementInfo(m_faceElements, "Face elements", "Tri3", full);
187
188 // write contact elements
189 printElementInfo(m_contactElements, "Contact elements", "Tri3_Contact", full);
190
191 // write points
192 printElementInfo(m_points, "Points", "Point1", full);
193
194 // write tags
195 if (m_tagMap.size() > 0) {
196 cout << "\tTags:\n";
197 TagMap::const_iterator it;
198 for (it = m_tagMap.begin(); it != m_tagMap.end(); it++) {
199 cout << "\t" << setw(7) << it->second << " " << it->first << endl;
200 }
201 }
202 }
203
204 } // namespace finley
205

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision
svn:mergeinfo /branches/4.0fordebian/finley/src/Mesh_write.cpp:5567-5588 /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 /branches/trilinos_from_5897/finley/src/Mesh_write.cpp:5898-6118 /release/3.0/finley/src/Mesh_write.cpp:2591-2601 /release/4.0/finley/src/Mesh_write.cpp:5380-5406 /trunk/finley/src/Mesh_write.cpp:4257-4344

  ViewVC Help
Powered by ViewVC 1.1.26