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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26