示例#1
0
EXTERN_C_BEGIN
#undef __FUNCT__  
#define __FUNCT__ "PetscDLLibraryRegister_tao"
/*
  DLLibraryRegister - This function is called when the dynamic library it is in is opened.

  This registers all of the TAO methods that are in the basic libtao library.

  Input Parameter:
  path - library path
 */
int PetscDLLibraryRegister_tao(const char *path)
{
  int info;
  TaoFunctionBegin;

#ifdef TAO_USE_PETSC
  info = PetscInitializeNoArguments(); if (info) return 1;
#endif

  /*
      If we got here then PETSc was properly loaded
  */
  info = TaoRegisterAll(path);CHKERRQ(info);
  TaoFunctionReturn(0);
}
示例#2
0
文件: petsc.cpp 项目: alieed/hermes
int add_petsc_object()
{
  _F_
#ifdef WITH_PETSC
  int ierr;
  PetscTruth petsc_initialized, petsc_finalized;
  ierr = PetscFinalized(&petsc_finalized); CHKERRQ(ierr);
  
  if (petsc_finalized == PETSC_TRUE)
    error("PETSc cannot be used once it has been finalized. You must restart the application.");
  
  ierr = PetscInitialized(&petsc_initialized); CHKERRQ(ierr);
  
  if (petsc_initialized != PETSC_TRUE)
  {
    bool have_args = CommandLineArgs::check();
    
    if (have_args)
      ierr = PetscInitialize(&CommandLineArgs::get_argc(), 
                             &CommandLineArgs::get_argv(), 
                             PETSC_NULL, PETSC_NULL);
    else
    #ifdef WITH_MPI
      CommandLineArgs::missing_error();
    #else
      ierr = PetscInitializeNoArguments();  
    #endif
    
    CHKERRQ(ierr);
  }
  
  num_petsc_objects++;
#endif 
  return 0;
}
示例#3
0
// -------------------------------------------------------------
// Initialize
// -------------------------------------------------------------
/// Does whatever is necessary to start up the PETSc library
void
Initialize(void)
{
  if (Initialized()) return;
  PetscErrorCode ierr(0);
  PetscBool flg;
#if USE_PROGRESS_RANKS
  gridpack::parallel::Communicator comm;
  MPI_Comm world = GA_MPI_Comm();
  PETSC_COMM_WORLD = world;
#endif
  try {
// Turn this on to enable PETSc logging.
#if 0
    int argc = 2;
    char **args;
    args = new char*[2];
    args[0] = new char[32];
    args[1] = new char[32];
    sprintf(args[0],"powerflow.x");
    sprintf(args[1],"-log_summary");
    ierr = PetscInitialize(&argc,&args,NULL,NULL); CHKERRXX(ierr);
    delete [] args[1];
    delete [] args[0];
    delete [] args;
#else
    ierr = PetscInitializeNoArguments(); CHKERRXX(ierr);
#endif
    PetscOptionsHasName(
#if PETSC_VERSION_GE(3,7,0)
                                    NULL,
#endif
                                    NULL, "-log_summary", &flg);
    ierr = PetscOptionsInsertFile(PETSC_COMM_WORLD,
#if PETSC_VERSION_GE(3,7,0)
                                    NULL,
#endif
                                  "gridpack.petscrc",
                                  PETSC_FALSE); CHKERRXX(ierr);
  } catch (const PETSC_EXCEPTION_TYPE& e) {
    throw PETScException(ierr, e);
  }
  // Print out some information on processor configuration
  int mpi_err, me, nproc;
  mpi_err = MPI_Comm_rank(PETSC_COMM_WORLD, &me);
  mpi_err = MPI_Comm_size(PETSC_COMM_WORLD, &nproc);
  if (mpi_err > 0) {
    throw gridpack::Exception("MPI initialization failed");
  }
  if (me == 0) {
    printf("\nGridPACK math module configured on %d processors\n",nproc);
  }
}
示例#4
0
    int add_petsc_object()
    {
      int ierr;
      PetscTruth petsc_initialized, petsc_finalized;
      ierr = PetscFinalized(&petsc_finalized); CHKERRQ(ierr);

      if (petsc_finalized == PETSC_TRUE)
        throw Hermes::Exceptions::Exception("PETSc cannot be used once it has been finalized. You must restart the application.");

      ierr = PetscInitialized(&petsc_initialized); CHKERRQ(ierr);

      if (petsc_initialized != PETSC_TRUE)
      {
        ierr = PetscInitializeNoArguments();
        CHKERRQ(ierr);
      }

      num_petsc_objects++;
    }
