コード例 #1
0
/**
 * @brief 
 * Use Euler Advection Scheme to Solve the PDE.
 */
int ConvectionSolve2d(structMesh *mesh, physics *phy, double** c, double finalTime){
    double time, CFL, dt;
    double **rhs = Matrix_create(mesh->ndim1, mesh->ndim2);
    
    time      = 0.0;
    CFL       = 0.1;
    
    // calculate time interval - dt
    dt = getTimeInterval(mesh, phy, CFL);

    double start, stop;
    start = MPI_Wtime();
    
    while (time < finalTime) {
        
        // increase local time
        if (time+dt > finalTime) {
            dt   = finalTime - time;
            time = finalTime;
        }else{
            time += dt;
        }
        
        TimeEvolution(mesh, phy, c, time, dt, rhs);
    }

    stop = MPI_Wtime();
    printf("Time Usaged: %f\n", (stop-start)*1000.0 );
    
    Matrix_free(rhs);
    return 0;
}
コード例 #2
0
ファイル: modelgeneral.cpp プロジェクト: ulvmoen/crava
ModelGeneral::ModelGeneral(ModelSettings           *& model_settings,
                           const InputFiles         * input_files,
                           SeismicParametersHolder  & seismic_parameters,
                           CommonData               * common_data,
                           int                        i_interval)
                           :do_4D_inversion_(model_settings->getDo4DInversion()),
                            do_4D_rock_physics_vnversion_(model_settings->getDo4DRockPhysicsInversion())
{
  random_gen_              = NULL;
  time_line_               = NULL;
  time_depth_mapping_      = NULL;
  velocity_from_inversion_ = false;
//  timeSimboxInitial_       =NULL;
  {
    simbox_ = common_data->GetMultipleIntervalGrid()->GetIntervalSimbox(i_interval);

    if (input_files->getSeedFile() == "")
      random_gen_ = new RandomGen(model_settings->getSeed());
    else
      random_gen_ = new RandomGen(input_files->getSeedFile().c_str());

    //
    // FORWARD MODELLING
    //
    if (model_settings->getForwardModeling() == true) {
    //
    }
    else {
      //
      // INVERSION/ESTIMATION
      //

      //Facies-names
      facies_names_  = common_data->GetFaciesNames();
      facies_labels_ = common_data->GetFaciesNr();

      //Priorfacies
      if (common_data->GetPriorFacies().size() > 0) {
        prior_facies_ = common_data->GetPriorFaciesInterval(i_interval);
      }
      if (model_settings->getIsPriorFaciesProbGiven()==ModelSettings::FACIES_FROM_CUBES) {
        prior_facies_prob_cubes_.resize(3);
        prior_facies_prob_cubes_[0] = new FFTGrid(common_data->GetPriorFaciesProbCube(i_interval, 0), simbox_->GetNXpad(), simbox_->GetNYpad(), simbox_->GetNZpad());
        prior_facies_prob_cubes_[1] = new FFTGrid(common_data->GetPriorFaciesProbCube(i_interval, 1), simbox_->GetNXpad(), simbox_->GetNYpad(), simbox_->GetNZpad());
        prior_facies_prob_cubes_[2] = new FFTGrid(common_data->GetPriorFaciesProbCube(i_interval, 2), simbox_->GetNXpad(), simbox_->GetNYpad(), simbox_->GetNZpad());
      }

      //TimeDepthMapping if intervals isn't used.
      if (model_settings->getDoDepthConversion()) {
        time_depth_mapping_      = common_data->GetTimeDepthMapping();
        velocity_from_inversion_ = common_data->GetVelocityFromInversion();
      }

      //Wells blocked to this interval simbox
      blocked_logs_ = common_data->GetBlockedLogsInterval(i_interval);

      if (common_data->GetTrendCubes().size() > 0)
        trend_cubes_ = common_data->GetTrendCube(i_interval);

      rock_distributions_  = common_data->GetDistributionsRock();
      reservoir_variables_ = common_data->GetReservoirVariables();

      //Set up timeline
      time_line_ = common_data->GetTimeLine();

      if (model_settings->getDo4DInversion()) {

        //setFaciesNamesFromRockPhysics();
        NRLib::Vector initial_mean(6);
        NRLib::Matrix initial_cov(6,6);

        SetupState4D(seismic_parameters, simbox_, state4d_, initial_mean, initial_cov);

        time_evolution_ = TimeEvolution(10000, *time_line_, rock_distributions_.begin()->second); //NBNB OK 10000->1000 for speed during testing
        time_evolution_.SetInitialMean(initial_mean);
        time_evolution_.SetInitialCov(initial_cov);
      }
    }
  }

}
コード例 #3
0
ファイル: main.cpp プロジェクト: waveletApplications/carmen
/*
______________________________________________________________________________________________

Main
______________________________________________________________________________________________

*/
int main(int argc, char *argv[])
{
	// --- Init Cluster variable ---------------------------------------------------------

	// carmen 0 => local execution i.e. show time on screen
	// carmen 1 => cluster execution i.e. refresh Performance.dat (default)

#if defined PARMPI
	// --- MPI Runtime system initialization
	// size - total number of processors
	// rnak - current CPU
	MPI_Init(&argc,&argv);
	MPI_Comm_size(MPI_COMM_WORLD, &size);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank);
