/[escript]/trunk/weipa/src/RipleyDomain.cpp
ViewVC logotype

Contents of /trunk/weipa/src/RipleyDomain.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3792 - (show annotations)
Wed Feb 1 06:16:25 2012 UTC (7 years, 6 months ago) by caltinay
File size: 7163 byte(s)
Merged ripley rectangular domain into trunk.

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2012 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 #include <weipa/RipleyDomain.h>
15 #include <weipa/RipleyNodes.h>
16 #include <weipa/DataVar.h>
17
18 #ifndef VISIT_PLUGIN
19 #include <ripley/RipleyDomain.h>
20 #endif
21
22 #include <iostream>
23
24 #if USE_SILO
25 #include <silo.h>
26 #endif
27
28 using namespace std;
29
30 namespace weipa {
31
32 RipleyDomain::RipleyDomain() :
33 initialized(false)
34 {
35 }
36
37 RipleyDomain::RipleyDomain(const RipleyDomain& m) :
38 boost::enable_shared_from_this<RipleyDomain>()
39 {
40 nodes = RipleyNodes_ptr(new RipleyNodes(*m.nodes));
41 cells = RipleyElements_ptr(new RipleyElements(*m.cells));
42 faces = RipleyElements_ptr(new RipleyElements(*m.faces));
43 initialized = m.initialized;
44 }
45
46 bool RipleyDomain::initFromEscript(const escript::AbstractDomain* escriptDomain)
47 {
48 initialized = false;
49 #ifndef VISIT_PLUGIN
50 const ripley::RipleyDomain* dom = dynamic_cast<const ripley::RipleyDomain*>(escriptDomain);
51 if (dom) {
52 nodes = RipleyNodes_ptr(new RipleyNodes("Elements"));
53 cells = RipleyElements_ptr(new RipleyElements("Elements", nodes));
54 faces = RipleyElements_ptr(new RipleyElements("FaceElements", nodes));
55
56 if (nodes->initFromRipley(dom) &&
57 cells->initFromRipley(dom, ripley::Elements) &&
58 faces->initFromRipley(dom, ripley::FaceElements)) {
59 initialized = true;
60 }
61 }
62 #endif // VISIT_PLUGIN
63
64 return initialized;
65 }
66
67 bool RipleyDomain::initFromFile(const string& filename)
68 {
69 // not supported yet
70 return false;
71 }
72
73 Centering RipleyDomain::getCenteringForFunctionSpace(int fsCode) const
74 {
75 return (fsCode==ripley::ReducedNodes || fsCode==ripley::Nodes ?
76 NODE_CENTERED : ZONE_CENTERED);
77 }
78
79 NodeData_ptr RipleyDomain::getMeshForFunctionSpace(int fsCode) const
80 {
81 NodeData_ptr result;
82
83 if (!initialized)
84 return result;
85
86 ElementData_ptr elements = getElementsForFunctionSpace(fsCode);
87 if (elements)
88 result = elements->getNodes();
89
90 return result;
91 }
92
93 ElementData_ptr RipleyDomain::getElementsForFunctionSpace(int fsCode) const
94 {
95 ElementData_ptr result;
96
97 if (!initialized)
98 return result;
99
100 switch (fsCode) {
101 case ripley::Nodes:
102 case ripley::ReducedNodes: // FIXME: reduced
103 case ripley::ReducedElements:
104 case ripley::Elements:
105 result = cells;
106 break;
107
108 case ripley::ReducedFaceElements:
109 case ripley::FaceElements:
110 result = faces;
111 break;
112
113 default: {
114 cerr << "Unsupported function space type " << fsCode
115 << "!" << endl;
116 return result;
117 }
118 }
119
120 return result;
121 }
122
123 //
124 // Returns a vector of strings containing mesh names for this domain
125 //
126 StringVec RipleyDomain::getMeshNames() const
127 {
128 StringVec res;
129 if (initialized) {
130 StringVec tmpVec;
131 tmpVec = cells->getMeshNames();
132 res.insert(res.end(), tmpVec.begin(), tmpVec.end());
133 tmpVec = faces->getMeshNames();
134 res.insert(res.end(), tmpVec.begin(), tmpVec.end());
135 }
136 return res;
137 }
138
139 //
140 // Returns a vector of strings containing mesh variable names for this domain
141 //
142 StringVec RipleyDomain::getVarNames() const
143 {
144 StringVec res;
145
146 if (initialized) {
147 res = nodes->getVarNames();
148 StringVec tmpVec = cells->getVarNames();
149 res.insert(res.end(), tmpVec.begin(), tmpVec.end());
150 tmpVec = faces->getVarNames();
151 res.insert(res.end(), tmpVec.begin(), tmpVec.end());
152 }
153
154 return res;
155 }
156
157 DataVar_ptr RipleyDomain::getDataVarByName(const string& name) const
158 {
159 if (!initialized) {
160 throw "Domain not initialized";
161 }
162
163 DataVar_ptr var(new DataVar(name));
164 if (name.find("FaceElements_") != name.npos) {
165 const IntVec& data = faces->getVarDataByName(name);
166 string elementName = name.substr(0, name.find('_'));
167 ElementData_ptr elements = getElementsByName(elementName);
168 var->initFromMeshData(shared_from_this(), data,
169 ripley::FaceElements, ZONE_CENTERED, elements->getNodes(),
170 elements->getIDs());
171 } else if (name.find("Elements_") != name.npos) {
172 const IntVec& data = cells->getVarDataByName(name);
173 string elementName = name.substr(0, name.find('_'));
174 ElementData_ptr elements = getElementsByName(elementName);
175 var->initFromMeshData(shared_from_this(), data, ripley::Elements,
176 ZONE_CENTERED, elements->getNodes(), elements->getIDs());
177 } else if (name.find("Nodes_") != name.npos) {
178 const IntVec& data = nodes->getVarDataByName(name);
179 var->initFromMeshData(shared_from_this(), data, ripley::Nodes,
180 NODE_CENTERED, getNodes(), getNodes()->getNodeIDs());
181 } else {
182 cerr << "WARNING: Unrecognized domain variable '" << name << "'\n";
183 return DataVar_ptr();
184 }
185
186 return var;
187 }
188
189 ElementData_ptr RipleyDomain::getElementsByName(const string& name) const
190 {
191 ElementData_ptr ret;
192 if (name == "Elements")
193 ret = cells;
194 else if (name == "FaceElements")
195 ret = faces;
196
197 return ret;
198 }
199
200 NodeData_ptr RipleyDomain::getMeshByName(const string& name) const
201 {
202 NodeData_ptr ret;
203 if (initialized) {
204 ElementData_ptr els = getElementsByName(name);
205 if (els)
206 ret = els->getNodes();
207 }
208
209 return ret;
210 }
211
212 void RipleyDomain::reorderGhostZones(int ownIndex)
213 {
214 if (initialized) {
215 cells->reorderGhostZones(ownIndex);
216 faces->reorderGhostZones(ownIndex);
217 #ifdef _DEBUG
218 cout << "block " << ownIndex << " has " << cells->getGhostCount()
219 << " ghost zones," << endl;
220 cout << "\t" << faces->getGhostCount() << " ghost faces." << endl;
221 #endif
222 }
223 }
224
225 void RipleyDomain::removeGhostZones(int ownIndex)
226 {
227 if (initialized) {
228 cells->removeGhostZones(ownIndex);
229 faces->removeGhostZones(ownIndex);
230 #ifdef _DEBUG
231 cout << "After removing ghost zones there are" << endl;
232 cout << " " << nodes->getNumNodes() << " Nodes, ";
233 cout << cells->getCount() << " Elements, ";
234 cout << faces->getCount() << " Face elements left." << endl;
235 #endif
236 }
237 }
238
239 bool RipleyDomain::writeToSilo(DBfile* dbfile, const string& pathInSilo,
240 const StringVec& labels, const StringVec& units,
241 bool writeMeshData)
242 {
243 #if USE_SILO
244 // Write nodes, elements and mesh variables
245 if (!initialized
246 || !cells->writeToSilo(dbfile, pathInSilo, labels, units, writeMeshData)
247 || !faces->writeToSilo(dbfile, pathInSilo, labels, units, writeMeshData))
248 return false;
249
250 siloPath = pathInSilo;
251 return true;
252
253 #else // !USE_SILO
254 return false;
255 #endif
256 }
257
258 } // namespace weipa
259

  ViewVC Help
Powered by ViewVC 1.1.26