Пример #1
0
void BrlcadReader::processStlFile(QString file_name, bool append_to_list)
{
  vtkSTLReader *stl = vtkSTLReader::New();
  stl->MergingOn();
  stl->SetFileName(file_name.toAscii().data());
  stl->Update();
  EG_VTKSP(vtkPolyData, poly);
  poly->DeepCopy(stl->GetOutput());
  poly->BuildCells();
  double L = 1e99;
  for (vtkIdType cellId = 0; cellId < poly->GetNumberOfCells(); ++cellId) {
    vtkIdType *pts, Npts;
    poly->GetCellPoints(cellId, Npts, pts);
    for (int i = 0; i < Npts; ++i) {
      vec3_t x1, x2;
      poly->GetPoints()->GetPoint(pts[i], x1.data());
      if (i == Npts - 1) {
        poly->GetPoints()->GetPoint(pts[0], x2.data());
      } else {
        poly->GetPoints()->GetPoint(pts[i+1], x2.data());
      }
      L = min(L, (x1-x2).abs());
    }
  }
  EG_VTKSP(vtkEgPolyDataToUnstructuredGridFilter, poly2ugrid);
  poly2ugrid->SetInput(poly);
  poly2ugrid->Update();

  EG_VTKSP(vtkUnstructuredGrid, grid);
  allocateGrid(grid, poly2ugrid->GetOutput()->GetNumberOfCells(), poly2ugrid->GetOutput()->GetNumberOfPoints());
  for (vtkIdType id_node = 0; id_node < poly2ugrid->GetOutput()->GetNumberOfPoints(); ++id_node) {
    vec3_t x;
    poly2ugrid->GetOutput()->GetPoints()->GetPoint(id_node, x.data());
    grid->GetPoints()->SetPoint(id_node, x.data());
  }
  for (vtkIdType id_cell = 0; id_cell < poly2ugrid->GetOutput()->GetNumberOfCells(); ++id_cell) {
    vtkIdType N_pts, *pts;
    vtkIdType type_cell = poly2ugrid->GetOutput()->GetCellType(id_cell);
    poly2ugrid->GetOutput()->GetCellPoints(id_cell, N_pts, pts);
    grid->InsertNextCell(type_cell, N_pts, pts);
  }

  EG_VTKDCC(vtkIntArray, cell_code, grid, "cell_code");
  EG_VTKDCC(vtkIntArray, orgdir,    grid, "cell_orgdir");
  EG_VTKDCC(vtkIntArray, voldir,    grid, "cell_voldir");
  EG_VTKDCC(vtkIntArray, curdir,    grid, "cell_curdir");
  for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) {
    cell_code->SetValue(id_cell, 9999);
    orgdir->SetValue(id_cell, 0);
    voldir->SetValue(id_cell, 0);
    curdir->SetValue(id_cell, 0);
  }

  if (append_to_list) {
    SetBoundaryCode set_bc;
    set_bc.setGrid(grid);
    set_bc.setAllSurfaceCells();
    int bc_max = 1;
    bool done = false;
    do {
      vtkIdType id_start = -1;
      for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) {
        if (cell_code->GetValue(id_cell) == 9999) {
          id_start = id_cell;
          break;
        }
      }
      if (id_start == -1) {
        done = true;
      } else {
        set_bc.setFeatureAngle(20.0);
        set_bc.setBC(bc_max);
        set_bc.setProcessAll(true);
        set_bc.setSelectAllVisible(false);
        set_bc.setOnlyPickedCell(false);
        set_bc.setOnlyPickedCellAndNeighbours(false);
        set_bc.setStart(id_start);
        set_bc();
        ++bc_max;
      }
    } while (!done);
    cout << "file: " << qPrintable(file_name) << endl;
    for (int bc = 1; bc < bc_max; ++bc) {
      QList<vtkIdType> cells;
      for (vtkIdType id_cell = 0; id_cell < grid->GetNumberOfCells(); ++id_cell) {
        if (cell_code->GetValue(id_cell) == bc) {
          cells.append(id_cell);
        }
      }
      vtkUnstructuredGrid *new_grid = vtkUnstructuredGrid::New();
      QString bc_txt;
      bc_txt.setNum(bc);
      if (bc_max >= 10) {
        bc_txt = bc_txt.rightJustified(2, '0');
      }
      QFileInfo file_info(file_name);
      m_BCNames[new_grid] = file_info.baseName() + "." + bc_txt;
      cout << "  " << qPrintable(file_info.baseName() + "." + bc_txt) << endl;
      makeCopy(grid, new_grid, cells);
      m_Grids.append(new_grid);
    }
  } else {
    makeCopy(grid, m_Grid);
  }
}
Пример #2
0
void GuiSetBoundaryCode::operate()
{
  m_ButtonGroup->checkedId();
  cout<<"buttongroup->checkedId()="<<m_ButtonGroup->checkedId()<<endl;

  //save settings
  QSettings local_qset("enGits","enGrid_GuisetBoundaryCode");
  local_qset.setValue("FeatureAngle", m_Ui.doubleSpinBoxFeatureAngle->value());
  local_qset.setValue("BoundaryCode", m_Ui.spinBoxBoundaryCode->value());
  local_qset.setValue("PickMethod", m_ButtonGroup->checkedId());
  
  SetBoundaryCode set_bc;
  set_bc.setGrid(m_Grid);
  set_bc.setAllSurfaceCells();
  if (m_RadioButtonAuto->isChecked()) {
    QSet <int> display_bcs;
    GuiMainWindow::pointer()->getDisplayBoundaryCodes(display_bcs);
    int bc = m_Ui.spinBoxBoundaryCode->value();
    EG_VTKDCC(vtkIntArray, cell_code, m_Grid, "cell_code");
    for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
      bc = max(bc, cell_code->GetValue(id_cell));
      if (display_bcs.contains(cell_code->GetValue(id_cell))) {
        cell_code->SetValue(id_cell, 9999);
      }
    }
    bool done = false;
    do {
      vtkIdType id_start = -1;
      for (vtkIdType id_cell = 0; id_cell < m_Grid->GetNumberOfCells(); ++id_cell) {
        if (cell_code->GetValue(id_cell) == 9999) {
          id_start = id_cell;
          break;
        }
      }
      if (id_start == -1) {
        done = true;
      } else {
        set_bc.setFeatureAngle(m_Ui.doubleSpinBoxFeatureAngle->value());
        set_bc.setNewBC(bc);
        set_bc.setProcessAll(false);
        set_bc.setSelectAllVisible(false);
        set_bc.setOnlyPickedCell(false);
        set_bc.setOnlyPickedCellAndNeighbours(false);
        set_bc.setStart(id_start);
        QString bc_name = GuiMainWindow::pointer()->getBC(bc).getName();
        if (bc_name == "unknown") {
          bc_name.setNum(bc);
          bc_name = "wall_" + bc_name.rightJustified(3, '0');
          BoundaryCondition sym_bc(bc_name, "wall", bc);
          GuiMainWindow::pointer()->setBC(bc, sym_bc);
        }
        set_bc();
        ++bc;
      }
    } while (!done);
  } else {
    if (0 <= mainWindow()->getPickedCell() && mainWindow()->getPickedCell() < GuiMainWindow::pointer()->getGrid()->GetNumberOfCells() ) {
      set_bc.setFeatureAngle(m_Ui.doubleSpinBoxFeatureAngle->value());
      set_bc.setNewBC(m_Ui.spinBoxBoundaryCode->value());

      set_bc.setProcessAll(m_ButtonGroup->button(1)->isChecked());
      set_bc.setSelectAllVisible(m_ButtonGroup->button(2)->isChecked());
      set_bc.setOnlyPickedCell(m_ButtonGroup->button(3)->isChecked());
      set_bc.setOnlyPickedCellAndNeighbours(m_ButtonGroup->button(4)->isChecked());

      cout << "GuiMainWindow::getPickedCell()=" << mainWindow()->getPickedCell() << endl;
      set_bc.setStart(mainWindow()->getPickedCell());
      set_bc();
    } else {
      EG_ERR_RETURN("Please select a cell first.");
    }
  }
}
Пример #3
0
void 
SkinMeme::set(Bsimplex* t, CWvec& bc) 
{
   set_track_simplex(t);
   set_bc(bc);
}
Пример #4
0
int main(int argc, char *argv[]) {
    int j;
    int n;
    int status;
    char directory[256],outputdir[256];



    if (argc > 4) {
        printf("Too many arguments.Only using first 3.\n");
    }
    n = atoi(argv[1]);
    time_step = atof(argv[2]);
    strcpy(directory,argv[3]);

    nb = 2;

    sprintf(outputdir,"%stemp_files/",directory);
    status = mkdir(outputdir,S_IRWXU | S_IRWXG | S_IRWXO);
    if (status == -33)  {
        printf("Status is -33 for some reason.\n");
    }
    //sprintf(param_fname,"%sparam_file.txt",directory);


    
    read_param_file(directory);
    nx = params.nx;
    ny = params.ny;
    nz = params.nz;
    CFL = params.cfl;
    IndirectTerm = params.indirect;

    size_x = nx;
    size_y = ny+2*NGHY;
    size_z = nz;
    stride = size_x*size_y;
    pitch = size_x;
    pitch2d = 0;
    //size_t double_to_int = sizeof(double)/sizeof(int);
    pitch2d_int = 0 ;//pitch*(int)double_to_int;
    dx = 2*M_PI/nx;

    if (size_x % 2 == 0) NEVEN = TRUE;
    else NEVEN = FALSE;

    num_threads = 1;

#ifdef _OPENMP
    //omp_set_num_threads(8);
    num_threads = omp_get_max_threads();
    printf("Using %d threads\n",num_threads);
#endif
    allocate_all();
#ifdef _FFTW
    allocate_conv();
#endif
    read_domain(directory);
    
    
    read_files(n,directory);
    //read_single_file(n,1,directory);
    /*
    if (cfl_dt < dt) {
        printf("Using cfl limited timestep of %.4e instead of %.4e\n",cfl_dt,dt);
        dt = cfl_dt;
    }
    */

    
    //move_to_com();


    read_stockholm(directory);
/*
    for(j=0;j<size_y;j++) {
        dens0[j] = params.mdot/(3*M_PI*Nu(ymed(j)));
        vy0[j] = -1.5*Nu(ymin(j))/ymin(j);
        vx0[j] = pow(ymed(j),-.5);
	    vx0[j] *= sqrt(1.0+pow(params.h,2)*pow(ymed(j),2*params.flaringindex)*
			  (2.0*params.flaringindex - 1.5));
        vx0[j] -= omf*ymed(j);

    }
*/
    omf0 = omf;

    output_stock(outputdir);

    output_init(outputdir);
   
    init_rk5();
    nsteps = 0;
    double tstart = psys[0].t;
    double tend = psys[0].t + time_step;
    double time = tstart;


#ifdef _FFTW
    printf("Using FFTW to compute fourier transforms\n");
#endif
#ifdef ARTIFICIALVISCOSITY
    printf("Using ARTIFICIAL VISCOSITY\n");
#endif
#ifdef FARGO
    printf("Using FARGO TRANSPORT\n");
#endif
#ifdef STOCKHOLMACC
    printf("Damping to current average in stockholm boundaries.\n");
#endif
#ifdef NOWAVEKILLRHO
    printf("Not damping the density.\n");
#endif
#ifdef FIXEDPSYS
    printf("Planetary system is FIXED.\n");
#endif
    printf("Starting time = %.3f\nEnding time = %.3f\n",tstart,tend);
    set_bc();

    set_dtLt(-1.0);

    while ((time < tend) && nsteps<MAXSTEPS) {
#ifdef FARGO
        compute_vmed(vx);
#endif
        dt = cfl();
        if (dt <= MINDT) {
            printf("Timestep has fallen below minimum!\n");
            break;
        }
        if (time + dt > tend) {
            dt = tend-time;
        }
        printf("\r t=%.3f, dt = %.8f,  %02d%% complete...",time,dt,(int)(100*(time-tstart)/(tend-tstart)));
        fflush(stdout);
        set_avg(0);
    
        potential();
        
#ifndef FIXEDPSYS
        move_planet();
#endif
    
       
        source_step();
       
        set_Lamex();
        viscosity();
#ifdef ARTIFICIALVISCOSITY
        
        artificial_visc();
#endif
    
        temp_to_vel();
        set_bc();
        
        vel_to_temp();
       
#ifdef FARGO
        compute_vmed(vx_temp);
#endif        
        transport_step();
        
        time += dt;
      
        set_avg(1);

        set_Lamdep();

        set_bc();
        stockholm();
        //output_psys(outputdir,nsteps);
        nsteps++;
    }
//    temp_to_vel();   

    set_dtLt(1.0);

    
    dt = tend - tstart;
    for(j=0;j<size_y;j++) {
        dbart[j]/=dt;
        //Lt[j]/=dt;
        //Lt[j+size_y]/=dt;
        //Ld[j]/=dt;
        //Ld[j+size_y]/=dt;
        //Lw[j]/=dt;
        //Lw[j+size_y]/=dt;
        Lw[j] = Lt[j] - Ld[j];
        Lw[j+size_y] = Lt[j+size_y] - Ld[j+size_y];
        drFt[j]/=dt;
        drFd[j]/=dt;
        drFdB[j]/=dt;
        mdotl[j]/=dt;
        drFnu[j]/=dt;
        drFw[j]/=dt;
        drFwB[j]/=dt;
        Lamex[j]/=dt;
        //Lamex[j+size_y]/=dt;
        Lamdep[j]/=dt;
        LamdepB[j]/=dt;
        dtLt[j]/=dt;
        dtLd[j]/=dt;
        dtLw[j]/=dt;
        dtLd_rhs[j]/=dt;
        mdotavg[j] /= dt;
        LamdepS[j + size_y*0] /= dt;
        LamdepS[j + size_y*1] /= dt;
        LamdepS[j + size_y*2] /= dt;
        LamdepS[j + size_y*3] /= dt;
        LamdepS[j + size_y*4] /= dt;
        LamdepS[j + size_y*5] /= dt;
        LamdepS[j + size_y*6] /= dt;
    }
    int mi;
    for(mi=1;mi<MMAX+2;mi++) {
        for(j=0;j<size_y;j++) {
            Lamex[j + size_y*mi] /= dt;
            drFd[j + size_y*mi] /= dt;
            dtLt[j + size_y*mi] /= dt;

        }
    }

    output(outputdir);
    output_torque(directory,n);
    output_torque(outputdir,n);
    free_rk5();
#ifdef _FFTW
    free_conv();
#endif
    //free_all();
    return 0;
}