Skip to content
Snippets Groups Projects
Commit c0c5f995 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

more View functions

parent 490e9ad0
No related branches found
No related tags found
No related merge requests found
...@@ -2040,19 +2040,103 @@ void gmshViewAddModelData(const int tag, const std::string &modelName, ...@@ -2040,19 +2040,103 @@ void gmshViewAddModelData(const int tag, const std::string &modelName,
#endif #endif
} }
/* void gmshViewAddListData(const int tag, const std::string &type, const int numEle,
void gmshViewAddListData(const int tag, ...); const std::vector<double> &data)
void gmshViewAddStringData(const int tag, ...); {
void gmshViewAddXYData(const int tag, const std::vector<double> &x, if(!_isInitialized()){ throw -1; }
const std::vector<double> &y); #if defined(HAVE_POST)
void gmshViewAddXYZData(const int tag, const std::vector<double> &x, PView *view = PView::getViewByTag(tag);
const std::vector<double> &y, if(!view){
const std::vector<double> &z); Msg::Error("Unknown view with tag %d", tag);
throw 2;
void gmshViewGetValue(tag, x, y, z, step, &vector_double); }
void gmshViewGetRawData(tag, &double_vector); PViewDataList *d = dynamic_cast<PViewDataList*>(view->getData());
void gmshViewSetRawData(tag, const &double_vector); if(!d){ // change the view type
*/ std::string name = view->getData()->getName();
delete view->getData();
d = new PViewDataList();
d->setName(name);
d->setFileName(name + ".pos");
view->setData(d);
}
const char *types[] = {"SP", "VP", "TP", "SL", "VL", "TL", "ST", "VT", "TT",
"SQ", "VQ", "TQ", "SS", "VS", "TS", "SH", "VH", "TH",
"SI", "VI", "TI", "SY", "VY", "TY"};
for(int idxtype = 0; idxtype < 24; idxtype++){
if(type == types[idxtype]){
d->importList(idxtype, numEle, data, true);
return;
}
}
Msg::Error("Unknown data type for list import");
throw 2;
#else
Msg::Error("Views require the post-processing module");
throw -1;
#endif
}
void gmshViewProbe(const int tag, const double x, const double y,
const double z, std::vector<double> &value,
const int step, const int numComp,
const bool gradient, const double tolerance,
const std::vector<double> xElemCoord,
const std::vector<double> yElemCoord,
const std::vector<double> zElemCoord)
{
if(!_isInitialized()){ throw -1; }
#if defined(HAVE_POST)
PView *view = PView::getViewByTag(tag);
if(!view){
Msg::Error("Unknown view with tag %d", tag);
throw 2;
}
PViewData *data = view->getData();
if(!data){ throw 2; }
value.clear();
std::vector<double> val(9 * data->getNumTimeSteps());
bool found = false;
int qn = 0;
double *qx = 0, *qy = 0, *qz = 0;
if(xElemCoord.size() && yElemCoord.size() && zElemCoord.size() &&
xElemCoord.size() == yElemCoord.size() &&
xElemCoord.size() == zElemCoord.size()){
qn = xElemCoord.size();
qx = (double*)&xElemCoord[0];
qy = (double*)&yElemCoord[0];
qz = (double*)&zElemCoord[0];
}
switch(numComp){
case 1:
found = data->searchScalarWithTol
(x, y, z, &val[0], step, 0, tolerance, qn, qx, qy, qz, gradient);
break;
case 3:
found = data->searchVectorWithTol
(x, y, z, &val[0], step, 0, tolerance, qn, qx, qy, qz, gradient);
break;
case 9:
found = data->searchTensorWithTol
(x, y, z, &val[0], step, 0, tolerance, qn, qx, qy, qz, gradient);
break;
default:
found = data->searchScalarWithTol
(x, y, z, &val[0], step, 0, tolerance, qn, qx, qy, qz, gradient);
if(!found)
found = data->searchVectorWithTol
(x, y, z, &val[0], step, 0, tolerance, qn, qx, qy, qz, gradient);
if(!found)
found = data->searchTensorWithTol
(x, y, z, &val[0], step, 0, tolerance, qn, qx, qy, qz, gradient);
break;
}
if(found)
value.insert(value.end(), val.begin(), val.end());
#else
Msg::Error("Views require the post-processing module");
throw -1;
#endif
}
void gmshViewExport(const int tag, const std::string &fileName, void gmshViewExport(const int tag, const std::string &fileName,
const bool append) const bool append)
......
...@@ -811,6 +811,26 @@ GMSH_API void gmshViewAddModelData(const int tag, const std::string &modelName, ...@@ -811,6 +811,26 @@ GMSH_API void gmshViewAddModelData(const int tag, const std::string &modelName,
const int numComponents = -1, const int numComponents = -1,
const int partition = 0); const int partition = 0);
// Adds list-based post-processing data to the view with tag `tag'. `type'
// identifies the data: "SP" for scalar points, "VP", for vector points,
// etc. `numEle' gives the number of elements in the data. `data' contains the
// data for the `numEle' elements.
GMSH_API void gmshViewAddListData(const int tag, const std::string &type,
const int numEle, const std::vector<double> &data);
// Probes the view `tag' for its `value' at point (`x', `y', `z').
GMSH_API void gmshViewProbe(const int tag, const double x, const double y,
const double z, std::vector<double> &value,
const int step = -1, const int numComp = -1,
const bool gradient = false,
const double tolerance = 0.,
const std::vector<double> xElemCoord
= std::vector<double>(),
const std::vector<double> yElemCoord
= std::vector<double>(),
const std::vector<double> zElemCoord
= std::vector<double>());
// Exports the view to a file. The export format is determined by the file // Exports the view to a file. The export format is determined by the file
// extension. // extension.
GMSH_API void gmshViewExport(const int tag, const std::string &fileName, GMSH_API void gmshViewExport(const int tag, const std::string &fileName,
......
...@@ -137,6 +137,7 @@ class PViewDataList : public PViewData { ...@@ -137,6 +137,7 @@ class PViewDataList : public PViewData {
bool forceNodeData=false, bool forceElementData=false); bool forceNodeData=false, bool forceElementData=false);
virtual void importLists(int N[24], std::vector<double> *V[24]); virtual void importLists(int N[24], std::vector<double> *V[24]);
virtual void getListPointers(int N[24], std::vector<double> *V[24]); virtual void getListPointers(int N[24], std::vector<double> *V[24]);
void importList(int index, int n, const std::vector<double> &v, bool finalize);
}; };
#endif #endif
...@@ -723,6 +723,21 @@ void PViewDataList::importLists(int N[24], std::vector<double> *V[24]) ...@@ -723,6 +723,21 @@ void PViewDataList::importLists(int N[24], std::vector<double> *V[24])
finalize(); finalize();
} }
void PViewDataList::importList(int index, int n, const std::vector<double> &v,
bool fin)
{
if(index < 0 || index >= 24){
Msg::Error("Wrong list index to import");
return;
}
std::vector<double> *list = 0;
int *nbe = 0, nbc, nbn;
_getRawData(index, &list, &nbe, &nbc, &nbn);
*nbe = n;
*list = v; // deep copy
if(fin) finalize();
}
void PViewDataList::getListPointers(int N[24], std::vector<double> *V[24]) void PViewDataList::getListPointers(int N[24], std::vector<double> *V[24])
{ {
for(int i = 0; i < 24; i++){ for(int i = 0; i < 24; i++){
......
#include <gmsh.h>
int main(int argc, char **argv)
{
gmshInitialize();
gmshOptionSetNumber("General.Terminal", 1);
std::vector<double> tri1 = {0., 1., 1.,
0., 0., 1.,
0., 0., 0.};
std::vector<double> tri2 = {0., 1., 0.,
0., 1., 1.,
0., 0., 0.};
for(int step = 0; step < 10; step++){
tri1.push_back(10.);
tri1.push_back(10.);
tri1.push_back(12. + step);
tri2.push_back(10.);
tri2.push_back(12. + step);
tri2.push_back(13. + step);
}
int t = gmshViewCreate("some data");
std::vector<double> data;
data.insert(data.end(), tri1.begin(), tri1.end());
data.insert(data.end(), tri2.begin(), tri2.end());
gmshViewAddListData(t, "ST", 2, data);
gmshViewExport(t, "data.pos");
gmshFinalize();
return 0;
}
#!/usr/bin/env python
from gmsh import *
import sys
gmshInitialize(sys.argv)
gmshOptionSetNumber("General.Terminal", 1)
tri1 = [0., 1., 1.,
0., 0., 1.,
0., 0., 0.];
tri2 = [0., 1., 0.,
0., 1., 1.,
0., 0., 0.];
for step in range(0, 10):
tri1.append(10.); tri1.append(10.); tri1.append(12. + step)
tri2.append(10.); tri2.append(12. + step); tri2.append(13. + step)
t = gmshViewCreate("some data")
gmshViewAddListData(t, "ST", 2, tri1 + tri2)
gmshViewExport(t, "data.pos")
gmshFinalize()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment