void StateRenderTest::Enter(beStateMachine* stateMachine) { auto renderInterface = m_appData->renderInterface; auto shaderPack = m_appData->shaderPack; shaderPack->UpdateFrameBuffers(renderInterface, m_camera.GetViewMatrix()); // Set ortho matrix buffer m_font.Init(renderInterface, shaderPack, "tutefont.txt", "tutefont.dds"); m_models.AddNew()->Init(renderInterface, shaderPack, "boar.dds"); m_models.AddNew()->InitWithFilename(renderInterface, shaderPack, "zombie/obj/zombie.obj", "zombie/obj/zombie.mtl", beModel::LoadOptions::Swizzle(beModel::LoadOptions::swizZ, beModel::LoadOptions::swizX, beModel::LoadOptions::swizY)); m_models.AddNew()->InitWithFilename(renderInterface, shaderPack, "cube.obj", "seafloor.dds", {}); m_models.AddNew()->InitWithFilename(renderInterface, shaderPack, "cube2.obj", "seafloor.dds", {}); m_models.AddNew()->InitWithFilename(renderInterface, shaderPack, "teapot.obj", "seafloor.dds", {beRendering::Topology::TriangleList, true, 1.f,{0,2,1}}); m_models.AddNew()->InitWithFilename(renderInterface, shaderPack, "boxes.obj", "barrels.dds", {beRendering::Topology::TriangleList, true, 0.1f,{0,2,1}}); InitGrid(renderInterface); beTexture::LoadOptions textureLoadOptions; textureLoadOptions.height = 256; textureLoadOptions.width = 256; textureLoadOptions.format = beTextureFormat::R32G32B32_FLOAT; m_screenGrabTexture.InitAsTarget(renderInterface, textureLoadOptions); m_bitmapTexQuadNorm.Init(renderInterface, shaderPack, 0.2f, 0.2f, "boar.dds"); m_bitmapTexQuadNorm.SetPosition(0.1f, 0.1f); m_bitmapTexQuadPixelCoord.Init(renderInterface, shaderPack, 128, 128, "bark.dds"); m_bitmapTexQuadPixelCoord.SetPosition(-0.8f, -0.5f); m_bitmapTextDynamic.SetColour(Vec4(0.f, 1.f, 0.8f, 1.f)); m_camera.AttachGamepad(m_appData->gamepad); m_camera.AttachMouse(m_appData->mouse); }
void MultiViewerMain::Connect(const char* a_strHost, const char* a_strPort, const char* a_strDBName, const char* a_strID, const char* a_strPassword, const char* a_strType) { #ifdef __CUBRID__SUPPORT__ if(strncmp(a_strType, CURBRID_TYPENAME , strlen(CURBRID_TYPENAME)) == 0) m_pSQLReader = new CubridReader(); else return; eDBReaderErr_t eDBReaderErr = m_pSQLReader->Connect(a_strHost, a_strPort, a_strDBName, a_strID, a_strPassword, NULL); if(eDBReaderSuccess != eDBReaderErr ) { ErrorDialog("Connect Error"); return; } m_eProgramState = eStateFileOpened; InitSQLTableInfo(); InitGrid(m_pTableDBDataGrid, true); m_bDirty = false; #else ErrorDialog("This version not support this action"); return; #endif }
void MultiViewerMain::Restore(VecArray2D<wxString>* a_p2DTableData, vector<wxString>* a_pColName, wxGrid* a_pwxGrid ,int a_nStartRow, int a_nEndRow) { int nStartRow = a_nStartRow; InitGrid(a_pwxGrid, true); unsigned int nRowTotal = a_nEndRow - a_nStartRow + 1; unsigned int nColTotal = a_p2DTableData->GetColSize(); a_pwxGrid->AppendRows(nRowTotal); a_pwxGrid->AppendCols(nColTotal); SetColHeader(a_pwxGrid, a_pColName ); unsigned int nCol = 0; unsigned int nRow = 0; for(nRow=0; nRow < nRowTotal ; nRow++ , nStartRow++) { for(nCol = 0; nCol < nColTotal ; nCol++) { wxString wstrData; wstrData = a_p2DTableData->GetData(nStartRow - 1, nCol); a_pwxGrid->SetCellValue(nRow, nCol, wstrData); } wxString wxstrRowNumber; wxstrRowNumber.Printf(_T("%d"), nStartRow); a_pwxGrid->SetRowLabelValue(nRow , wxstrRowNumber); } }
BOOL KSceneSettingDialogV2::OnInitDialog() { BOOL bRet = CDialog::OnInitDialog(); ///³õʼ»¯Grid /*{ TypeGridCtrl::InitAppearanceStruct InitStruct; InitStruct.m_nRowCount = 10; InitStruct.m_nColumnCount = 2; InitStruct.m_nFixedRowCount = 1; InitStruct.m_nFixedColumnCount = 0; InitStruct.m_nDefColumnWidth = 100; InitStruct.m_nFixedColumnWidth = 100; InitStruct.m_nDefRowHeight = 15; InitStruct.m_bEditEnable = true; InitStruct.m_bInitBasicTitles = false; InitStruct.m_bEnableHightLighFixed = false; InitStruct.m_bSingleRowSelection = true; InitStruct.m_bSingleColomnSelection = true; InitStruct.m_bEnableRowResize = false; InitStruct.m_bEnableColResize = true; InitStruct.m_csCornerDescription = _T(""); m_GridCtrl.InitAppearance(&InitStruct); }*/ InitGrid(); return bRet; }
CurveEditor::CurveEditor(MyGUI::Widget* _parent) { initialiseByAttributes(this, _parent); mEditTimeEditBox->setEditReadOnly(true); mEditValueEditBox->setEditReadOnly(true); mRangeMinEditBox->eventKeyLostFocus += MyGUI::newDelegate(this, &CurveEditor::NotifyRangeLostFocus); mRangeMinEditBox->eventEditSelectAccept += MyGUI::newDelegate(this, &CurveEditor::NotifyRangeEditAccept); mRangeMaxEditBox->eventKeyLostFocus += MyGUI::newDelegate(this, &CurveEditor::NotifyRangeLostFocus); mRangeMaxEditBox->eventEditSelectAccept += MyGUI::newDelegate(this, &CurveEditor::NotifyRangeEditAccept); MyGUI::PolygonalSkin::CreateLineSets = false; MyGUI::Widget* widget = mCurveCanvasWidget->createWidget<MyGUI::Widget>("PolygonalSkin", MyGUI::IntCoord(MyGUI::IntPoint(), mCurveCanvasWidget->getSize()), MyGUI::Align::Stretch); widget->setColour(MyGUI::Colour::Red); MyGUI::ISubWidget* main = widget->getSubWidgetMain(); mCurveLines = main->castType<MyGUI::PolygonalSkin>(); MyGUI::PolygonalSkin::CreateLineSets = true; widget = mCurveCanvasWidget->createWidget<MyGUI::Widget>("PolygonalSkin", MyGUI::IntCoord(MyGUI::IntPoint(), mCurveCanvasWidget->getSize()), MyGUI::Align::Stretch); widget->setColour(MyGUI::Colour::Red); main = widget->getSubWidgetMain(); mCurveCanvas = main->castType<MyGUI::PolygonalSkin>(); widget->eventMouseButtonPressed += MyGUI::newDelegate(this, &CurveEditor::NotifyMousePressed); MyGUI::PolygonalSkin::CreateLineSets = false; mCanvasWidget = widget; mCurveCanvas->setWidth(5.0f); std::vector<MyGUI::FloatPoint> mLinePoints; mLinePoints.push_back(MyGUI::FloatPoint(0, 0)); mLinePoints.push_back(MyGUI::FloatPoint(0, 1)); mCurveCanvas->setPoints(mLinePoints); mLinePoints.clear(); mCurveCanvas->setPoints(mLinePoints); // todo fix it mCurveLines->_setColour(MyGUI::Colour(0.2f, 0.2f, 0.2f)); // default range mValueRange.x = 0; mValueRange.y = 10; mRangeMinEditBox->setCaption("0"); mRangeMaxEditBox->setCaption("10"); InitGrid(); RefreshNumbers(); MyGUI::Window* window = mMainWidget->castType<MyGUI::Window>(false); if (window != nullptr) window->eventWindowButtonPressed += newDelegate(this, &CurveEditor::NotifyWindowButtonPressed); mSplineButton = mMainWidget->createWidget<MyGUI::Button>("CheckBox", MyGUI::IntCoord(15, 10, 95, 25), MyGUI::Align::Left | MyGUI::Align::Top); mSplineButton->setCaption("Use Spline"); mSplineButton->eventMouseButtonClick += MyGUI::newDelegate(this, &CurveEditor::NotifySplineChecked); }
void ConstructLocalGrid (long my_id) { Local[my_id].Local_Grid = InitGrid(my_id); /* Create the root box */ InsertParticlesInTree(my_id, MY_PARTICLES, MY_NUM_PARTICLES, Local[my_id].Local_Grid); /* Put all of your particles into your local tree */ }
void MultiViewerMain::FileNew(const char* a_strFileName ) { m_pSQLReader->FileNew(a_strFileName ); m_eProgramState = eStateFileOpened; InitSQLTableInfo(); InitGrid(m_pTableDBDataGrid, true); m_bDirty = false; }
Grid(const Grid& rhs) : index_translations(rhs.Indexing()), level(rhs.Level()), global(rhs.Global()), local(rhs.Local()), extent(rhs.Extent()), iterators(rhs.Iterators()), father(rhs.Father()) { InitGrid(); SetGrid(rhs); }
void MultiViewerMain::FileOpen(const char* a_strFileName ) { if(m_eProgramState == eStateFileOpened && m_bDirty) { // wxMessageBox(_("Test"), _("OnMenuFileOpen")); } m_pSQLReader->FileOpen(a_strFileName ); m_eProgramState = eStateFileOpened; InitSQLTableInfo(); InitGrid(m_pTableDBDataGrid, true); m_bDirty = false; }
Grid(const GlobalIndices& global_, const LocalIndices& local_, const SpatialExtent& extent_, int level_ = 0, Multigrid* father_ = NULL) : index_translations(this), level(level_), global(global_), local(local_), extent(extent_), iterators(local_), father(father_) { InitGrid(); }
void AstarPathfind::GenerateGrid(CMap* map) { grid.resize(map->GetNumOfTiles_MapHeight()); for(int i = 0; i < map->GetNumOfTiles_MapHeight(); ++i) { grid[i].resize(map->GetNumOfTiles_MapWidth()); for(int j = 0; j < map->GetNumOfTiles_MapWidth(); ++j) { PositionNode* positionNode = new PositionNode; grid[i][j] = positionNode; } } InitGrid(map); }
void GraphEditor::load(bool initgrid) // by default initgrid = true // when editing (erasing edges, vertices,reorienting) initgrid = false { if(!is_init) //MAC {gwp->canvas->setSceneRect(0,0,contentsRect().width(),contentsRect().height()); is_init=true; } //if(!is_init)return; clear();// delete all items if(gwp->pGG->nv() > staticData::MaxND) {Tprintf("Too big graph nv= %d (>%d)",gwp->pGG->nv(),staticData::MaxND);return;} GeometricGraph & G = *(gwp->pGG); if(initgrid) {Normalise(); InitGrid(current_grid); } DrawGrid(current_grid); if(ShowGrid)showGrid(true); Prop<NodeItem *> nodeitem(G.Set(tvertex()),PROP_CANVAS_ITEM,(NodeItem *)NULL); Prop<EdgeItem *> edgeitem(G.Set(tedge()),PROP_CANVAS_ITEM,(EdgeItem *)NULL); nodeitem.SetName("nodeitem");edgeitem.SetName("edgeitem"); for(tvertex v = 1;v <= G.nv();v++) nodeitem[v] = CreateNodeItem(v,gwp); for(tedge e = 1;e <= G.ne();e++) edgeitem[e] = CreateEdgeItem(e,gwp); if(staticData::ShowExtTbrin()) {tedge e = G.extbrin().GetEdge(); EdgeItem *edge = (G.extbrin() > 0) ? edgeitem[e] : edgeitem[e]->opp; edge->SetColor(color[Green],false); } Prop<bool> eoriented(G.Set(tedge()),PROP_ORIENTED,false); CreateColorItems(gwp,color_node,color_edge); G.vcolor.definit(color_node); G.vlabel.definit(0L); G.elabel.definit(0L); CreateThickItems(gwp,width_edge); G.ewidth.definit(width_edge); }
int main( int argc, char *argv[]) /* FinalApplication */ { time_t t0, t1, t_inter; time(&t0); fprintf(stdout,"Starting at: %s", asctime(localtime(&t0))); time(&t_inter); InitGrid("Particles.inp"); time(&t1); fprintf(stdout,"time spent on InitGrid(): %lf\n seconds",difftime(t1,t_inter)); // GenFieldGrid initialization printf("GeneratingField...\n"); time(&t_inter); GeneratingField(&GenFieldGrid,MaxIters); time(&t1); fprintf(stdout,"time spent on GeneratingField(): %lf\n seconds",difftime(t1,t_inter)); // Particle population initialization printf("ParticleGeneration...\n"); time(&t_inter); ParticleGeneration(GenFieldGrid, ParticleGrid, &Particles); time(&t1); fprintf(stdout,"time spent on ParticleGeneration(): %lf\n seconds",difftime(t1,t_inter)); // Compute evolution of the particle population printf("SystemEvolution...\n"); time(&t_inter); SystemEvolution(&ParticleGrid, &Particles, MaxSteps); time(&t1); fprintf(stdout,"time spent on SystemEvolution(): %lf\n seconds",difftime(t1,t_inter)); time(&t1); fprintf(stdout,"Ending at: %s", asctime(localtime(&t1))); fprintf(stdout,"Computations ended in %lf seconds\n",difftime(t1,t0)); fprintf(stdout,"End of program!\n"); return(0); } // end FinalApplication
void CNetworkControllView::OnInitialUpdate() { CFormView::OnInitialUpdate(); if(g_NetWorkLevel==1) { CAfxMessageDialog dlg; CString strPromption; strPromption.LoadString(IDS_STRNOPRIVILEGE); dlg.SetPromtionTxt(strPromption); dlg.DoModal(); } GetDlgItem(IDC_MacSTATIC)->ShowWindow(SW_HIDE); GetDlgItem(IDC_MACEDIT)->ShowWindow(SW_HIDE); GetDlgItem(IDC_GETBTN)->ShowWindow(SW_HIDE); GetDlgItem(IDC_SAVEBTN)->ShowWindow(SW_HIDE); GetDlgItem(IDC_FARCALLIP_BTN)->ShowWindow(SW_HIDE); /* GetDlgItem(IDC_GETBTN)->ShowWindow(SW_HIDE); GetDlgItem(IDC_SAVEBTN)->ShowWindow(SW_HIDE); GetDlgItem(IDC_REBOOTBTN)->ShowWindow(SW_HIDE); GetDlgItem(IDC_FARCALLBTN)->ShowWindow(SW_HIDE); GetDlgItem(IDC_FARCALLIP_BTN)->ShowWindow(SW_HIDE); */ SetTimer(1,20000,NULL); // TODO: Add your specialized code here and/or call the base class ////////////////////////////////////////////////////////////////////////// // init timesever combobox initTimeServerList(); InitGrid(); }
int main(int argc, char *argv[]) { int i,j,k,l,inmethod,outmethod,info,errorstat; int nogrids,nomeshes,nofile,dim,elementsredone=0; int nodes3d,elements3d,showmem; Real mergeeps; char prefix[MAXFILESIZE]; struct GridType *grids; struct CellType *cell[MAXCASES]; struct FemType data[MAXCASES]; struct BoundaryType *boundaries[MAXCASES]; struct ElmergridType eg; showmem = TRUE; printf("\nStarting program Elmergrid\n"); InitParameters(&eg); grids = (struct GridType*)malloc((size_t) (MAXCASES)*sizeof(struct GridType)); InitGrid(grids); info = TRUE; if(argc <= 1) { errorstat = LoadCommands(argv[1],&eg,grids,argc-1,info); Instructions(); if(errorstat) Goodbye(); } if(argc == 2) { errorstat = LoadCommands(argv[1],&eg,grids,argc-1,info); if(errorstat) Goodbye(); } else if(argc < 4) { Instructions(); Goodbye(); } else { errorstat = InlineParameters(&eg,argc,argv); if(errorstat) Goodbye(); } if(!eg.outmethod || !eg.inmethod) { printf("Please define the input and output formats\n"); } if(eg.inmethod != 1) { if(eg.outmethod == 1 || eg.outmethod == 8 || eg.outmethod == 9 || eg.outmethod == 10) { printf("input of type %d can't create output of type %d\n", eg.inmethod,eg.outmethod); errorstat++; Goodbye(); } } #if 0 if(eg.inmethod != 8 && eg.outmethod == 5) { printf("To write Easymesh format you need to read easymesh format!\n"); errorstat++; } #endif if(eg.timeron) timer_activate(eg.infofile); /**********************************/ printf("\nElmergrid loading data:\n"); printf( "-----------------------\n"); dim = eg.dim; nofile = 0; nomeshes = 0; nogrids = 0; inmethod = eg.inmethod; outmethod = eg.outmethod; read_another_file: timer_show(); switch (inmethod) { case 1: if(LoadElmergrid(&grids,&nogrids,eg.filesin[nofile],eg.relh,info) == 1) { if(dim == 3) ExampleGrid3D(&grids,&nogrids,info); if(dim == 2) ExampleGrid2D(&grids,&nogrids,info); if(dim == 1) ExampleGrid1D(&grids,&nogrids,info); SaveElmergrid(grids,nogrids,eg.filesin[nofile],info); printf("Because file %s didn't exist, it was created for you.\n",eg.filesin[nofile]); Goodbye(); } LoadCommands(eg.filesin[nofile],&eg,grids,2,info); break; case 2: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(LoadElmerInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info)) Goodbye(); nomeshes++; break; case 3: if(LoadSolutionElmer(&(data[nofile]),TRUE,eg.filesin[nofile],info)) Goodbye(); nomeshes++; break; case 4: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); if(LoadAnsysInput(&(data[0]),boundaries[0],eg.filesin[nofile],info)) Goodbye(); nomeshes++; break; case 5: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(LoadAbaqusInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 6: if(LoadAbaqusOutput(&(data[nofile]),eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 7: if(LoadFidapInput(&(data[nofile]),eg.filesin[nofile],TRUE)) Goodbye(); boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(0 && !eg.usenames) data[nofile].boundarynamesexist = data[nofile].bodynamesexist = FALSE; ElementsToBoundaryConditions(&(data[nofile]),boundaries[nofile],FALSE,TRUE); RenumberBoundaryTypes(&data[nofile],boundaries[nofile],TRUE,0,info); nomeshes++; break; case 8: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadUniversalMesh(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 9: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(LoadComsolMesh(&(data[nofile]),eg.filesin[nofile],info)) Goodbye(); ElementsToBoundaryConditions(&(data[nofile]),boundaries[nofile],FALSE,TRUE); nomeshes++; break; case 10: if(LoadFieldviewInput(&(data[nofile]),eg.filesin[nofile],TRUE)) Goodbye(); boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } ElementsToBoundaryConditions(&(data[nofile]),boundaries[nofile],FALSE,TRUE); nomeshes++; break; case 11: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadTriangleInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 12: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadMeditInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 13: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadGidInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 14: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadGmshInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 15: if(info) printf("Partitioned solution is fused on-the-fly therefore no other operations may be performed.\n"); FuseSolutionElmerPartitioned(eg.filesin[nofile],eg.filesout[nofile],eg.decimals,eg.partjoin, eg.saveinterval[0],eg.saveinterval[1],eg.saveinterval[2],info); if(info) printf("Finishing with the fusion of partitioned Elmer solutions\n"); Goodbye(); break; #if 0 case 16: InitializeKnots(&(data[nofile])); if( Easymesh(argc,argv,&data[nofile].noknots, &data[nofile].noelements,&sides)) Goodbye(); data[nofile].dim = 2; data[nofile].coordsystem = COORD_CART2; data[nofile].maxnodes = 3; AllocateKnots(&(data[nofile])); boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(EasymeshCopy(&(data[nofile]),boundaries[nofile])) Goodbye(); nomeshes++; break; #endif case 17: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadNastranInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 18: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(LoadCGsimMesh(&(data[nofile]),eg.filesin[nofile],info)) Goodbye(); nomeshes++; break; case 19: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadGeoInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; default: Instructions(); Goodbye(); } nofile++; if(nofile < eg.nofilesin) { printf("\nElmergrid loading data from another file:\n"); goto read_another_file; } /***********************************/ redoelements: printf("\nElmergrid creating and manipulating meshes:\n"); printf( "-------------------------------------------\n"); timer_show(); if(nogrids > nomeshes && outmethod != 1) { nomeshes = nogrids; for(k=0;k<nogrids;k++) { CreateCells(&(grids[k]),&(cell[k]),info); CreateKnots(&(grids[k]),cell[k],&(data[k]),0,0); boundaries[k] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(j=0;j<MAXBOUNDARIES;j++) { boundaries[k][j].created = FALSE; boundaries[k][j].nosides = FALSE; } if(grids[k].noboundaries > 0) { for(j=0;j<grids[k].noboundaries;j++) { if(grids[k].boundsolid[j] < 4) { CreateBoundary(cell[k],&(data[k]),&(boundaries[k][j]), grids[k].boundext[j],grids[k].boundint[j], 1,grids[k].boundtype[j]); } else { CreatePoints(cell[k],&(data[k]),&(boundaries[k][j]), grids[k].boundext[j],grids[k].boundint[j], grids[k].boundsolid[j],grids[k].boundtype[j]); } } } } } /* In some formats the dimension for curved 2D meshes seems to be set to 2. This should fix the problem for all input types. */ if( data->dim < 3 ) { data->dim = GetCoordinateDimension(data,info); } /* Make the discontinous boundary needed, for example, in poor thermal conduction */ for(k=0;k<nomeshes;k++) { if(!eg.discont) { for(j=0;j<grids[k].noboundaries;j++) if(grids[k].boundsolid[j] == 2) { eg.discontbounds[eg.discont] = grids[k].boundtype[j]; eg.discont++; } } if(eg.discont) { for(i=1;i<=eg.discont;i++) SetDiscontinuousBoundary(&(data[k]),boundaries[k],eg.discontbounds[i-1],2,info); } } /* Divide quadrilateral meshes into triangular meshes */ for(k=0;k<nomeshes;k++) if(nogrids && (eg.triangles || grids[k].triangles == TRUE)) { Real criticalangle; criticalangle = MAX(eg.triangleangle , grids[k].triangleangle); ElementsToTriangles(&data[k],boundaries[k],criticalangle,info); } /* Make a boundary layer with two different methods */ if(eg.layers > 0) for(k=0;k<nomeshes;k++) CreateBoundaryLayer(&data[k],boundaries[k],eg.layers, eg.layerbounds, eg.layernumber, eg.layerratios, eg.layerthickness, eg.layerparents, eg.layermove, eg.layereps, info); else if(eg.layers < 0) for(k=0;k<nomeshes;k++) CreateBoundaryLayerDivide(&data[k],boundaries[k],abs(eg.layers), eg.layerbounds, eg.layernumber, eg.layerratios, eg.layerthickness, eg.layerparents, info); /* Take up the infor on rotation */ for(k=0;k<nogrids;k++) if( grids[k].rotatecurve ) { eg.rotatecurve = TRUE; eg.curvezet = grids[k].curvezet; eg.curverad = grids[k].curverad; eg.curveangle = grids[k].curveangle; } if(outmethod != 1 && dim != 2 && eg.dim != 2) { j = MAX(nogrids,1); for(k=0;k<j;k++) { if(grids[k].dimension == 3 || grids[k].rotate) { boundaries[j] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) boundaries[j][i].created = FALSE; CreateKnotsExtruded(&(data[k]),boundaries[k],&(grids[k]), &(data[j]),boundaries[j],info); if(nogrids) { elements3d = MAX(eg.elements3d, grids[k].wantedelems3d); nodes3d = MAX(eg.nodes3d, grids[k].wantednodes3d); if(elements3d) { if( abs(data[j].noelements - elements3d) / (1.0*elements3d) > 0.01 && elementsredone < 5 ) { grids[k].wantedelems *= pow(1.0*elements3d / data[j].noelements, (2.0/3.0)); elementsredone++; } else elementsredone = 0; } else if(nodes3d) { if( abs(data[j].noknots - nodes3d) / (1.0*nodes3d) > 0.01 && elementsredone < 5 ) { grids[k].wantedelems *= pow(1.0*nodes3d / data[j].noknots, (2.0/3.0)); elementsredone++; } else elementsredone = 0; } if(elementsredone) { nomeshes = 0; for(i=0;i < nogrids;i++) SetElementDivision(&(grids[i]),eg.relh,info); DestroyKnots(&data[j]); DestroyKnots(&data[k]); free(cell[k]); if(info) printf("Iteration %d of elements number targiting %d in 2D\n", elementsredone,grids[k].wantedelems); goto redoelements; } } data[k] = data[j]; boundaries[k] = boundaries[j]; } } } /* If the original mesh was given in polar coordinates make the transformation into cartesian ones */ for(k=0;k<nomeshes;k++) { if(eg.polar || data[k].coordsystem == COORD_POLAR) { if(!eg.polar) eg.polarradius = grids[k].polarradius; PolarCoordinates(&data[k],eg.polarradius,info); } } /* If the original mesh was given in cylindrical coordinates make the transformation into cartesian ones */ for(k=0;k<nomeshes;k++) { if(eg.cylinder || data[k].coordsystem == COORD_CYL) { CylinderCoordinates(&data[k],info); } } if(1) for(k=0;k<nomeshes;k++) RotateTranslateScale(&data[k],&eg,info); /* Rotate may apply to 2d and 3d geometries as well */ for(k=0;k<nomeshes;k++) if(eg.rotatecurve) CylindricalCoordinateCurve(&data[k],eg.curvezet,eg.curverad,eg.curveangle); /* Unite meshes if there are several of them */ if(eg.unitemeshes) { for(k=1;k<nomeshes;k++) UniteMeshes(&data[0],&data[k],boundaries[0],boundaries[k],info); nomeshes = nogrids = 1; } if(eg.clone[0] || eg.clone[1] || eg.clone[2]) { for(k=0;k<nomeshes;k++) { CloneMeshes(&data[k],boundaries[k],eg.clone,eg.clonesize,FALSE,info); mergeeps = fabs(eg.clonesize[0]+eg.clonesize[1]+eg.clonesize[2]) * 1.0e-8; MergeElements(&data[k],boundaries[k],eg.order,eg.corder,mergeeps,TRUE,TRUE); } } if(eg.mirror[0] || eg.mirror[1] || eg.mirror[2]) { for(k=0;k<nomeshes;k++) { MirrorMeshes(&data[k],boundaries[k],eg.mirror,FALSE,eg.clonesize,eg.mirrorbc,info); mergeeps = fabs(eg.clonesize[0]+eg.clonesize[1]+eg.clonesize[2]) * 1.0e-8; MergeElements(&data[k],boundaries[k],eg.order,eg.corder,mergeeps,FALSE,TRUE); } } /* Naming convection for the case of several meshes */ if(nomeshes > 1) { strcpy(prefix,eg.filesout[0]); for(k=0;k<nomeshes;k++) sprintf(eg.filesout[k],"%s%d",prefix,k+1); } for(k=0;k<nomeshes;k++) { if(nogrids && grids[k].reduceordermatmax) { eg.reduce = TRUE; eg.reducemat1 = grids[k].reduceordermatmin; eg.reducemat2 = grids[k].reduceordermatmax; } if(eg.reduce) ReduceElementOrder(&data[k],eg.reducemat1,eg.reducemat2); } for(k=0;k<nomeshes;k++) if(eg.increase) IncreaseElementOrder(&data[k],TRUE); for(k=0;k<nomeshes;k++) { if(eg.merge) MergeElements(&data[k],boundaries[k],eg.order,eg.corder,eg.cmerge,FALSE,TRUE); else if(eg.order == 3) #if PARTMETIS ReorderElementsMetis(&data[k],TRUE); #else printf("Cannot order nodes by Metis as it is not even compiled!\n"); #endif else if(eg.order) ReorderElements(&data[k],boundaries[k],eg.order,eg.corder,TRUE); if(eg.isoparam) IsoparametricElements(&data[k],boundaries[k],TRUE,info); }
/************\ ** Solver *****************************************************\ ** ** ** Solver runs the sudoku solver. Input puzzle is in the ** ** buffer array, and somewhat controlled by a number of ** ** globals (see the globals at the top of the main program ** ** for globals and meanings). ** ** ** \****************************************************************/ int bb_solver(unsigned *puzzle) { register unsigned i; PuzSolCnt = 0; InitGrid(); for (i = 0; i < 81; i++) if (puzzle[i]) PushSingle((char)(i), V2B[puzzle[i]]); // Loop through the puzzle solving routines until finished while (Changed) { // If No Solution possible, jump straight to the backtrack routine if (!No_Sol) { // Check if any Singles to be propogated if (SingleCnt) { #ifdef CALC_STATS SCnt++; #endif if (SingleCnt > 2) // If multiple singles ProcessInitSingles(); // process them all at once if (SingleCnt) // otherwise ProcessSingles(); // process them one at a time if (!Gp->CellsLeft) { if (!No_Sol) { PuzSolCnt++; if (PuzSolCnt > 1) break; } No_Sol = Changed = 1; continue; } } // If nothing has changed, apply the next solver if (Changed) { #ifdef CALC_STATS HCnt++; #endif FindHiddenSingles(); if (SingleCnt) continue; // if (use_methods & USE_LOCK_CAND) { #ifdef CALC_STATS LCCnt++; #endif FindLockedCandidates(); if (Changed) continue; } } } //If nothing new found, just make a guess #ifdef CALC_STATS GCnt++; #endif MakeGuess(); if (No_Sol) break; // if (!initp && (MaxDepth < PIdx)) MaxDepth = PIdx; // if (PIdx > 62) { printf ("Max Depth exceeded, recompile for more depth.\n\n"); exit(0); } } #ifdef CALC_STATS TSCnt += SCnt; // Update Stats THCnt += HCnt; TGCnt += GCnt; TLCCnt += LCCnt; TSSCnt += SSCnt; TFCnt += FCnt; TOneCnt += OneCnt; TTwoCnt += TwoCnt; #endif return PuzSolCnt; }
int main(int argc, char **argv) { int nthreads = 0; pthread_t threads[MAXTHREADS]; grain_type rowGranularity = NONE; long initSum = 0, finalSum = 0; int i; if (argc > 3) { gridsize = atoi(argv[1]); if (gridsize > MAXGRIDSIZE || gridsize < 1) { printf("Grid size must be between 1 and 10.\n"); return(1); } nthreads = atoi(argv[2]); if (nthreads < 1 || nthreads > MAXTHREADS) { printf("Number of threads must be between 1 and 1000."); return(1); } if (argv[3][1] == 'r' || argv[3][1] == 'R') rowGranularity = ROW; if (argv[3][1] == 'c' || argv[3][1] == 'C') rowGranularity = CELL; if (argv[3][1] == 'g' || argv[3][1] == 'G') rowGranularity = GRID; } else { printf("Format: gridapp gridSize numThreads -cell\n"); printf(" gridapp gridSize numThreads -row\n"); printf(" gridapp gridSize numThreads -grid\n"); printf(" gridapp gridSize numThreads -none\n"); return(1); } printf("Initial Grid:\n\n"); initSum = InitGrid(grid, gridsize); PrintGrid(grid, gridsize); printf("\nInitial Sum: %d\n", initSum); printf("Executing threads...\n"); /* better to seed the random number generator outside of do swaps or all threads will start with same choice */ srand((unsigned int)time( NULL ) ); time(&start_t); for (i = 0; i < nthreads; i++) { if (pthread_create(&(threads[i]), NULL, do_swaps, (void *)(&rowGranularity)) != 0) { perror("thread creation failed:"); exit(-1); } } for (i = 0; i < nthreads; i++) pthread_detach(threads[i]); while (1) { sleep(2); if (threads_left == 0) { fprintf(stdout, "\nFinal Grid:\n\n"); PrintGrid(grid, gridsize); finalSum = SumGrid(grid, gridsize); fprintf(stdout, "\n\nFinal Sum: %d\n", finalSum); if (initSum != finalSum){ fprintf(stdout,"DATA INTEGRITY VIOLATION!!!!!\n"); } else { fprintf(stdout,"DATA INTEGRITY MAINTAINED!!!!!\n"); } fprintf(stdout, "Secs elapsed: %g\n", difftime(end_t, start_t)); exit(0); } } return(0); }
int main(int argc, char* argv[]) { int** grid; // grid containing the cells and whether they are alive or dead // set up curses for displaying the grid #ifdef USE_CURSES initscr(); if(has_colors()) { start_color(); init_pair(1, COLOR_BLACK, COLOR_WHITE); init_pair(2, COLOR_WHITE, COLOR_CYAN); } #endif // allocate the grid grid = AllocateGrid(); if(grid == NULL) { printf("ERROR: Could not allocate memory for grid\n"); return -1; } // initialize and print the grid InitGrid(grid); #ifdef PRINT_GRID PrintGrid(grid); #endif for(int time = 1; time <= TIME_STEPS; ++time) { // sleep to observe updates #ifdef PRINT_GRID usleep(SLEEP_TIME); #endif // allocate temporary grid for storing the simultaneous update int** tempGrid = AllocateGrid(); if(tempGrid == NULL) { printf("ERROR: Could not allocate memory for grid\n"); return -1; } for(int i = 0; i < GRID_SIZE; ++i) { for(int j = 0; j < GRID_SIZE; ++j) { int numNeighborAlive = 0; for(int k = -1; k <= 1; ++k) { for(int l = -1; l <= 1; ++l) { int row = (i + k) % GRID_SIZE; int col = (j + l) % GRID_SIZE; if(row == -1) row = GRID_SIZE - 1; if(col == -1) col = GRID_SIZE - 1; if( (row != i) || (col != j) ) numNeighborAlive += grid[row][col]; } } switch(numNeighborAlive) { case 2: tempGrid[i][j] = grid[i][j]; break; case 3: tempGrid[i][j] = 1; break; default: tempGrid[i][j] = 0; } } } free(grid); grid = tempGrid; #ifdef USE_CURSES move(0, 0); #endif #ifdef PRINT_GRID PrintGrid(grid); #endif } CountLive(grid); #ifdef USE_CURSES printw("\nPress any key to continue..."); refresh(); getchar(); #endif free(grid); #ifdef USE_CURSES endwin(); #endif return 0; }
SquareGrid::SquareGrid(unsigned int x, unsigned int y, const bool north_south = false, const bool east_west = false) : size_x_(x), size_y_(y), linked_north_south_(north_south), linked_east_west_(east_west) { InitGrid(); };
SquareGrid::SquareGrid() : size_x_(1), size_y_(1) { InitGrid(); };
int main(int argc, char **argv) { int nthreads = 0; #ifdef UNIX pthread_t threads[MAXTHREADS]; #endif UNIX grain_type rowGranularity = NONE; #ifdef WINDOWS HANDLE threads[MAXTHREADS]; #endif long initSum = 0, finalSum = 0; int i; if (argc > 3) { gridsize = atoi(argv[1]); if (gridsize > MAXGRIDSIZE || gridsize < 1) { printf("Grid size must be between 1 and 10.\n"); return(1); } nthreads = atoi(argv[2]); if (nthreads < 1 || nthreads > MAXTHREADS) { printf("Number of threads must be between 1 and 1000."); return(1); } if (argv[3][1] == 'r' || argv[3][1] == 'R') rowGranularity = ROW; if (argv[3][1] == 'c' || argv[3][1] == 'C') rowGranularity = CELL; if (argv[3][1] == 'g' || argv[3][1] == 'G') rowGranularity = GRID; } else { printf("Format: gridapp gridSize numThreads -cell\n"); printf(" gridapp gridSize numThreads -row\n"); printf(" gridapp gridSize numThreads -grid\n"); printf(" gridapp gridSize numThreads -none\n"); return(1); } printf("Initial Grid:\n\n"); initSum = InitGrid(grid, gridsize); PrintGrid(grid, gridsize); printf("\nInitial Sum: %d\n", initSum); printf("Executing threads...\n"); //initialize all the mutex we need #ifdef UNIX init_row_mutex(row_mutex, gridsize); init_cell_mutex(cell_mutex, gridsize); #endif #ifdef WINDOWS init_row_mutex(row_mutex, gridsize); init_cell_mutex(cell_mutex, gridsize); #endif /* better to seed the random number generator outside of do swaps or all threads will start with same choice */ srand((unsigned int)time( NULL ) ); time(&start_t); for (i = 0; i < nthreads; i++) { //create thread #ifdef UNIX if (pthread_create(&(threads[i]), NULL, do_swaps, (void *)(&rowGranularity)) != 0) { perror("thread creation failed:"); exit(-1); } #endif #ifdef WINDOWS threads[i]=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)do_swaps,(void*)(&rowGranularity), 0, NULL); #endif } for (i = 0; i < nthreads; i++) { #ifdef UNIX pthread_detach(threads[i]); #endif #ifdef WINDOWS for (i = 0; i < nthreads; i++) CloseHandle(threads[i]); #endif } while (1) { #ifdef UNIX sleep(2); #endif #ifdef WINDOWS _sleep(2000); #endif if (threads_left == 0) { fprintf(stdout, "\nFinal Grid:\n\n"); PrintGrid(grid, gridsize); finalSum = SumGrid(grid, gridsize); fprintf(stdout, "\n\nFinal Sum: %d\n", finalSum); if (initSum != finalSum){ fprintf(stdout,"DATA INTEGRITY VIOLATION!!!!!\n"); } else { fprintf(stdout,"DATA INTEGRITY MAINTAINED!!!!!\n"); } #ifdef UNIX fprintf(stdout, "Secs elapsed: %g\n", difftime(end_t, start_t)); #endif #ifdef WINDOWS printf("secs elapsed: %d\n", end_t - start_t); getchar(); #endif exit(0); } } //destroy the mutex we have created #ifdef UNIX pthread_mutex_destroy(&grid_mutex); pthread_mutex_destroy(&row_mutex); pthread_mutex_destroy(&lock_enter); pthread_mutex_destroy(&lock_exit); pthread_mutex_destroy(&cell_mutex); #endif #ifdef WIINDOWS CloseHandle(grid_mutex); CloseHandle(row_mutex); CloseHandle(lock_enter); CloseHandle(lock_exit); CloseHandle(cell_mutex); #endif system("pause"); return(0); }