/[escript]/branches/split/weipa/src/RipleyDomain.cpp
ViewVC logotype

Contents of /branches/split/weipa/src/RipleyDomain.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4724 - (show annotations)
Thu Mar 6 05:22:12 2014 UTC (5 years, 3 months ago) by jfenwick
File size: 7350 byte(s)
Work towards parallel domains

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

  ViewVC Help
Powered by ViewVC 1.1.26