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

Annotation of /trunk/weipa/src/DataVar.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2888 - (hide annotations)
Fri Jan 29 00:07:00 2010 UTC (9 years, 2 months ago) by caltinay
Original Path: trunk/dataexporter/src/DataVar.cpp
File size: 19525 byte(s)
Looks like netcdf.hh doesn't exist on Windows so changed to netcdfcpp.h.

1 caltinay 2183
2     /*******************************************************
3     *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 caltinay 2183 * 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 caltinay 2810 #include <escriptexport/DataVar.h>
15     #include <escriptexport/ElementData.h>
16     #include <escriptexport/FinleyMesh.h>
17     #include <escriptexport/NodeData.h>
18     #include <escript/Data.h>
19    
20     #if USE_NETCDF
21 caltinay 2888 #include <netcdfcpp.h>
22 caltinay 2810 #endif
23    
24     #if USE_SILO
25 caltinay 2183 #include <silo.h>
26     #endif
27    
28     using namespace std;
29    
30 caltinay 2810 namespace escriptexport {
31 caltinay 2187
32 caltinay 2183 enum {
33     NODE_CENTERED = 1,
34     ZONE_CENTERED = 2
35     };
36    
37     //
38     // Constructor
39     //
40     DataVar::DataVar(const string& name) :
41 caltinay 2810 initialized(false), varName(name),
42     numSamples(0), rank(0), ptsPerSample(0), centering(0)
43 caltinay 2183 {
44     }
45    
46     //
47     // Copy constructor
48     //
49     DataVar::DataVar(const DataVar& d) :
50 caltinay 2880 initialized(d.initialized), finleyMesh(d.finleyMesh),
51 caltinay 2183 varName(d.varName), numSamples(d.numSamples),
52     rank(d.rank), ptsPerSample(d.ptsPerSample), centering(d.centering),
53 caltinay 2810 funcSpace(d.funcSpace), shape(d.shape), sampleID(d.sampleID)
54 caltinay 2183 {
55 caltinay 2810 if (numSamples > 0) {
56     CoordArray::const_iterator it;
57     for (it = d.dataArray.begin(); it != d.dataArray.end(); it++) {
58     float* c = new float[numSamples];
59     copy(*it, (*it)+numSamples, c);
60     dataArray.push_back(c);
61     }
62 caltinay 2183 }
63     }
64    
65     //
66 caltinay 2810 // Destructor
67 caltinay 2183 //
68 caltinay 2810 DataVar::~DataVar()
69 caltinay 2183 {
70 caltinay 2810 cleanup();
71 caltinay 2183 }
72    
73     //
74     //
75 caltinay 2810 //
76     void DataVar::cleanup()
77 caltinay 2183 {
78     CoordArray::iterator it;
79 caltinay 2810 for (it = dataArray.begin(); it != dataArray.end(); it++)
80 caltinay 2183 delete[] *it;
81 caltinay 2810 dataArray.clear();
82     shape.clear();
83     sampleID.clear();
84     numSamples = 0;
85     initialized = false;
86 caltinay 2183 }
87    
88     //
89     //
90 caltinay 2810 //
91     bool DataVar::initFromEscript(escript::Data& escriptData, FinleyMesh_ptr mesh)
92 caltinay 2183 {
93 caltinay 2810 cleanup();
94 caltinay 2183
95 caltinay 2810 if (!escriptData.actsExpanded()) {
96     cerr << "WARNING: Only expanded data supported!" << endl;
97     return false;
98     }
99    
100 caltinay 2880 finleyMesh = mesh;
101 caltinay 2810 rank = escriptData.getDataPointRank();
102     ptsPerSample = escriptData.getNumDataPointsPerSample();
103     shape = escriptData.getDataPointShape();
104     funcSpace = escriptData.getFunctionSpace().getTypeCode();
105     numSamples = escriptData.getNumSamples();
106    
107     if (funcSpace == FINLEY_REDUCED_NODES || funcSpace == FINLEY_NODES) {
108     centering = NODE_CENTERED;
109 caltinay 2183 } else {
110 caltinay 2810 centering = ZONE_CENTERED;
111 caltinay 2183 }
112    
113 caltinay 2810 #ifdef _DEBUG
114     cout << varName << ":\t" << numSamples << " samples, "
115     << ptsPerSample << " pts/s, rank: " << rank << endl;
116     #endif
117 caltinay 2183
118 caltinay 2880 NodeData_ptr nodes = finleyMesh->getMeshForFinleyFS(funcSpace);
119     if (nodes == NULL)
120     return false;
121    
122     meshName = nodes->getName();
123     siloMeshName = nodes->getFullSiloName();
124 caltinay 2810 initialized = true;
125 caltinay 2183
126 caltinay 2880 // no samples? Nothing more to do.
127 caltinay 2810 if (numSamples == 0)
128     return true;
129 caltinay 2183
130 caltinay 2810 const int* iPtr = escriptData.getFunctionSpace().borrowSampleReferenceIDs();
131     sampleID.insert(sampleID.end(), numSamples, 0);
132     copy(iPtr, iPtr+numSamples, sampleID.begin());
133 caltinay 2183
134 caltinay 2810 size_t dimSize = 1;
135     if (rank > 0)
136     dimSize *= shape[0];
137     if (rank > 1)
138     dimSize *= shape[1];
139     if (rank > 2) {
140     cerr << "WARNING: Rank " << rank << " data is not supported!\n";
141     initialized = false;
142     }
143 caltinay 2183
144 caltinay 2810 if (initialized) {
145     size_t dataSize = dimSize * ptsPerSample;
146     float* tempData = new float[dataSize*numSamples];
147     float* destPtr = tempData;
148     for (int sampleNo=0; sampleNo<numSamples; sampleNo++) {
149     const escript::DataAbstract::ValueType::value_type* values =
150     escriptData.getSampleDataRO(sampleNo);
151     copy(values, values+dataSize, destPtr);
152     destPtr += dataSize;
153     }
154    
155     const float* srcPtr = tempData;
156     for (int i=0; i < dimSize; i++, srcPtr++) {
157     float* c = averageData(srcPtr, dimSize);
158     dataArray.push_back(c);
159     }
160     delete[] tempData;
161    
162 caltinay 2880 initialized = reorderSamples();
163 caltinay 2183 }
164 caltinay 2810
165     return initialized;
166 caltinay 2183 }
167    
168     //
169 caltinay 2810 // Initialise with mesh data
170 caltinay 2183 //
171 caltinay 2810 bool DataVar::initFromMesh(FinleyMesh_ptr mesh)
172 caltinay 2183 {
173 caltinay 2810 cleanup();
174    
175 caltinay 2880 finleyMesh = mesh;
176 caltinay 2810 rank = 0;
177     ptsPerSample = 1;
178 caltinay 2880 NodeData_ptr nodes;
179    
180     if (varName.find("ContactElements_") != varName.npos) {
181     funcSpace = FINLEY_CONTACT_ELEMENTS_1;
182     centering = ZONE_CENTERED;
183     string elementName = varName.substr(0, varName.find('_'));
184     ElementData_ptr elements = mesh->getElementsByName(elementName);
185     nodes = elements->getNodeMesh();
186     sampleID = elements->getIDs();
187     } else if (varName.find("FaceElements_") != varName.npos) {
188     funcSpace = FINLEY_FACE_ELEMENTS;
189     centering = ZONE_CENTERED;
190     string elementName = varName.substr(0, varName.find('_'));
191     ElementData_ptr elements = mesh->getElementsByName(elementName);
192     nodes = elements->getNodeMesh();
193     sampleID = elements->getIDs();
194     } else if (varName.find("Elements_") != varName.npos) {
195     funcSpace = FINLEY_ELEMENTS;
196     centering = ZONE_CENTERED;
197     string elementName = varName.substr(0, varName.find('_'));
198     ElementData_ptr elements = mesh->getElementsByName(elementName);
199     nodes = elements->getNodeMesh();
200     sampleID = elements->getIDs();
201     } else if (varName.find("Nodes_") != varName.npos) {
202     funcSpace = FINLEY_NODES;
203     centering = NODE_CENTERED;
204     nodes = mesh->getNodes();
205     sampleID = nodes->getNodeIDs();
206     } else {
207     cerr << "WARNING: Unrecognized mesh variable '" << varName << "'\n";
208     return false;
209     }
210    
211     meshName = nodes->getName();
212     siloMeshName = nodes->getFullSiloName();
213    
214     const IntVec& data = mesh->getVarDataByName(varName);
215 caltinay 2810 numSamples = data.size();
216 caltinay 2183
217 caltinay 2810 if (numSamples > 0) {
218     float* c = new float[numSamples];
219     dataArray.push_back(c);
220     IntVec::const_iterator it;
221     for (it=data.begin(); it != data.end(); it++)
222     *c++ = static_cast<float>(*it);
223 caltinay 2183 }
224 caltinay 2810 initialized = true;
225    
226     return initialized;
227 caltinay 2183 }
228    
229     //
230 caltinay 2810 // Reads variable data from NetCDF file
231 caltinay 2183 //
232 caltinay 2810 bool DataVar::initFromNetCDF(const string& filename, FinleyMesh_ptr mesh)
233 caltinay 2183 {
234 caltinay 2810 cleanup();
235    
236     #if USE_NETCDF
237 caltinay 2183 NcError ncerr(NcError::silent_nonfatal);
238 caltinay 2196 NcFile* input = new NcFile(filename.c_str());
239 caltinay 2183 if (!input->is_valid()) {
240 caltinay 2196 cerr << "Could not open input file " << filename << "." << endl;
241 caltinay 2183 delete input;
242     return false;
243     }
244    
245     NcDim* dim;
246     NcAtt* att;
247    
248     att = input->get_att("type_id");
249     int typeID = att->as_int(0);
250     if (typeID != 2) {
251 caltinay 2810 cerr << "WARNING: Only expanded data supported!" << endl;
252 caltinay 2183 delete input;
253     return false;
254     }
255    
256     att = input->get_att("rank");
257     rank = att->as_int(0);
258    
259     dim = input->get_dim("num_data_points_per_sample");
260     ptsPerSample = dim->size();
261    
262     att = input->get_att("function_space_type");
263     funcSpace = att->as_int(0);
264    
265 caltinay 2810 if (funcSpace == FINLEY_REDUCED_NODES || funcSpace == FINLEY_NODES) {
266     centering = NODE_CENTERED;
267     } else {
268     centering = ZONE_CENTERED;
269     }
270    
271     dim = input->get_dim("num_samples");
272     numSamples = dim->size();
273    
274 caltinay 2183 #ifdef _DEBUG
275     cout << varName << ":\t" << numSamples << " samples, "
276     << ptsPerSample << " pts/s, rank: " << rank << endl;
277     #endif
278    
279 caltinay 2880 finleyMesh = mesh;
280     NodeData_ptr nodes = finleyMesh->getMeshForFinleyFS(funcSpace);
281     if (nodes == NULL) {
282 caltinay 2810 delete input;
283 caltinay 2880 return false;
284 caltinay 2810 }
285    
286 caltinay 2880 meshName = nodes->getName();
287     siloMeshName = nodes->getFullSiloName();
288     initialized = true;
289 caltinay 2183
290 caltinay 2810 size_t dimSize = 1;
291     vector<long> counts;
292    
293     if (rank > 0) {
294     dim = input->get_dim("d0");
295     int d = dim->size();
296     shape.push_back(d);
297     counts.push_back(d);
298     dimSize *= d;
299 caltinay 2183 }
300 caltinay 2810 if (rank > 1) {
301     dim = input->get_dim("d1");
302     int d = dim->size();
303     shape.push_back(d);
304     counts.push_back(d);
305     dimSize *= d;
306     }
307     if (rank > 2) {
308     cerr << "WARNING: Rank " << rank << " data is not supported!\n";
309     initialized = false;
310     }
311    
312 caltinay 2880 if (initialized && numSamples > 0) {
313     sampleID.insert(sampleID.end(), numSamples, 0);
314     NcVar* var = input->get_var("id");
315     var->get(&sampleID[0], numSamples);
316    
317 caltinay 2810 size_t dataSize = dimSize*numSamples*ptsPerSample;
318     counts.push_back(ptsPerSample);
319     counts.push_back(numSamples);
320     float* tempData = new float[dataSize];
321 caltinay 2880 var = input->get_var("data");
322 caltinay 2810 var->get(tempData, &counts[0]);
323 caltinay 2183
324 caltinay 2810 const float* srcPtr = tempData;
325     for (int i=0; i < dimSize; i++, srcPtr++) {
326     float* c = averageData(srcPtr, dimSize);
327     dataArray.push_back(c);
328     }
329     delete[] tempData;
330 caltinay 2183
331 caltinay 2880 initialized = reorderSamples();
332 caltinay 2810 }
333 caltinay 2183
334 caltinay 2810 delete input;
335     #endif // USE_NETCDF
336 caltinay 2183
337 caltinay 2810 return initialized;
338 caltinay 2183 }
339    
340     //
341     // Returns true if the data values are nodal, false if they are zonal.
342     //
343     bool DataVar::isNodeCentered() const
344     {
345 caltinay 2810 return (centering == NODE_CENTERED);
346 caltinay 2183 }
347    
348     //
349 caltinay 2810 // Returns a subset of the src array according to stride parameter.
350     // If samples consist of multiple values they are averaged beforehand.
351     // Used to separate (x0,y0,z0,x1,y1,z1,...) into (x0,x1,...), (y0,y1,...) and
352     // (z0,z1,...)
353 caltinay 2183 //
354 caltinay 2810 float* DataVar::averageData(const float* src, size_t stride)
355 caltinay 2183 {
356 caltinay 2880 float* res;
357 caltinay 2183
358 caltinay 2810 if (ptsPerSample == 1) {
359 caltinay 2880 res = new float[numSamples];
360 caltinay 2810 float* dest = res;
361     for (int i=0; i<numSamples; i++, src+=stride)
362     *dest++ = *src;
363     } else {
364 caltinay 2880 ElementData_ptr cells = finleyMesh->getElementsForFinleyFS(funcSpace);
365     int cellFactor = cells->getElementFactor();
366     res = new float[cellFactor * numSamples];
367 caltinay 2810 float* dest = res;
368 caltinay 2880 QuadMaskInfo qmi = cells->getQuadMask(funcSpace);
369     if (qmi.mask.size() > 0) {
370     const float* tmpSrc = src;
371     for (int i=0; i<numSamples; i++, tmpSrc+=stride*ptsPerSample) {
372     for (int l=0; l<cellFactor; l++) {
373     double tmpVal = 0.0;
374     for (int j=0; j<ptsPerSample; j++) {
375     if (qmi.mask[l][j] != 0) {
376     tmpVal += *(tmpSrc+stride*j);
377     }
378     }
379     *dest++ = (float)(tmpVal / qmi.factor[l]);
380     }
381     }
382     } else {
383     for (int i=0; i<numSamples; i++) {
384     double tmpVal = 0.0;
385     for (int j=0; j<ptsPerSample; j++, src+=stride) {
386     tmpVal += *src;
387     }
388     tmpVal /= ptsPerSample;
389     for (int l=0; l<cellFactor; l++) {
390     *dest++ = static_cast<float>(tmpVal);
391     }
392     }
393 caltinay 2183 }
394     }
395 caltinay 2810 return res;
396 caltinay 2183 }
397    
398     //
399 caltinay 2880 // Filters and reorders the raw sample values according to the node/element
400     // IDs. This is used to have data arrays ordered according to the underlying
401     // mesh (i.e. DataID[i]==MeshNodeID[i])
402 caltinay 2183 //
403 caltinay 2880 bool DataVar::reorderSamples()
404 caltinay 2183 {
405 caltinay 2810 if (numSamples == 0)
406 caltinay 2183 return true;
407    
408 caltinay 2810 const IntVec* requiredIDs = NULL;
409     int requiredNumSamples = 0;
410 caltinay 2880 int cellFactor = 1;
411 caltinay 2183
412 caltinay 2810 if (centering == NODE_CENTERED) {
413 caltinay 2880 NodeData_ptr nodes = finleyMesh->getMeshForFinleyFS(funcSpace);
414 caltinay 2810 requiredIDs = &nodes->getNodeIDs();
415     requiredNumSamples = nodes->getNumNodes();
416     } else {
417     ElementData_ptr cells = finleyMesh->getElementsForFinleyFS(funcSpace);
418     if (cells == NULL)
419     return false;
420 caltinay 2183
421 caltinay 2810 requiredIDs = &cells->getIDs();
422 caltinay 2834 requiredNumSamples = cells->getNumElements();
423 caltinay 2880 cellFactor = cells->getElementFactor();
424     if (cellFactor > 1) {
425     numSamples *= cellFactor;
426     // update sample IDs
427     IntVec newSampleID(numSamples);
428     IntVec::const_iterator idIt = sampleID.begin();
429     IntVec::iterator newIDit = newSampleID.begin();
430     for (; idIt != sampleID.end(); idIt++, newIDit+=cellFactor) {
431     fill(newIDit, newIDit+cellFactor, *idIt);
432     }
433     sampleID.swap(newSampleID);
434     }
435 caltinay 2183 }
436    
437 caltinay 2810 if (requiredNumSamples > numSamples) {
438     cerr << "ERROR: " << varName << " has " << numSamples
439     << " instead of " << requiredNumSamples << " samples!" << endl;
440 caltinay 2183 return false;
441     }
442    
443 caltinay 2810 IndexMap sampleID2idx = buildIndexMap();
444     numSamples = requiredNumSamples;
445    
446     // now filter the data
447     for (size_t i=0; i < dataArray.size(); i++) {
448     float* c = new float[numSamples];
449     const float* src = dataArray[i];
450     IntVec::const_iterator idIt = requiredIDs->begin();
451 caltinay 2880 size_t destIdx = 0;
452     for (; idIt != requiredIDs->end(); idIt+=cellFactor, destIdx+=cellFactor) {
453 caltinay 2810 size_t srcIdx = sampleID2idx.find(*idIt)->second;
454 caltinay 2880 copy(&src[srcIdx], &src[srcIdx+cellFactor], &c[destIdx]);
455 caltinay 2810 }
456     delete[] dataArray[i];
457     dataArray[i] = c;
458     }
459 caltinay 2880
460     // sample IDs now = mesh node/element IDs
461     sampleID = *requiredIDs;
462    
463 caltinay 2183 return true;
464     }
465    
466 caltinay 2886 //
467     //
468     //
469     void DataVar::sampleToStream(ostream& os, int index)
470     {
471     if (rank == 0) {
472     os << dataArray[0][index];
473     } else if (rank == 1) {
474     if (shape[0] < 3)
475     os << dataArray[0][index] << " " << dataArray[1][index]
476     << " " << 0.;
477     else
478     os << dataArray[0][index] << " " << dataArray[1][index]
479     << " " << dataArray[2][index];
480     } else if (rank == 2) {
481     if (shape[1] < 3) {
482     os << dataArray[0][index] << " " << dataArray[1][index]
483     << " " << 0. << " ";
484     os << dataArray[2][index] << " " << dataArray[3][index]
485     << " " << 0. << " ";
486     os << 0. << " " << 0. << " " << 0.;
487     } else {
488     os << dataArray[0][index] << " " << dataArray[1][index]
489     << " " << dataArray[2][index] << " ";
490     os << dataArray[3][index] << " " << dataArray[4][index]
491     << " " << dataArray[5][index] << " ";
492     os << dataArray[6][index] << " " << dataArray[7][index]
493     << " " << dataArray[8][index];
494     }
495     }
496     os << endl;
497     }
498    
499     //
500     //
501     //
502     void DataVar::writeToVTK(ostream& os, int ownIndex)
503     {
504     if (numSamples == 0)
505     return;
506    
507     if (isNodeCentered()) {
508     // data was reordered in reorderSamples() but for VTK we write the
509     // original node mesh and thus need the original ordering...
510     const IntVec& requiredIDs = finleyMesh->getNodes()->getNodeIDs();
511     const IntVec& nodeGNI = finleyMesh->getNodes()->getGlobalNodeIndices();
512     const IntVec& nodeDist = finleyMesh->getNodes()->getNodeDistribution();
513     int firstId = nodeDist[ownIndex];
514     int lastId = nodeDist[ownIndex+1];
515     IndexMap sampleID2idx = buildIndexMap();
516     for (int i=0; i<nodeGNI.size(); i++) {
517     if (firstId <= nodeGNI[i] && nodeGNI[i] < lastId) {
518     int idx = sampleID2idx[requiredIDs[i]];
519     sampleToStream(os, idx);
520     }
521     }
522     } else {
523     // cell data: ghost cells have been removed so do not write ghost
524     // samples (which are the last elements in the arrays)
525     int toWrite =
526     finleyMesh->getElementsByName(meshName)->getNumElements();
527     for (int i=0; i<toWrite; i++) {
528     sampleToStream(os, i);
529     }
530     }
531     }
532    
533 caltinay 2183 ///////////////////////////////
534     // SILO related methods follow
535     ///////////////////////////////
536    
537     //
538     // If the data is tensor data then the components of the tensor are stored
539     // separately in the Silo file. This method then returns a string that
540     // contains the proper Silo expression to put the tensor together again.
541     // For non-tensor data this method returns an empty string.
542     //
543     string DataVar::getTensorDef() const
544     {
545 caltinay 2810 if (rank < 2 || !initialized)
546 caltinay 2183 return string();
547    
548     /// Format string for Silo 2x2 tensor
549     const string tensor2DefFmt =
550     "{{ <%sa_00>, <%sa_01> },"
551     " { <%sa_10>, <%sa_11> }}";
552    
553     /// Format string for Silo 3x3 tensor
554     const string tensor3DefFmt =
555     "{{ <%sa_00>, <%sa_01>, <%sa_02> },"
556     " { <%sa_10>, <%sa_11>, <%sa_12> },"
557     " { <%sa_20>, <%sa_21>, <%sa_22> }}";
558    
559     string tensorDef;
560     string tensorDir = varName+string("_comps/");
561     if (shape[1] == 3) {
562     char* tDef = new char[tensor3DefFmt.length()+9*tensorDir.length()];
563     sprintf(tDef, tensor3DefFmt.c_str(),
564     tensorDir.c_str(), tensorDir.c_str(), tensorDir.c_str(),
565     tensorDir.c_str(), tensorDir.c_str(), tensorDir.c_str(),
566     tensorDir.c_str(), tensorDir.c_str(), tensorDir.c_str());
567     tensorDef = tDef;
568     delete[] tDef;
569     } else {
570     char* tDef = new char[tensor2DefFmt.length()+4*tensorDir.length()];
571     sprintf(tDef, tensor2DefFmt.c_str(),
572     tensorDir.c_str(), tensorDir.c_str(),
573     tensorDir.c_str(), tensorDir.c_str(),
574     tensorDir.c_str(), tensorDir.c_str());
575     tensorDef = tDef;
576     delete[] tDef;
577     }
578     return tensorDef;
579     }
580    
581     //
582     // Writes the data to given Silo file under the virtual path provided.
583     // The corresponding mesh must have been written already and made known
584     // to this variable by a call to setMesh().
585     //
586     bool DataVar::writeToSilo(DBfile* dbfile, const string& siloPath)
587     {
588 caltinay 2810 #if USE_SILO
589     if (!initialized)
590     return false;
591    
592 caltinay 2183 if (numSamples == 0)
593     return true;
594    
595     int ret;
596    
597     if (siloPath != "") {
598     ret = DBSetDir(dbfile, siloPath.c_str());
599     if (ret != 0)
600     return false;
601     }
602 caltinay 2810
603     char* siloMesh = const_cast<char*>(siloMeshName.c_str());
604 caltinay 2183 int dcenter = (centering == NODE_CENTERED ? DB_NODECENT : DB_ZONECENT);
605    
606     if (rank == 0) {
607 caltinay 2810 ret = DBPutUcdvar1(dbfile, varName.c_str(), siloMesh, dataArray[0],
608     numSamples, NULL, 0, DB_FLOAT, dcenter, NULL);
609 caltinay 2183 }
610     else if (rank == 1) {
611     const string comps[3] = {
612     varName+string("_x"), varName+string("_y"), varName+string("_z")
613     };
614     const char* varnames[3] = {
615     comps[0].c_str(), comps[1].c_str(), comps[2].c_str()
616     };
617    
618 caltinay 2810 ret = DBPutUcdvar(dbfile, varName.c_str(), siloMesh, shape[0],
619     (char**)varnames, &dataArray[0], numSamples, NULL,
620 caltinay 2183 0, DB_FLOAT, dcenter, NULL);
621     }
622     else {
623     string tensorDir = varName+string("_comps/");
624     ret = DBMkdir(dbfile, tensorDir.c_str());
625     if (ret == 0) {
626     int one = 1;
627     DBoptlist* optList = DBMakeOptlist(1);
628     DBAddOption(optList, DBOPT_HIDE_FROM_GUI, &one);
629    
630     for (int i=0; i<shape[1]; i++) {
631     for (int j=0; j<shape[0]; j++) {
632     ostringstream varname;
633     varname << tensorDir << "a_" << i << j;
634 caltinay 2810 ret = DBPutUcdvar1(dbfile, varname.str().c_str(), siloMesh,
635     dataArray[i*shape[0]+j], numSamples,
636 caltinay 2183 NULL, 0, DB_FLOAT, dcenter, optList);
637     if (ret != 0) break;
638     }
639     if (ret != 0) break;
640     }
641     DBFreeOptlist(optList);
642     } // ret==0
643     } // rank
644    
645     DBSetDir(dbfile, "/");
646     return (ret == 0);
647    
648 caltinay 2810 #else // !USE_SILO
649 caltinay 2183 return false;
650     #endif
651     }
652    
653 caltinay 2810 } // namespace escriptexport
654 caltinay 2187

  ViewVC Help
Powered by ViewVC 1.1.26