fluidControlWidget::fluidControlWidget(QWidget *parent) : QWidget(parent) { mySimulation = NULL; animationTimer = new QTimer(this); connect( animationTimer, SIGNAL(timeout()), this, SLOT(doAnimation()) ); //setUp Gui QPushButton * but_resetFlux = new QPushButton("Reset Flux!"); connect(but_resetFlux, SIGNAL(released()), this, SLOT(resetToCollectedFlux())); //QPushButton * butt_defForce = new QPushButton("Define Force!"); //connect(butt_defForce, SIGNAL(released()), this, SLOT(setForceFlux())); //QPushButton * butt = new QPushButton("Flux 2 Vorticity 2 Flux!"); //connect(butt, SIGNAL(released()), this, SLOT(flux2vort2flux())); QPushButton * butt_simStep = new QPushButton("Do 1 Timestep"); connect(butt_simStep, SIGNAL(released()), this, SLOT(singleSimulationStep())); QPushButton * butt_startSim = new QPushButton("Start/Stop Simulation"); connect(butt_startSim , SIGNAL(released()), this, SLOT(startSim())); QPushButton * but_borderconstr = new QPushButton("Define Border Constraints");//"Debug (harmonic flow)!"); connect(but_borderconstr , SIGNAL(released()), this, SLOT(debugSome())); QPushButton * debug2 = new QPushButton("Debug (pathtracing/vorts)!"); connect(debug2 , SIGNAL(released()), this, SLOT(debugSome2())); stepSliderLabel = new QLabel("Timestep Size ()"); viscosityLabel = new QLabel("Viscosity [0,10]"); forceAgeLabel = new QLabel("ForceAge (nr Iteratons): "); forceStrengthLabel = new QLabel("Force Strength (): "); stepSlider = new QSlider(Qt::Horizontal, this); stepSlider->setMinimum(0); stepSlider->setMaximum(1000); stepSlider->setTickPosition(QSlider::TicksAbove); stepSlider->setValue(0); connect(stepSlider,SIGNAL(sliderReleased()), this, SLOT(updateTimeStep())); viscositySlider = new QSlider(Qt::Horizontal, this); viscositySlider->setMinimum(0); viscositySlider->setMaximum(200); viscositySlider->setTickPosition(QSlider::TicksAbove); viscositySlider->setValue(0); connect(viscositySlider,SIGNAL(sliderReleased()), this, SLOT(updateViscosity())); forceAgeSlider = new QSlider(Qt::Horizontal, this); forceAgeSlider->setMinimum(0); forceAgeSlider->setMaximum(100); forceAgeSlider->setTickPosition(QSlider::TicksAbove); forceAgeSlider->setValue(5); connect(forceAgeSlider,SIGNAL(sliderReleased()), this, SLOT(forceAgeChanged())); forceAgeChanged(); forceStrengthSlider = new QSlider(Qt::Horizontal, this); forceStrengthSlider->setMinimum(0); forceStrengthSlider->setMaximum(480); forceStrengthSlider->setTickPosition(QSlider::TicksAbove); forceStrengthSlider->setValue(80); connect(forceStrengthSlider,SIGNAL(sliderReleased()), this, SLOT(forceStrengthChanged())); forceStrengthChanged(); // viscosityAndTimestep = new QLabel(""); // updateViscTimeLabel(); animationLabel = new QLabel(""); vectorInput = new QLineEdit(); vectorInput->setText(""); //vectorInput->setInputMask("#09.00 #09.00 #09.00"); connect(vectorInput,SIGNAL(textChanged( const QString& )), this, SLOT(borderDirInput(const QString & ))); ////////////////////////////////////////////////////////////////////////// //display settings ////////////////////////////////////////////////////////////////////////// QCheckBox * showStreamLines; QCheckBox * doInterpolation; QCheckBox * showVortNotSpeed; QCheckBox * texLine; showStreamLines = new QCheckBox(); showStreamLines->setChecked(false); connect(showStreamLines, SIGNAL(stateChanged(int)), this, SLOT(showStreamLn(int))); doInterpolation = new QCheckBox(); doInterpolation->setChecked(true); connect(doInterpolation, SIGNAL(stateChanged(int)), this, SLOT(doInterpl(int))); showVortNotSpeed = new QCheckBox(); showVortNotSpeed->setChecked(true); connect(showVortNotSpeed, SIGNAL(stateChanged(int)), this, SLOT(showVorticity(int))); texLine = new QCheckBox(); texLine->setChecked(true); connect(texLine, SIGNAL(stateChanged(int)), this, SLOT(showTexLines(int))); QLabel * streamLinesInterpolationLable = new QLabel("Lines/Interpol/Linelength/Vort/Tex/Color"); QSpinBox * lineLength = new QSpinBox(this); lineLength->setMinimum(1); lineLength->setMaximum(50); lineLength->setSingleStep(1); connect(lineLength, SIGNAL(valueChanged(int)), this, SLOT(streamLineLengthChanged(int))); QSpinBox * colorScale = new QSpinBox(this); colorScale->setMinimum(1); colorScale->setMaximum(100); colorScale->setSingleStep(1); colorScale->setValue(50); connect(colorScale, SIGNAL(valueChanged(int)), this, SLOT(colorScaleChanged(int))); QVBoxLayout * layout = new QVBoxLayout(); layout->addWidget(animationLabel); layout->addWidget(vectorInput); layout->addWidget(but_borderconstr); //layout->addWidget(butt); //layout->addWidget(butt_defForce); layout->addWidget(butt_startSim); layout->addWidget(but_resetFlux); layout->addWidget(butt_simStep); layout->addWidget(stepSliderLabel); layout->addWidget(stepSlider); layout->addWidget(viscosityLabel); layout->addWidget(viscositySlider); layout->addWidget(forceAgeLabel); layout->addWidget(forceAgeSlider); layout->addWidget(forceStrengthLabel); layout->addWidget(forceStrengthSlider); // layout->addWidget(viscosityAndTimestep); layout->addWidget(streamLinesInterpolationLable); QHBoxLayout * hlayout = new QHBoxLayout(); hlayout->addWidget(showStreamLines); hlayout->addWidget(doInterpolation); hlayout->addWidget(lineLength); hlayout->addWidget(showVortNotSpeed); hlayout->addWidget(texLine); hlayout->addWidget(colorScale); layout->addLayout(hlayout); layout->addWidget(debug2); QPushButton * dbg1 = new QPushButton("PathTr"); connect(dbg1 , SIGNAL(released()), this, SLOT(pathtrace())); QPushButton * dbg2= new QPushButton("VortPart"); connect(dbg2 , SIGNAL(released()), this, SLOT(showVorticityPart())); QHBoxLayout * hlayout2 = new QHBoxLayout(); hlayout2->addWidget(dbg1); hlayout2->addWidget(dbg2); layout->addLayout(hlayout2); this->setLayout(layout); Model::getModel()->attach(this); this->selectedBorder = 0; for(int i = 0; i < Model::getModel()->getMeshInfo()->getBorder().size(); i++){ borderConstrDirs.push_back(tuple3f()); } }
// calling the boids simulation function MThreadRetVal tBoidsDll(void *data) { DLLData * d=(DLLData*)data; d->result=startSim(); return (MThreadRetVal)0; }
void ReadITT::postInst() { startSim(); }
int Fenfloss::compute(const char *) { dprintf(1, "Fenfloss::compute\n"); int reattach = !strcmp(s_ConnectionMethod[p_ConnectionMethod->getValue()], "reattach"); if (reattach) { p_ConnectionMethod->setValue(0); stepNo = -1; } // Start: gettime int numElem; if (stepNo==0) { stepNo=1; return STOP_PIPELINE; } // Find out, whether we have to re-start sim use_boco2 = 0; coDoSet *grid = (coDoSet*) p_grid->getCurrentObject(); coDoSet *boco = (coDoSet*) p_boco->getCurrentObject(); coDoSet *boco2 = (coDoSet*) p_boco2->getCurrentObject(); if (reattach) d_distGridName = strdup(grid->getName()); // fl: debug grid->getAllElements(&numProc); dprintf(4, " Fenfloss::compute(const char *): grid: %s, %d\n", grid->getName(), numProc); if (grid) { dprintf(1, "Fenfloss::compute reset\n"); // we have a new grid input object const char *gridName = grid->getName(); if (strcmp(gridName,d_distGridName)!=0) { // sim currently running if (stepNo>=0) { #ifndef WIN32 //system("killall -KILL p_flow_4.8.2"); sleep(5); #endif resetSimLib(); stepNo=-1; } delete [] d_distGridName; d_distGridName = strcpy ( new char[strlen(gridName)+1] , gridName ); } } if ( (boco) && (!boco2) ) { // first run! using boco bc object sendInfo("no boco2 object, using boco object"); } if ( (boco) && (boco2) ) { // data on both boco-ports! const char *bocoName = boco->getName(); // check if there is new data from domain decomposition if ( strcmp(bocoName,d_distBocoName)!=0 ) { // no new data from domain decomposition sendInfo("simulation coupling! using boco2 bc object"); use_boco2 = 1; } else { // new data from domain decomposition sendInfo("new data from domain decomposition ..."); } } coDoPolygons *poly_in, *poly_out = NULL; int NumberOfPoints; int NumberOfVertices, NumberOfPolygons; float *inx_coord, *iny_coord, *inz_coord; int *invertices, *inpolygons; static int grid_size; // correct size of data arrays for visualization const coDistributedObject *const *gridArr = grid->getAllElements(&numProc); const coDistributedObject *const *bocoArr; const coDistributedObject *const **procGrid; const coDistributedObject *const **procBoco = 0; const coDoIntArr *gridDim; const coDoIntArr *bocoDim; if (stepNo<0) { //const char *dir; printf("Fenfloss::compute stepno < 0\n"); // get target directory //dir = p_dir->getValue(); // CHECK TYPES .. later if (!grid || !boco) { sendError("Data not received"); return FAIL; } if (!boco2) bocoArr = boco->getAllElements(&numProc); else bocoArr = boco2->getAllElements(&numProc); #ifndef DUMMY /////////////////////////////////////////////////////////////////////// // start simulation dprintf(0, "------------------starting simulation-------------------\n"); PrepareSimStart(numProc); if (startSim(reattach)) return -1; stepNo=0; #endif if (!reattach) { dprintf(2,"sending parameters ...\n"); int32 command; do { recvBS_Data(&command, sizeof(command)); char name[128]; dprintf(4,"command: %d\n",command); switch (command) { case GET_SC_PARA_FLO: case GET_V3_PARA_FLO: case GET_SC_PARA_INT: case GET_BOOL_PARA: case GET_TEXT_PARA: if (recvData((void*) name, 64) != 64) dprintf(0, "error in initial parameters\n"); break; case GET_INITIAL_PARA_DONE: break; default: dprintf(0, "error: unsupported parameter in initialization\n"); break; } switch (command) { case GET_SC_PARA_FLO: { coFloatParam *param = dynamic_cast<coFloatParam *>(findElem(name)); struct { float val ; int32 error; } ret = {0.0,0}; if (param) ret.val = param->getValue(); else if (!findAttribute(grid, name, "%f", (void *) &ret.val)) ret.error = -1; dprintf(4, "sending %f %d\n", ret.val, ret.error); sendBS_Data((void*) &ret, sizeof(ret)); break; } case GET_V3_PARA_FLO: { coFloatVectorParam *param = dynamic_cast<coFloatVectorParam *>(findElem(name)); struct { float val[3] ; int32 error; } ret; ret.error = 0; if (param) for(int i=0; i<3; i++) { ret.val[i] = param->getValue(i); dprintf(4,"param[%d]=%f\n",i,ret.val[i]); } else ret.error = -1; dprintf(4, "sending %f %d\n", ret.val[0], ret.error); sendBS_Data((void*) &ret, sizeof(ret)); break; } case GET_SC_PARA_INT: case GET_BOOL_PARA: { int val = 0; int error = 0; if (command == GET_SC_PARA_INT) { coIntScalarParam *param = dynamic_cast<coIntScalarParam *>(findElem(name)); if (param) val = param->getValue(); else if (!findAttribute(grid, name, "%d", (void *) &val)) error = -1; } else if (command == GET_BOOL_PARA) { coBooleanParam *param = dynamic_cast<coBooleanParam *>(findElem(name)); if (param) val = param->getValue(); else if (!findAttribute(grid, name, "%d", (void *) &val)) error = -1; } struct { int val; int32 error; } ret; ret.val = val; ret.error = error; dprintf(4, "sending int para %d %d\n", ret.val, ret.error); sendBS_Data((void*) &ret, sizeof(ret)); break; } case GET_TEXT_PARA: { coStringParam *param = dynamic_cast<coStringParam *>(findElem(name)); char res[256]; memset(res, 0, 256); if (param) { const char *val = param->getValue(); if (val) strncpy(res, val, 255); } else findAttribute(grid, name, "%s", (void *) res); sendData(res, 256); break; } default: break; } } while (command != GET_INITIAL_PARA_DONE); dprintf(2,"sending parameters ... done!\n"); } /////////////////////////////////////////////////////////////////////// // send dimensions int *idata,size=0; int i,j; procGrid = new const coDistributedObject *const*[numProc]; procBoco = new const coDistributedObject *const*[numProc]; for (i = 0; i < numProc; i++) { procGrid[i] = ((const coDoSet*)gridArr[i])->getAllElements(&numElem); gridDim = (coDoIntArr *) procGrid[i][0]; idata = gridDim->getAddress(); size = gridDim->getDimension(0) * sizeof(int); dprintf(1, "Fenfloss-Mod(%d): Compute(): Sending grid %d \n", __LINE__, size); dprintf(1, " sending %d %d %d %d\n", idata[0], idata[1], idata[2], idata[3]); if (!reattach) { struct commandMsg data = { GEO_DIM, size }; sendBS_Data(&data, sizeof(data)); if (size) sendBS_Data(idata,size); } } for (i = 0; i < numProc; i++) { procBoco[i] = ((const coDoSet*)bocoArr[i])->getAllElements(&numElem); bocoDim = (const coDoIntArr *) procBoco[i][0]; idata = bocoDim->getAddress(); size = bocoDim->getDimension(0) * sizeof(int); dprintf(2, "Fenfloss-Mod(%d): Compute(): Sending bc %d \n", __LINE__, size); if (!reattach) { struct commandMsg data = { BOCO_DIM, size }; sendBS_Data(&data, sizeof(data)); if (size) sendBS_Data(idata,size); } } /////////////////////////////////////////////////////////////////////// // send grids float *fdata; for (i = 0; i < numProc; i++) { coDoFloat *floatArr = (coDoFloat *) procGrid[i][1]; floatArr->getAddress(&fdata); size = floatArr->getNumPoints() * sizeof(float); if (size) { dprintf(1, "FenFloss-Mod(%d) GRID: Sending (cpu=%d), size = %d Bytes\n", __LINE__, i, size); if (!reattach) { struct { int command; int size; } data = { SEND_GEO, size }; sendBS_Data(&data, sizeof(data)); sendBS_Data(fdata,size); } } #ifdef DUMMY else testfile << " --- ignored one field" << endl; #endif // M. Becker: flow generates additional nodes // if we want to be sure that data and grid-arrays have the same length, // we have to shorten the data arrays (at the end of ::compute)! if (i == 0) { coDoIntArr *intArr = (coDoIntArr *) procGrid[i][0]; idata = intArr->getAddress(); grid_size = idata[1]; dprintf(1, "*************************** grid_size: %d\n", grid_size); } for (j = 2; j < 11; j++) { coDoIntArr *intArr = (coDoIntArr *) procGrid[i][j]; idata = intArr->getAddress(); size = intArr->getDimension(0) * sizeof(int); if (size) { dprintf(1, "FenFloss-Mod(%d) GRID: Sending (cpu=%d, j=%d), size = %d Bytes\n", __LINE__, i, j, size); dprintf(4," idata[0] = %d, idata[1] = %d, idata[2] = %d\n", idata[0], idata[1], idata[2]); if (!reattach) { sendBS_Data(idata,size); } } #ifdef DUMMY else testfile << " --- ignored one field" << endl; #endif } } /////////////////////////////////////////////////////////////////////// // send boco for (i = 0; i < numProc; i++) { if (!reattach) { struct { int command; int size; } data = { SEND_BOCO, size }; sendBS_Data(&data, sizeof(data)); } for (j = 1; j < 12; j++) { coDoIntArr *intArr = (coDoIntArr *) procBoco[i][j]; idata = intArr->getAddress(); size = intArr->getDimension(0) * sizeof(int); if (size) { // debug, fl: for(int k = 0; k < size/4; k++) { dprintf(3,"send boco(%2d,%2d): %8d\n",i,j,idata[k]); } dprintf(2, "FenFloss-Mod(%d) BC: Sending (cpu=%d, j=%d), size = %d Bytes\n", __LINE__, i, j, size); if (!reattach) { sendBS_Data(idata,size); } } #ifdef DUMMY else testfile << " --- ignored one field" << endl; #endif } for (j = 12; j < 13; j++) // displ_wert { sendInfo("Sending RB-Data ..."); coDoFloat *floatArr = (coDoFloat *) procBoco[i][j]; floatArr->getAddress(&fdata); size = floatArr->getNumPoints() * sizeof(float); if (size) { dprintf(2, "FenFloss-Mod(%d) BC: Sending (cpu=%d, j=%d), size = %d Bytes\n", __LINE__, i, j, size); if (!reattach) { sendBS_Data(fdata,size); } /*<tmp> if(j == 13) { sendInfo("Writing Diplacement-Data to file ..."); ofstream ofs("displwerte.debug"); for(int ji(0); ji<size; ji+=6) { ofs << fdata[ji] << " " << fdata[ji+1] << " " << fdata[ji+2] << " " << fdata[ji+3] << " " << fdata[ji+4] << " " << fdata[ji+5] << endl; } ofs.close(); } </tmp>*/ } #ifdef DUMMY else testfile << "--- ignored one field" << endl; #endif } } } /* endif(stepno < 0) */ #ifndef YAC executeCommands(); #endif numbc = 0; for (int j = 0; j < numbc && bcrad; j++) dprintf(4, "j=%d: bcrad=%f, bcvu=%f, bcvm=%f\n", j, bcrad[j], bcvu[j], bcvm[j]); if (use_boco2) { // use boco2 object (from Flowmid module)! bocoArr = boco2->getAllElements(&numProc); if (!boco2_num_int) { boco2_num_int = new int[numProc]; boco2_idata = new int*[numProc]; } // size for (int i = 0; i < numProc; i++) { if (boco2_idata[i]) delete [] boco2_idata[i]; procBoco[i] = ((coDoSet*)bocoArr[i])->getAllElements(&numElem); bocoDim = (coDoIntArr *) procBoco[i][0]; boco2_num_int[i] = bocoDim->getDimension(0); boco2_idata[i] = new int[boco2_num_int[i]]; memcpy(boco2_idata[i], bocoDim->getAddress(), boco2_num_int[i] * sizeof(int)); } if (!boco2_num_float) { boco2_num_float = new int[numProc]; boco2_fdata = new float*[numProc]; } ofstream debugfile; debugfile.open("boco2_bcin_data.txt"); // data for (int i=0;i<numProc;i++) { float *address; procBoco[i] = ((coDoSet*)bocoArr[i])->getAllElements(&numElem); coDoFloat *floatArr = (coDoFloat *) procBoco[i][13]; // displ_wert if (boco2_fdata[i]) delete [] boco2_fdata[i]; boco2_num_float[i] = floatArr->getNumPoints(); boco2_fdata[i] = new float[2 * boco2_num_float[i]]; // |displ_wert| == |pres_wert| ? floatArr->getAddress(&address); memcpy(boco2_fdata[i], address, boco2_num_float[i] * sizeof(float)); floatArr = (coDoFloat *) procBoco[i][14]; // pres_wert floatArr->getAddress(&address); memcpy(boco2_fdata[i] + boco2_num_float[i], address, boco2_num_float[i] * sizeof(float)); } /* for (int j=13;j<15;j++) // displ_wert, pres_wert { coDoFloat *floatArr = (coDoFloat *) procBoco[i][j]; floatArr->getAddress(&fdata); size = floatArr->getNumPoints() * sizeof(float); if (size) { printf("FenFloss-Mod(%d) BC: Sending (cpu=%d, j=%d), size = %d Bytes\n", __LINE__, i, j, size); sendBS_Data(fdata,size); } if (j==13) for (int k=0; k<size/4; k+=6) { debugfile << k/6 << " " << fdata[k] << " " << fdata[k+1] << " " << fdata[k+2] << " " << fdata[k+3] << " " << fdata[k+4] << " " << fdata[k+5] << endl; } debugfile.close(); #ifdef DUMMY else testfile << " --- ignored one field" << endl; #endif } } */ } ////////////////////////////// // we had to add to the spot point data, the description for // CollectTimeSteps and the Plot module // the output port for the VR Plugin poly_in = (coDoPolygons *)p_in_bcin->getCurrentObject(); if (poly_in) { NumberOfPoints = poly_in->getNumPoints(); NumberOfVertices = poly_in->getNumVertices(); NumberOfPolygons = poly_in->getNumPolygons(); poly_in->getAddresses(&inx_coord, &iny_coord, &inz_coord, &invertices, &inpolygons); poly_out = new coDoPolygons(p_out_bcin->getObjName(), NumberOfPoints, inx_coord, iny_coord, inz_coord, NumberOfVertices, invertices, NumberOfPolygons, inpolygons); poly_out->addAttribute("vertexOrder","1"); poly_out->addAttribute("COLOR","red"); p_out_bcin->setCurrentObject(poly_out); } #ifndef YAC coFeedback feedback("FenflossPlugin"); feedback.addPara(p_updateInterval); feedback.addPara(p_pauseSim); feedback.addPara(p_GetSimData); feedback.addPara(p_detachSim); feedback.addPara(p_useInitial); feedback.addPara(p_stopSim); if (poly_in) feedback.apply(poly_out); #endif // Flow knows now, that it has to send new simulation data if (p_GetSimData->getValue()) p_GetSimData->setValue(0); // push off button /* if (p_stopSim->getValue()) p_stopSim->setValue(0); // push off button */ // M. Becker 17.6.2002 // resize data arrays to fit with original created grid for visualization if (p_velocity->getCurrentObject()) // do this only if there is an object! { coDoVec3 *velo = (coDoVec3 *)p_velocity->getCurrentObject(); velo->setSize(grid_size); coDoFloat *press = (coDoFloat *)p_press->getCurrentObject(); press->setSize(grid_size); if (p_turb->getCurrentObject()) { coDoFloat *turb = (coDoFloat *)p_turb->getCurrentObject(); turb->setSize(grid_size); } } if (!p_velocity->getCurrentObject()) return STOP_PIPELINE; else return CONTINUE_PIPELINE; }