diff --git a/Post/PViewDataGModel.h b/Post/PViewDataGModel.h index 101f54d0c56e533b6b01c47fa0b8ed454140b11f..25c08053176cf1e4751f36ee38f34552de1c74f5 100644 --- a/Post/PViewDataGModel.h +++ b/Post/PViewDataGModel.h @@ -192,6 +192,14 @@ class PViewDataGModel : public PViewData { // direct access to value by index bool getValueByIndex(int step, int dataIndex, int node, int comp, double &val); + // Add some data "on the fly" + // data are stored by vertex, i.e., if field has let's say 3 components, + // nodalData contains 3 * N entries with N being the number of mesh vertices + // of in the model. + // nodlaData [ iVer * N + jComp] is the jComp th component at vertex iVer + bool addNodalData(int step, double time, int partition, + int numComp, const std::vector<double> &nodalData); + // I/O routines bool readMSH(std::string fileName, int fileIndex, FILE *fp, bool binary, bool swap, int step, double time, int partition, diff --git a/Post/PViewDataGModelIO.cpp b/Post/PViewDataGModelIO.cpp index cd7788c15edb7fe74680e00f60f4d53a414109f3..66b296388e82a509b091e7c020e4096c39b410ac 100644 --- a/Post/PViewDataGModelIO.cpp +++ b/Post/PViewDataGModelIO.cpp @@ -1,4 +1,4 @@ -// $Id: PViewDataGModelIO.cpp,v 1.42 2008-04-17 10:45:23 geuzaine Exp $ +// $Id: PViewDataGModelIO.cpp,v 1.43 2008-04-22 10:02:44 remacle Exp $ // // Copyright (C) 1997-2008 C. Geuzaine, J.-F. Remacle // @@ -30,6 +30,38 @@ #include "Numeric.h" #include "StringUtils.h" +bool PViewDataGModel::addNodalData(int step, + double time, + int partition, + int numComp, + const std::vector<double> &nodalData){ + // add empty steps up to the actual step + while(step >= (int)_steps.size()) + _steps.push_back(new stepData<double>(GModel::current(), numComp)); + + const int mult = 1; + int numEnt = _steps[step]->getModel()->getNumMeshVertices(); + if (nodalData.size() != numEnt * numComp){ + Msg(GERROR, "adding nodal data with wrong number of entries (%d != %d)", + nodalData.size(), numEnt); + return false; + } + + _steps[step]->setTime(time); + _steps[step]->resizeData(numEnt); + + for(int i = 0; i < numEnt; i++){ + // MVertex *v = _steps[step]->getModel()->getMeshVertexByTag(i); + double *d = _steps[step]->getData(i, true, 1); + for(int j = 0; j < numComp * mult; j++) + d[j] = nodalData[i * numComp + j]; + } + _partitions.insert(partition); + finalize(); + return true; +} + + bool PViewDataGModel::readMSH(std::string fileName, int fileIndex, FILE *fp, bool binary, bool swap, int step, double time, int partition, int numComp, int numEnt)