#else
  	size=1;
	rank=0;
#endif
  
	if (argc == 2)
		Cluster = atoi(argv[1]);

	// --- Print messages on screen- -----------------------------------------------------

	cout << "carmen: begin execution.\n\n";
	printf("Carmen %4.2f \n",CarmenVersion);
	cout << "Copyright (C) 2000-2005 by Olivier Roussel.\n";
	cout << "All rights reserved.\n\n";
	
#if defined PARMPI
	//Synchronize all parallel branches
  	MPI_Barrier(MPI_COMM_WORLD);
#endif

  	CPUTime.start();
  
  // --- Create first node of the tree structure ---------------------------------------

	Node 	*Mesh=0;
	FineMesh *FMesh=0;

	
	// --- Init global values (See Parameters.h and Parameters.cpp) ----------------------------

	cout << "carmen: init computation ...\n";
	InitParameters();

  // --- Debug output information for parallel execution -------------------------------------
  
#if defined PARMPI                                                                            
  	if (Multiresolution) 
  	{
		printf("\nParallel Multiresolution solver not implemented yet!\n");
		exit(0);
	}
	
  	printf("My Rank=%d\n",rank);
  
  	// --- Each CPU print his coordinates in the virtual processor cart ------------------------
	printf("Cart_i = %d;     Cart_j = %d;     Cart_k = %d;\n",coords[0],coords[1],coords[2]);
	
  	// --- Each CPU print his computation domain
  	printf("Xmin = %lf;     XMax = %lf;\n",XMin[1],XMax[1]);
	printf("Ymin = %lf;     YMax = %lf;\n",XMin[2],XMax[2]);
	printf("Zmin = %lf;     ZMax = %lf;\n",XMin[3],XMax[3]);
	
  	// --- And the local scale number ----------------------------------------------------------
  	printf("ScaleNb = %d\n",ScaleNb);
#endif
  
	// --- Allocate ----------------------------------------------------------------------------

	if (Multiresolution)
		Mesh = new Node;
	else
		FMesh = new FineMesh;

	// --- Init tree structure -----------------------------------------------------------------

	if (Multiresolution)
	{
		InitTree(Mesh);
		RefreshTree(Mesh);
	}

	// --- Compute initial integral values and init time step ----------------------------------

	if (Multiresolution)
		Mesh->computeIntegral();
	else
		FMesh->computeIntegral();
	
	// -- Write integral values --
	
	
			
	// -- Compute initial time step --
	InitTimeStep();

	if (rank==0) PrintIntegral("Integral.dat");

	// --- Save initial values into files ------------------------------------------------------

	if (PrintEvery == 0)
	{
		if (Multiresolution)
			View(Mesh, "Tree_0.dat", "Mesh_0.dat", "Average_0.dat");
		else
			View(FMesh,"Average_0.dat");
	}
	
	// --- When PrintEvery != 0, save initial values into specific name format ---

	if (PrintEvery != 0)
	{
		if (Multiresolution)
			ViewEvery(Mesh, 0);
		else
			ViewEvery(FMesh, 0);
	}

  	// --- Parallel execution only --------------------------------------------
  	// --- Save to disk DX header for ouput files -----------------------------
  	// --- This file is needed for the external postprocessing (merging files from the different processors)