示例#5
0
EXTERN_C_BEGIN
#undef __FUNCT__  
#define __FUNCT__ "PetscDLLibraryRegister_petscsnes"
/*
  PetscDLLibraryRegister - This function is called when the dynamic library it is in is opened.

  This registers all of the SNES methods that are in the basic PETSc libpetscsnes library.

  Input Parameter:
  path - library path

 */
PetscErrorCode PETSCSNES_DLLEXPORT PetscDLLibraryRegister_petscsnes(const char path[])
{
  PetscErrorCode ierr;

  ierr = PetscInitializeNoArguments(); if (ierr) return 1;
  PetscFunctionBegin;
  /*
      If we got here then PETSc was properly loaded
  */
  ierr = SNESInitializePackage(path);CHKERRQ(ierr);
  PetscFunctionReturn(0);
}
示例#6
0
int main(int argc, char **argv)
{
 /* This test case applies a prescribed vortex field in a unit cube to
  * test the re-meshing techinique of the surface mesh. 
  *
  * OBS.: - comment stepSL() on Simulator3D::stepALE
  *       - switch to tetrahedralize( (char*) "QYYAp",&in,&out ) on
  *       Model3D::mesh3DPoints
  *
  * Since the field is prescribed, there is no need of calculating the
  * convection in a Euleurian way (stepSL) and the insertion of nodes on
  * the 3D mesh.
  *
  * */

 PetscInitializeNoArguments();
 
 int iter = 1;
 double d1 = 0.0;   // surface tangent velocity u_n=u-u_t 
 double d2 = 0.0;   // surface smooth cord (fujiwara)

 double dt = 0.02;
 double T = 3.0;
 double time = 0;

 string meshFile = "sphere.msh";

 const char *vtkFolder  = "./vtk/";
 const char *mshFolder  = "./msh/";
 const char *datFolder  = "./dat/";
 string meshDir = (string) getenv("DATA_DIR");
 meshDir += "/gmsh/3d/sphere/vortex/" + meshFile;
 const char *mesh = meshDir.c_str();

 Model3D m1;
 Simulator3D s1;

 const char *mesh1 = mesh;
 m1.readMSH(mesh1);
 m1.setInterfaceBC();
 m1.setTriEdge();
 m1.mesh2Dto3D("QYYAp");
 m1.setMapping();
#if NUMGLEU == 5
 m1.setMiniElement();
#else
 m1.setQuadElement();
#endif
 m1.setSurfaceConfig();
 m1.setInitSurfaceVolume();
 m1.setInitSurfaceArea();

 s1(m1);

 s1.setDt(dt);

 s1.setD1(d1);
 s1.setD2(d2);

 // initial conditions
 s1.stepImposedPeriodicField("3d",T,s1.getTime()); // X,Y and Z --> Sol(n+1)

 int nReMesh = 1;
 while( time < T )
 {
  for( int j=0;j<nReMesh;j++ )
  {
   cout << color(none,magenta,black);
   cout << "____________________________________ Iteration: "
	    << iter << endl << endl;
   cout << resetColor();

   InOut save(m1,s1); // cria objeto de gravacao
   save.printSimulationReport();

   time = s1.getTime();

   // time step: n+1/4
   Simulator3D s20(m1,s1);
   double stepTime = dt/4.0;
   s20.stepImposedPeriodicField("3d",T,time+stepTime,stepTime); // SolOld(n) --> Sol(n+1/2)
   s20.saveOldData();        // Sol(n+1/2) --> SolOld(n+1/2)

   // time step: n+1/2
   Simulator3D s30(m1,s20);
   stepTime = dt/2.0;
   s30.stepImposedPeriodicField("3d",T,time+stepTime,stepTime); // SolOld(n) --> Sol(n+1/2)
   s30.saveOldData();        // Sol(n+1/2) --> SolOld(n+1/2)
   s30.stepALE();         // SolOld(n+1/2) --> ALE(n+1/2)

   // time step: n using ALE(n+1/2)
   s1.setUALE(s30.getUALE());
   s1.setVALE(s30.getVALE());
   s1.setWALE(s30.getWALE());
   s1.movePoints();
   m1.setNormalAndKappa();

   double field = cos(3.14159265358*time/T);
   cout << endl;
   cout << "                             | T:        " << T << endl;
   cout << "                             | dt:       " << dt << endl;
   cout << "                             | time:     " << time << endl;
   cout << "                             | iter:     " << iter << endl;
   cout << "                             | field:    " << field << endl;
   cout << endl;

   save.saveMSH(mshFolder,"newMesh",iter);
   save.saveVTK(vtkFolder,"sim",iter);
   save.saveVTKSurface(vtkFolder,"sim",iter);
   save.saveBubbleInfo(datFolder);

   s1.saveOldData(); // Sol(n+1) --> SolOld(n)

   s1.timeStep();

   cout << color(none,magenta,black);
   cout << "________________________________________ END of "
	<< iter << endl << endl;;
   cout << resetColor();

   iter++;
  }
  Model3D mOld = m1;

  /* *********** MESH TREATMENT ************* */
  // set normal and kappa values
  m1.initMeshParameters();

  // surface operations
  //m1.smoothPointsByCurvature();

  m1.insertPointsByLength("flat");
  m1.contractEdgesByLength("flat");

  if( time > 1.9 )
   m1.contractEdgesByLength("flat",0.65);
  if( time > 2.2 )
   m1.contractEdgesByLength2("flat",0.7);
  if( time > 2.3 )
   m1.contractEdgesByLength2("flat",0.8);
  if( time > 2.8 )
   m1.contractEdgesByLength2("flat",1.2);

  //m1.removePointsByLength();
  m1.flipTriangleEdges();

  //m1.removePointsByNeighbourCheck();
  //m1.checkAngleBetweenPlanes();
  /* **************************************** */

  m1.setInterfaceBC();
  m1.setMiniElement();
  m1.restoreMappingArrays();
  m1.setSurfaceVolume();
  m1.setSurfaceArea();
  m1.triMeshStats();

  // computing velocity field X^(n+1),time+1 at new nodes too!
  Simulator3D s2(m1,s1);
  s2.stepImposedPeriodicField("3d",T,time); // X,Y and Z --> Sol(n+1)
  s2.saveOldData();
  s1 = s2;
  s1.setCentroidVelPos();

  InOut saveEnd(m1,s1); // cria objeto de gravacao
  saveEnd.printMeshReport();
  saveEnd.saveMeshInfo(datFolder);
 }

 PetscFinalize();
 return 0;
}
示例#7
0
SparseVector::SparseVector()
{
    PetscInitializeNoArguments();
}
示例#8
0
int main(int argc, char **argv)
{
 /* This test case applies a prescribed 2D vortex field in a unit cube to
  * test the re-meshing techinique of the surface mesh. 
  *
  * OBS.: - comment stepSL() on Simulator3D::stepALE
  *       - switch to tetrahedralize( (char*) "QYYAp",&in,&out ) on
  *       Model3D::mesh3DPoints
  *
  * Since the field is prescribed, there is no need of calculating the
  * convection in a Euleurian way (stepSL) and the insertion of nodes on
  * the 3D mesh.
  *
  * */

 PetscInitializeNoArguments();
 
 int iter = 1;
 double d1 = 0.0;  // surface tangent velocity u_n=u-u_t 
 double d2 = 0.1;  // surface smooth cord (fujiwara)

 double dt = 0.01;
 double time = 0.0;

 string meshFile = "sphere.msh";

 const char *vtkFolder  = "./vtk/";
 const char *mshFolder  = "./msh/";
 const char *datFolder  = "./dat/";
 string meshDir = (string) getenv("DATA_DIR");
 meshDir += "/gmsh/3d/sphere/zalesak/" + meshFile;
 const char *mesh = meshDir.c_str();

 Model3D m1;
 Simulator3D s1;

 const char *mesh1 = mesh;
 m1.readMSH(mesh1);
 m1.setInterfaceBC();
 m1.setTriEdge();
 m1.mesh2Dto3D("QYYAp");
 m1.setMapping();
#if NUMGLEU == 5
 m1.setMiniElement();
#else
 m1.setQuadElement();
#endif
 m1.setSurfaceConfig();
 m1.setInitSurfaceVolume();
 m1.setInitSurfaceArea();

 s1(m1);

 s1.setD1(d1);
 s1.setD2(d2);
 s1.setDt(dt);

 InOut save(m1,s1); // cria objeto de gravacao
 save.saveVTK(vtkFolder,"geometry");
 save.saveVTKSurface(vtkFolder,"geometry");
 save.saveMeshInfo(datFolder);
 save.saveInfo(datFolder,"info",mesh);

 int nIter = 3000;
 int nReMesh = 1;
 for( int i=1;i<=nIter;i++ )
 {
  for( int j=0;j<nReMesh;j++ )
  {

   cout << color(none,magenta,black);
   cout << "____________________________________ Iteration: " 
	    << iter << endl << endl;
   cout << resetColor();

   InOut save(m1,s1); // cria objeto de gravacao
   save.printSimulationReport();

   time = s1.getTime();

   s1.stepImposedPeriodicField("rotating",0.0,time);
   s1.stepALE();
   s1.movePoints();
   s1.setInterfaceGeo();

   save.saveMSH(mshFolder,"newMesh",iter);
   save.saveVTK(vtkFolder,"sim",iter);
   save.saveVTKSurface(vtkFolder,"sim",iter);
   save.saveBubbleInfo(datFolder);
   //save.crossSectionalVoidFraction(datFolder,"voidFraction",iter);

   s1.saveOldData();

   cout << color(none,magenta,black);
   cout << "________________________________________ END of " 
	    << iter << endl << endl;;
   cout << resetColor();

   iter++;
  }
  Model3D mOld = m1; 

  /* *********** MESH TREATMENT ************* */
  // set normal and kappa values
  m1.setNormalAndKappa();
  m1.initMeshParameters();

  // surface operations
  //m1.smoothPointsByCurvature();

  m1.insertPointsByLength("flat");
  m1.contractEdgesByLength("flat");
  //m1.removePointsByLength();
  //m1.flipTriangleEdges();

  //m1.removePointsByNeighbourCheck();
  //m1.checkAngleBetweenPlanes();
  /* **************************************** */

  m1.setInterfaceBC();
  m1.setMiniElement();
  m1.restoreMappingArrays();
  m1.setSurfaceVolume();
  m1.setSurfaceArea();
  m1.triMeshStats();

  // computing velocity field X^(n+1),time+1 at new nodes too!
  Simulator3D s2(m1,s1);
  s2.stepImposedPeriodicField("rotating",0.0,time);
  s2.saveOldData();
  s1 = s2;
  s1.setCentroidVelPos();

  InOut saveEnd(m1,s1); // cria objeto de gravacao
  saveEnd.printMeshReport();
  saveEnd.saveMeshInfo(datFolder);
 }

 PetscFinalize();
 return 0;
}