Ejemplo n.º 1
0
void Get_dXdB(std::string path, Real* dxdb, Mesh<Real>* m, Int beta)
{
  std::ifstream fin;
  std::stringstream ss;

  Int i, b;

  PObj<Real>* p = m->p;
  Int rank = p->GetRank();
  Int np = p->GetNp();

  Int rankRead, npRead, nnodeRead;
  Int nnode = m->GetNumNodes();

  ss.clear();
  ss << rank;

  //read points to move from file and dxdb for them
  std::string Filename = path + "-DxDb." + (ss.str()) + ".dat";
  fin.open(Filename.c_str());
  if(!fin.is_open()){
    std::cerr << "WARNING: opening file failed --> " << Filename << std::endl;
    return;
  }
  
  //read in header to check for mismatched process numbers
  fin >> npRead;
  fin >> rankRead;
  fin >> nnodeRead;

  //check that the state is sane
  if(npRead != np){
    std::cerr << "WARNING: Get_dXdB() Mesh movement sensitivities were run with a " 
	      << "nonmatching number of processes, files not synced!" << std::endl;
  }
  if(rankRead != rank){
    std::cerr << "WARNING: Get_dXdB() Mesh movement sensitivities opened with wrong rank!"
       << std::endl;
  }
  if(nnodeRead != nnode){
    std::cerr << "WARNING: Get_dXdB() Mesh movement sensitivities opened with wrong number "
	      << "of nodes!" << std::endl;
  }


  //read in globalnodes for each beta up until we have read
  //the beta we are looking for
  for(b = 0; b <= beta; b++){
    for(i = 0; i < nnode*3; i++){
      fin >> dxdb[i];
    }
  }

  fin.close();

  return;
}
Ejemplo n.º 2
0
void Compute_dXdB(SolutionSpace<Real>& space)
{
  Mesh<Real>* m = space.m;
  BoundaryConditions<Real>* bc = space.bc;

  RCmplx h (0.0, 1.0e-11);

  Int i, j;

  Int nnode = m->GetNumNodes();
  Int gnode = m->GetNumParallelNodes();
  Int nbnode = m->GetNumBoundaryNodes();

  Int beta;

  //this contains dxdb dydx and dzdb
  Real* dxdb = new Real[nnode*3];
  RCmplx* dxdbSurfC = new RCmplx[nnode*3];

  Mesh<RCmplx> cm(*m);
  PObj<RCmplx> cp;
  cm.SetParallelPointer(&cp);
  cp.BuildCommMaps(&cm);
  //check for parallel comm sanity
  cp.CheckSanityCoords(cm.xyz);

  Int cnnode = cm.GetNumNodes();
  
  std::cout << "\n\nCOMPUTING dX/dB\n" << std::endl;

  std::string fullpath = space.param->path + space.param->spacename;
  Int ndv = GetNdvDesignFile(fullpath);
  std::cout << "\n\nFOUND " << ndv << " design variables\n" << std::endl;

  std::ofstream fout;
  std::stringstream ss;
  ss.clear();
  ss.str("");
  ss << cp.GetRank();
  std::string dxdbFilename = space.param->path+space.param->spacename + "-DxDb." + (ss.str()) + ".dat";
  fout.open(dxdbFilename.c_str());
  fout << std::setprecision(16);

  Int np = m->p->GetNp();
  Int rank = m->p->GetRank();
  fout << np << " " << rank << " " << cnnode << std::endl;

  for(beta = 0; beta < ndv; beta++){
    std::cout << "PERTURBING BETA: " << beta << std::endl;
    Compute_dXdB_Surface(space.param->path + space.param->spacename, m, bc, dxdb, beta);
    //perturb points by h * dxdb_surface
    for(i = 0; i < nnode; i++){
      for(j = 0; j < 3; j++){
	dxdbSurfC[i*3 + j] = dxdb[i*3 + j]*h;
      }
    }      
    Int smoothingPasses = 1000;
    MoveMeshLinearElastic(&cm, bc, dxdbSurfC, smoothingPasses);
  
    //compute dxdb
    for(i = 0; i < cnnode*3; i++){
      dxdb[i] = imag(cm.xyz[i])/imag(h);
    }
    //write dxdb dxdb dzdb to file
    for(i = 0; i < cnnode; i++){
      for(j = 0; j < 3; j++){
	fout << dxdb[i*3 + j] << " " ;
      }
      fout << std::endl;
    }
    //reset xyz coords for next pass
    for(i = 0; i < nnode*3; i++){
      cm.xyz[i] = m->xyz[i];
    }
    cp.UpdateXYZ(cm.xyz);

  }

  fout.close();

  delete [] dxdb;
  delete [] dxdbSurfC;

  return;
}
Ejemplo n.º 3
0
int main(int argc, char* argv[]){

#ifdef _DEBUG
  //enable exceptions so we can trap NaNs, etc.
  feenableexcept(FE_INVALID | FE_OVERFLOW);
#endif

  Int rank, np;
  Int mode = 0;
  Int ndv = 0;
  Real* dObjdBeta = NULL;
  
  std::vector<Param<Real>* > paramList; 
  SolutionOrdering<Real> operations;
  TemporalControl<Real> temporalControl;

  string tempname;
  stringstream temposs;

  TimerList timers(5);
  timers.CreateTimer("MPI_InitTimer");
  timers.CreateTimer("SolveTimer");
  timers.CreateTimer("DesignTimer");
  timers.CreateTimer("MovementTimer");

  //create parallel object for comms
  timers.StartTimer("MPI_InitTimer");
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  MPI_Comm_size(MPI_COMM_WORLD, &np);
  timers.StopTimer("MPI_InitTimer");

  PObj<Real> pobj;
  rank = pobj.GetRank();
  //remove Abort.Log if its present
  if(rank == 0){
    remove("Abort.Log");
  }
  
  if(!((argc == 2) || (argc == 3))){
    cerr << "Invalid arguments!!!" << endl;
    cerr << "USE: " << argv[0] << " <casename>" << endl;
    cerr << "OR" << endl;
    cerr << "USE: " << argv[0] << " <casename> <design type>" << endl;
    cerr << "<design type> - none = 0" << endl;
    cerr << "<design type> - objective f-n evaluation = 1" << endl;
    cerr << "<design type> - direct = 2" << endl;
    cerr << "<design type> - adjoint = 3" << endl;
    cerr << "<design type> - CTSE = 4" << endl;
    cerr << "<design type> - GRID SMOOTHING = 5" << endl;
    cerr << "<design type> - Compute Mesh Sensitivity = 6" << endl;
    cerr << "<design type> - Finite Difference = 7" << endl;

    //dumps all options in param file to output
    Param<Real> tmp;
    tmp.PrintAllParams();

    MPI_Finalize();
    return (1);
  }

  std::string casestring = argv[1];
  size_t pos = casestring.rfind('/');
  std::string pathname;
  if(pos != std::string::npos){
    pathname = casestring.substr(0, pos+1);
    casestring = casestring.substr(pos);
  }
  else{
    pathname = "./";
  }

  //set pathname in abort class
  Abort.rootDirectory = pathname;

  if(argc == 3){
    temposs.clear();
    temposs.str("");
    temposs << argv[2];
    temposs >> mode;
  }