PView *GMSH_Scal2VecPlugin::execute(PView *v) { // Load options int iView[3]; for (int comp=0; comp<3; comp++) iView[comp] = (int)Scal2VecOptions_Number[comp].def; // Load data PView *vRef=0, *vComp[3]; for (int comp=0; comp<3; comp++) { if (iView[comp]<0) vComp[comp] = 0; else { vComp[comp] = getView(iView[comp], v); if (!vComp[comp]) { Msg::Error("Scal2Vec plugin could not find View '%i'", iView[comp]); return v; } if (!vRef) vRef = vComp[comp]; } } if (!vRef) { Msg::Error("Scal2Vec plugin could not find any view."); return v; } PViewData *dataRef = vRef->getData(); // Initialize the new view PView *vNew = new PView(); PViewDataList *dataNew = getDataList(vNew); int step0 = dataRef->getFirstNonEmptyTimeStep(); for (int ent=0; ent < dataRef->getNumEntities(step0); ent++) { for (int ele=0; ele < dataRef->getNumElements(step0, ent); ele++) { if (dataRef->skipElement(step0, ent, ele)) continue; int type = dataRef->getType(step0, ent, ele); int numNodes = dataRef->getNumNodes(step0, ent, ele); std::vector<double> *out = dataNew->incrementList(3, type, numNodes); // Pointer in data of the new view if (!out) continue; double x[8], y[8], z[8]; for (int nod=0; nod<numNodes; nod++) dataRef->getNode(step0, ent, ele, nod, x[nod], y[nod], z[nod]); int dim = dataRef->getDimension(step0, ent, ele); elementFactory factory; element *element = factory.create(numNodes, dim, x, y, z); if (!element) continue; for (int nod=0; nod<numNodes; nod++) out->push_back(x[nod]); // Save coordinates (x,y,z) for (int nod=0; nod<numNodes; nod++) out->push_back(y[nod]); for (int nod=0; nod<numNodes; nod++) out->push_back(z[nod]); for (int step=step0; step < dataRef->getNumTimeSteps(); step++) { if (!dataRef->hasTimeStep(step)) continue; for (int nod=0; nod<numNodes; nod++) { for (int comp=0; comp<3; comp++) { double val=0.; if(vComp[comp]) vComp[comp]->getData()->getValue(step, ent, ele, nod, 0, val); out->push_back(val); // Save value } } } delete element; } } for (int step=step0; step < dataRef->getNumTimeSteps(); step++) { if (!dataRef->hasTimeStep(step)) continue; dataNew->Time.push_back(dataRef->getTime(step)); } std::string nameNewView = Scal2VecOptions_String[0].def; dataNew->setName(nameNewView); dataNew->setFileName(nameNewView + ".pos"); dataNew->finalize(); return vNew; }
PView *GMSH_Scal2VecPlugin::execute(PView *v) { int iViewX = (int)Scal2VecOptions_Number[0].def; int iViewY = (int)Scal2VecOptions_Number[1].def; int iViewZ = (int)Scal2VecOptions_Number[2].def; std::string nameNewView = Scal2VecOptions_String[0].def; PView *vRef = 0, *vX = 0, *vY = 0, *vZ = 0; PViewData *dataRef = 0, *dataX = 0, *dataY = 0, *dataZ = 0; // Load data if(iViewX >= 0){ vX = getView(iViewX, v); if(!vX){ Msg::Error("Scal2Vec plugin could not find View X: %i", iViewX); return v; } dataX = vX->getData(); if(!vRef){ vRef = vX; dataRef = dataX; } } if(iViewY >= 0){ vY = getView(iViewY, v); if(!vY){ Msg::Error("Scal2Vec plugin could not find View Y: %i", iViewY); return v; } dataY = vY->getData(); if(!vRef){ vRef = vY; dataRef = dataY; } } if(iViewZ >= 0){ vZ = getView(iViewZ, v); if(!vZ){ Msg::Error("Scal2Vec plugin could not find View Z: %i", iViewZ); return v; } dataZ = vZ->getData(); if(!vRef){ vRef = vZ; dataRef = dataZ; } } if(!vRef){ Msg::Error("Scal2Vec plugin could not find any view.", iViewZ); return v; } // Initialize the new view PView *vNew = new PView(); PViewDataList *dataNew = getDataList(vNew); for(int ent = 0; ent < dataRef->getNumEntities(0); ent++){ for(int ele = 0; ele < dataRef->getNumElements(0, ent); ele++){ if(dataRef->skipElement(0, ent, ele)) continue; int numComp = 3; // The 3 components of the new view: x,y,z int type = dataRef->getType(0, ent, ele); int numNodes = dataRef->getNumNodes(0, ent, ele); std::vector<double> *out = dataNew->incrementList(numComp, type, numNodes); // Pointer in data of the new view if(!out) continue; double x[8], y[8], z[8], valX, valY, valZ; for(int nod = 0; nod < numNodes; nod++) dataRef->getNode(0, ent, ele, nod, x[nod], y[nod], z[nod]); int dim = dataRef->getDimension(0, ent, ele); elementFactory factory; element *element = factory.create(numNodes, dim, x, y, z); if(!element) continue; for(int nod = 0; nod < numNodes; nod++) out->push_back(x[nod]); // Save coordinates (x,y,z) for(int nod = 0; nod < numNodes; nod++) out->push_back(y[nod]); for(int nod = 0; nod < numNodes; nod++) out->push_back(z[nod]); for(int step = 0; step < dataRef->getNumTimeSteps(); step++){ for(int nod = 0; nod < numNodes; nod++){ if(vX) dataX->getValue(step, ent, ele, nod, 0, valX); else valX = 0; if(vY) dataY->getValue(step, ent, ele, nod, 0, valY); else valY = 0; if(vZ) dataZ->getValue(step, ent, ele, nod, 0, valZ); else valZ = 0; out->push_back(valX); // Save values (fx,fy,fz) out->push_back(valY); out->push_back(valZ); } } delete element; } } for(int step = 0; step < dataRef->getNumTimeSteps(); step++){ if(dataRef->hasTimeStep(step)){ double time = dataRef->getTime(step); dataNew->Time.push_back(time); } } dataNew->setName(nameNewView); dataNew->setFileName(nameNewView + ".pos"); dataNew->finalize(); return vNew; }
PView *GMSH_LevelsetPlugin::execute(PView *v) { // for adapted views we can only run the plugin on one step at a time if(v->getData()->getAdaptiveData()){ PViewOptions *opt = v->getOptions(); v->getData()->getAdaptiveData()->changeResolution (opt->timeStep, _recurLevel, _targetError, this); v->setChanged(true); } PViewData *vdata = getPossiblyAdaptiveData(v), *wdata; if(_valueView < 0) { wdata = vdata; } else if(_valueView > (int)PView::list.size() - 1){ Msg::Error("View[%d] does not exist: reverting to View[%d]", _valueView, v->getIndex()); wdata = vdata; } else{ wdata = getPossiblyAdaptiveData(PView::list[_valueView]); } // sanity checks if(vdata->getNumEntities() != wdata->getNumEntities() || vdata->getNumElements() != wdata->getNumElements()){ Msg::Error("Incompatible views"); return v; } if(_valueTimeStep >= wdata->getNumTimeSteps()) { Msg::Error("Wrong time step %d in view", _valueTimeStep); return v; } // Force creation of one view per time step if we have multi meshes if(vdata->hasMultipleMeshes()) _valueIndependent = 0; double x[8], y[8], z[8], levels[8]; double scalarValues[8] = {0., 0., 0., 0., 0., 0., 0., 0.}; if(_valueIndependent) { // create a single output view containing the (possibly // multi-step) levelset int firstNonEmptyStep = vdata->getFirstNonEmptyTimeStep(); PViewDataList *out = getDataList(new PView()); for(int ent = 0; ent < vdata->getNumEntities(firstNonEmptyStep); ent++){ for(int ele = 0; ele < vdata->getNumElements(firstNonEmptyStep, ent); ele++){ if(vdata->skipElement(firstNonEmptyStep, ent, ele)) continue; for(int nod = 0; nod < vdata->getNumNodes(firstNonEmptyStep, ent, ele); nod++){ vdata->getNode(firstNonEmptyStep, ent, ele, nod, x[nod], y[nod], z[nod]); levels[nod] = levelset(x[nod], y[nod], z[nod], 0.); } _cutAndAddElements(vdata, wdata, ent, ele, -1, _valueTimeStep, x, y, z, levels, scalarValues, out); } } out->setName(vdata->getName() + "_Levelset"); out->setFileName(vdata->getFileName() + "_Levelset.pos"); out->finalize(); } else{ // create one view per timestep for(int step = 0; step < vdata->getNumTimeSteps(); step++){ if(!vdata->hasTimeStep(step)) continue; PViewDataList *out = getDataList(new PView()); for(int ent = 0; ent < vdata->getNumEntities(step); ent++){ for(int ele = 0; ele < vdata->getNumElements(step, ent); ele++){ if(vdata->skipElement(step, ent, ele)) continue; for(int nod = 0; nod < vdata->getNumNodes(step, ent, ele); nod++){ vdata->getNode(step, ent, ele, nod, x[nod], y[nod], z[nod]); vdata->getScalarValue(step, ent, ele, nod, scalarValues[nod]); levels[nod] = levelset(x[nod], y[nod], z[nod], scalarValues[nod]); } int wstep = (_valueTimeStep < 0) ? step : _valueTimeStep; _cutAndAddElements(vdata, wdata, ent, ele, step, wstep, x, y, z, levels, scalarValues, out); } } char tmp[246]; sprintf(tmp, "_Levelset_%d", step); out->setName(vdata->getName() + tmp); out->setFileName(vdata->getFileName() + tmp + ".pos"); out->finalize(); } } return 0; }