#if defined PARMPI

	real 	tempXMin[4];
	real	tempXMax[4];
	
  	// --- Save original task parameters for the parallel execution
  	int tempScaleNb=ScaleNb;

  	// --- Simulate sequantial running
  	ScaleNb=AllTaskScaleNb;

  	for (int i=0;i<4;i++) 
  	{
  		tempXMin[i]=XMin[i];
		tempXMax[i]=XMax[i];
		// --- Simulate sequantial running
		XMin[i]=AllXMin[i];
		XMax[i]=AllXMax[i];
  	}

  	// --- Write header with parameters, as we have run sequantial code
  	if (rank==0) FMesh->writeHeader("header.txt");

  	// Restore variables
  	for (int i=0;i<4;i++) 
  	{
		XMin[i]=tempXMin[i];
   		XMax[i]=tempXMax[i];
	}
	
  	ScaleNb=tempScaleNb;

#endif  
  
  	// --- Done ---

	cout << "carmen: done.\n";

	// --- Write solver type ---

	if (Multiresolution)
		cout << "carmen: multiresolution (MR) solver.\n";
	else
		cout << "carmen: finite volume (FV) solver.\n";

	// --- Write number of iterations ---

	if (IterationNb == 1)
		cout << "carmen: compute 1 iteration ...\n";
  	else
		cout << "carmen: compute " << IterationNb << " iterations ...\n";
	
	printf("\n\n\n");

	// --- Begin time iteration ----------------------------------------------------------------

	for (IterationNo = 1; IterationNo <= IterationNb; IterationNo++)
	{

		// --- Time evolution procedure ---
		if (Multiresolution)
			TimeEvolution(Mesh);
		else
			TimeEvolution(FMesh);

		// --- Remesh ---
		 if (Multiresolution) Remesh(Mesh);

		// --- Check CPU Time ---
	  	CPUTime.check();

		// --- Write information every (Refresh) iteration ---
		if ((IterationNo-1)%Refresh == 0)
		{                                          
			// - Write integral values -
			if (rank==0) PrintIntegral("Integral.dat");

			if (Cluster == 0)
				ShowTime(CPUTime);  // Show time on screen
		  //else
			if (rank==0) Performance("carmen.prf"); // Refresh file "carmen.prf"
    		}

		// --- Backup data every (10*Refresh) iteration ---
		if ((IterationNo-1)%(10*Refresh) == 0 && UseBackup)
		{
			if (Multiresolution)
				Backup(Mesh);
			else
				Backup(FMesh);
    		}

		// --- Print solution if IterationNo = PrintIt1 to PrintIt6 ---
		if (Multiresolution)
			ViewIteration(Mesh);
		else
			ViewIteration(FMesh);

		// --- Print solution if IterationNo is a multiple of PrintEvery ---

		if (PrintEvery != 0)
		{
     			if (IterationNo%PrintEvery == 0)
			{
				if (Multiresolution)
					ViewEvery(Mesh, IterationNo);
				else
					ViewEvery(FMesh, IterationNo);
			}
		}

	// --- End time iteration ------------------------------------------------------------------
	}	

	// --- Backup final data  ------------------------------------------------------------------

	IterationNo--;

	if (UseBackup)
  {
		if (Multiresolution)
			Backup(Mesh);
		else
			Backup(FMesh);
	}

	// --- Write integral values ---------------------------------------------------------------
	
	if (rank==0) PrintIntegral("Integral.dat");
	
	IterationNo++;

	// --- Save values into file ---------------------------------------------------------------

	if (Multiresolution)
		View(Mesh, "Tree.dat", "Mesh.dat", "Average.dat");
	else
		View(FMesh, "Average.dat");

	cout << "\ncarmen: done.\n";
	
	// --- Analyse performance and save it into file -------------------------------------------
				
	if (rank==0) Performance("carmen.prf");	

	// --- End ---------------------------------------------------------------------------------

	if (Multiresolution)
		delete Mesh;
	else
		delete FMesh;


#if defined PARMPI

  	//free memory for the MPI runtime variables
	delete[] disp;
	delete[] blocklen;
	int sz;
	MPI_Buffer_detach(&MPIbuffer,&sz);
	// for (int i = 0; i < 4*Dimension; i++)	MPI_Request_free(&req[i]);
	MPI_Finalize();
	
#endif
    
  	cout <<"carmen: end execution.\n";
	return EXIT_SUCCESS;
}