From: michael Date: Mon, 14 Dec 2020 16:12:43 +0000 (+0100) Subject: First MPI tests X-Git-Tag: V9_7_0~93 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b71fc203edda97a03592f60b301f8d21bac4a0fa;p=tools%2Fsolverlab.git First MPI tests --- diff --git a/CoreFlows/examples/C/CMakeLists.txt b/CoreFlows/examples/C/CMakeLists.txt index d9a5aa4..0abbd28 100755 --- a/CoreFlows/examples/C/CMakeLists.txt +++ b/CoreFlows/examples/C/CMakeLists.txt @@ -7,9 +7,6 @@ INCLUDE_DIRECTORIES( ) -SET(_extra_lib_CoreFlows CoreFlowsLibs ) - - if(CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_BUILD_TYPE STREQUAL Debug) include(CodeCoverage) @@ -44,7 +41,7 @@ function(CreateTestExecAndInstall SourceTestFile libList) endfunction(CreateTestExecAndInstall) -set( libs_for_tests ${_extra_lib_CoreFlows} ) +set( libs_for_tests CoreFlowsLibs ) # copy tests resources (med files etc.) into the build directory file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../resources DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) @@ -99,4 +96,14 @@ CreateTestExecAndInstall(StationaryDiffusionEquation_2DFV_StructuredSquares.cxx CreateTestExecAndInstall(StationaryDiffusionEquation_3DEF_StructuredTetrahedra.cxx "${libs_for_tests}" ) CreateTestExecAndInstall(StationaryDiffusionEquation_3DFV_StructuredTetrahedra.cxx "${libs_for_tests}" ) CreateTestExecAndInstall(testEOS.cxx "${libs_for_tests}" ) +CreateTestExecAndInstall(WaveSystem_2DFV_SphericalExplosion_CDMATH.cxx "${libs_for_tests}" ) + + +if( SOLVERLAB_WITH_MPI ) + add_executable(WaveSystem_2DFV_SphericalExplosion_MPI.exe WaveSystem_2DFV_SphericalExplosion_MPI.cxx) # compilation of the testxxx.exe + target_link_libraries(WaveSystem_2DFV_SphericalExplosion_MPI.exe CoreFlowsLibs ${MPI_LIBRARY}) # provide required lib for testxxx.exe + install(TARGETS WaveSystem_2DFV_SphericalExplosion_MPI.exe DESTINATION share/examples) + add_test(NAME WaveSystem_2DFV_SphericalExplosion_MPI_SEQ COMMAND "${MPIEXEC}" "-n" "1" "./WaveSystem_2DFV_SphericalExplosion_MPI.exe") # adding a ctest Test + add_test(NAME WaveSystem_2DFV_SphericalExplosion_MPI_PAR COMMAND "${MPIEXEC}" "-n" "2" "./WaveSystem_2DFV_SphericalExplosion_MPI.exe") # adding a ctest Test +endif( SOLVERLAB_WITH_MPI ) diff --git a/CoreFlows/examples/C/WaveSystem_2DFV_SphericalExplosion_CDMATH.cxx b/CoreFlows/examples/C/WaveSystem_2DFV_SphericalExplosion_CDMATH.cxx new file mode 100755 index 0000000..24ad784 --- /dev/null +++ b/CoreFlows/examples/C/WaveSystem_2DFV_SphericalExplosion_CDMATH.cxx @@ -0,0 +1,277 @@ +//============================================================================ +// Author : Michael NDJINGA +// Date : November 2020 +// Description : 2D linear wave system +//============================================================================ + +#include +#include +#include + +#include "Mesh.hxx" +#include "Cell.hxx" +#include "Face.hxx" +#include "Field.hxx" +#include "SparseMatrixPetsc.hxx" +#include "CdmathException.hxx" + +using namespace std; + +double p0 =155e5; //reference pressure in a pressurised nuclear vessel +double c0 =700.; //reference sound speed for water at 155 bars, 600K +double rho0=p0/c0*c0;//reference density +double precision=1e-5; + +void initial_conditions_shock(Mesh my_mesh,Field& pressure_field,Field& velocity_field) +{ + double rayon=0.35; + double xcentre=0.; + double ycentre=0; + + int dim =my_mesh.getMeshDimension(); + int nbCells=my_mesh.getNumberOfCells(); + + for (int j=0 ; j=2) + Un[k + 2*nbCells] = rho0*velocity_field[k,1] ; + if(dim==3) + Un[k + 3*nbCells] = rho0*velocity_field[k,2]; + } + + /* + * MED output of the initial condition at t=0 and iter = 0 + */ + int it=0; + bool isStationary=false; + double time=0.; + double dt = cfl * dx_min / c0; + + cout << "Saving the solution at T=" << time << endl; + pressure_field.setTime(time,it); + pressure_field.writeVTK("WaveSystem"+to_string(dim)+"DUpwind"+meshName+"_pressure"); + velocity_field.setTime(time,it); + velocity_field.writeVTK("WaveSystem"+to_string(dim)+"DUpwind"+meshName+"_velocity"); + /* --------------------------------------------- */ + + SparseMatrixPetsc divMat=computeDivergenceMatrix(my_mesh,nbVoisinsMax,dt); + + /* Time loop */ + cout<< "Starting computation of the linear wave system with an explicit UPWIND scheme" << endl; + while (it=ntmax or isStationary or time >=tmax) + { + cout<<"-- Iteration: " << it << ", Time: " << time << ", dt: " << dt<1) + { + velocity_field[k,1]=Un[k*(dim+1)+2]/rho0; + if(dim>2) + velocity_field[k,2]=Un[k*(dim+1)+3]/rho0; + } + } + pressure_field.setTime(time,it); + pressure_field.writeVTK("WaveSystem"+to_string(dim)+"DUpwind"+meshName+"_pressure",false); + velocity_field.setTime(time,it); + velocity_field.writeVTK("WaveSystem"+to_string(dim)+"DUpwind"+meshName+"_velocity",false); + } + } + cout<<"End of calculation -- Iteration: " << it << ", Time: "<< time<< ", dt: " << dt<=ntmax) + cout<< "Nombre de pas de temps maximum ntmax= "<< ntmax<< " atteint"< +#include +#include + +#include "Mesh.hxx" +#include "Cell.hxx" +#include "Face.hxx" +#include "Field.hxx" +#include "CdmathException.hxx" + +#include + +using namespace std; + +double p0 =155e5; //reference pressure in a pressurised nuclear vessel +double c0 =700.; //reference sound speed for water at 155 bars, 600K +double rho0=p0/c0*c0;//reference density +double precision=1e-5; + +void initial_conditions_shock(Mesh my_mesh,Field& pressure_field,Field& velocity_field) +{ + double rayon=0.35; + double xcentre=0.; + double ycentre=0; + + int dim =my_mesh.getMeshDimension(); + int nbCells=my_mesh.getNumberOfCells(); + + for (int j=0 ; j=ntmax or isStationary or time >=tmax ) + { + PetscPrintf(PETSC_COMM_WORLD,"-- Iteration: %d, Time: %f, dt: %f, saving results on processor 0 \n", it, time, dt); + VecScatterBegin(scat,Un,Un_seq,INSERT_VALUES,SCATTER_FORWARD); + VecScatterEnd( scat,Un,Un_seq,INSERT_VALUES,SCATTER_FORWARD); + + if(rank == 0) + { + for(int k=0; k=ntmax) + PetscPrintf(PETSC_COMM_WORLD, "Nombre de pas de temps maximum ntmax= %d atteint\n", ntmax); + else if(isStationary) + PetscPrintf(PETSC_COMM_WORLD, "Régime stationnaire atteint au pas de temps %d, t= %f\n", it, time); + else + PetscPrintf(PETSC_COMM_WORLD, "Temps maximum tmax= %f atteint\n", tmax); + + VecDestroy(&Un); + VecDestroy(&Un_seq); + VecDestroy(&dUn); + MatDestroy(&divMat); +} + +int main(int argc, char *argv[]) +{ + /* PETSc initialisation */ + PetscInitialize(&argc, &argv, PETSC_NULL, PETSC_NULL); + PetscMPIInt size; /* size of communicator */ + PetscMPIInt rank; /* processor rank */ + MPI_Comm_rank(PETSC_COMM_WORLD,&rank); + MPI_Comm_size(PETSC_COMM_WORLD,&size); + + // Problem data + double cfl=0.49; + double tmax=1.; + int ntmax=80;//20000; + int freqSortie=10; + string fileOutPut="SphericalWave"; + Mesh myMesh; + + if(size>1) + PetscPrintf(PETSC_COMM_WORLD,"---- More than one processor detected : running a parallel simulation ----\n"); + PetscPrintf(PETSC_COMM_WORLD,"---- Limited parallelism : input and output remain sequential ----\n"); + PetscPrintf(PETSC_COMM_WORLD,"---- Only the matrix-vector products are done in parallel ----\n"); + PetscPrintf(PETSC_COMM_WORLD,"---- Processor 0 is in charge of building the mesh, saving the results, filling and then distributing the matrix to other processors.\n\n"); + + if(rank == 0) + { + cout << "-- Starting the RESOLUTION OF THE 2D WAVE SYSTEM on "<< size <<" processors"<