Commit ff94bcf2 authored by Dion Haefner's avatar Dion Haefner

split random field generator in parallel and sequential components

parent 38d5508c
configure_file(dorie.in dorie @ONLY) configure_file(dorie.in ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/dorie @ONLY)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/dorie DESTINATION ${CMAKE_INSTALL_BINDIR}) # copy the temporary file into the final destination, setting the permissions
file(COPY ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/dorie
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/dorie DESTINATION ${CMAKE_INSTALL_BINDIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ
GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
...@@ -5,8 +5,8 @@ DORIEDIR=@CMAKE_BINARY_DIR@ ...@@ -5,8 +5,8 @@ DORIEDIR=@CMAKE_BINARY_DIR@
MPIRUN=@MPIEXEC@ MPIRUN=@MPIEXEC@
############################ ############################
DORIE_EXECUTABLE=$DORIEDIR/src/dorie DORIE_EXECUTABLE=$DORIEDIR/dune/dorie/dorie
PARAMETERDIR=$DORIEDIR/doc/parameters PARAMETERDIR=$DORIEDIR/doc/default_files
DORIE_PYTHON=$DORIEDIR/dune-env DORIE_PYTHON=$DORIEDIR/dune-env
run_dorie_sequential() run_dorie_sequential()
...@@ -30,8 +30,10 @@ initialize_folder() ...@@ -30,8 +30,10 @@ initialize_folder()
echo "###################" echo "###################"
echo "INITIALIZING FOLDER" echo "INITIALIZING FOLDER"
echo "###################" echo "###################"
cp -iv $PARAMETERDIR/default.ini parameter.ini cp -iv $PARAMETERDIR/default.ini $PWD/config.ini
cp -iv $PARAMETERDIR/default_bc.dat bc.dat cp -iv $PARAMETERDIR/default_pf.ini $PWD/parfield.ini
cp -iv $PARAMETERDIR/2d_infiltr.bcdat $PWD/2d_infiltr.bcdat
cp -iv $PARAMETERDIR/3d_infiltr.bcdat $PWD/3d_infiltr.bcdat
echo "Initialization done" echo "Initialization done"
} }
...@@ -40,6 +42,11 @@ plot_vtk() ...@@ -40,6 +42,11 @@ plot_vtk()
$DORIE_PYTHON plot_vtk.py --vtk $1 --var $2 $DORIE_PYTHON plot_vtk.py --vtk $1 --var $2
} }
pf_from_file()
{
$DORIE_PYTHON pf_from_file.py --param $1 --debug
}
################### ###################
# CHECK IF DORIE WAS INSTALLED # CHECK IF DORIE WAS INSTALLED
...@@ -51,6 +58,7 @@ fi ...@@ -51,6 +58,7 @@ fi
RUN=0 RUN=0
PLOT=0 PLOT=0
CREATE=0 CREATE=0
PFG=0
PARALLEL=0 PARALLEL=0
# NO ARGUMENTS SUPPLIED # NO ARGUMENTS SUPPLIED
...@@ -62,8 +70,7 @@ fi ...@@ -62,8 +70,7 @@ fi
# PARSE EACH ARGUMENT # PARSE EACH ARGUMENT
case $1 in case $1 in
run) # run dorie
run)
RUN=1 RUN=1
shift shift
if [[ $# > 0 ]]; then if [[ $# > 0 ]]; then
...@@ -97,6 +104,16 @@ case $1 in ...@@ -97,6 +104,16 @@ case $1 in
esac esac
fi fi
if [[ -e $INIFILE && -f $INIFILE && -s $INIFILE ]]; then
if [[ $PARALLEL > 0 ]]; then
run_dorie_parallel $INIFILE $PARALLEL
else
run_dorie_sequential $INIFILE
fi
else
echo "Error: Invalid parameter file $INIFILE"
fi
exit
;; ;;
plot) plot)
...@@ -125,20 +142,36 @@ case $1 in ...@@ -125,20 +142,36 @@ case $1 in
shift shift
done done
fi fi
plot_vtk "$VTKFILE" "$VARIABLES"
exit
;; ;;
create) create)
CREATE=1 initialize_folder
exit
;;
pfg)
shift
if [[ $# = 1 ]]; then
pf_from_file $1
exit
else
echo "Usage: dorie pfg INIFILE. For more information run 'dorie help'"
exit
fi
;; ;;
help) help)
echo -e "Usage: dorie COMMAND [COMMAND-OPTIONS]\n" echo -e "Usage: dorie COMMAND [COMMAND-OPTIONS]\n"
echo -e "COMMANDS:" echo -e "COMMANDS:"
echo -e " 'run INIFILE [OPTIONS]' starts DORiE with parameter file INIFILE" echo -e " 'run INIFILE [OPTIONS]' starts DORiE with parameter file INIFILE"
echo -e " OPTIONS:" echo -e " OPTIONS:"
echo -e " '--parallel NPROC' starts DORiE in parallel with NPROC processes" echo -e " '--parallel NPROC' starts DORiE in parallel with NPROC processes"
echo -e " '--sequential' starts DORiE in sequential mode (default)" echo -e " '--sequential' starts DORiE in sequential mode (default)"
echo -e " 'create' creates dummy parameter files in the current directory" echo -e " 'create' creates dummy parameter files in the current directory"
echo -e " 'pfg INIFILE' runs the parameter field generator"
echo -e " 'plot VTK [--var VAR]' plots the variables VAR (default: all variables) from the VTK file(s) VTK" echo -e " 'plot VTK [--var VAR]' plots the variables VAR (default: all variables) from the VTK file(s) VTK"
echo -e " 'help' displays this message" echo -e " 'help' displays this message"
...@@ -150,31 +183,3 @@ case $1 in ...@@ -150,31 +183,3 @@ case $1 in
exit exit
;; ;;
esac esac
# RUN DORIE
if [[ $RUN = 1 ]]; then
if [[ -e $INIFILE && -f $INIFILE && -s $INIFILE ]]; then
if [[ $PARALLEL > 0 ]]; then
run_dorie_parallel $INIFILE $PARALLEL
else
run_dorie_sequential $INIFILE
fi
else
echo "Error: Invalid parameter file $INIFILE"
fi
exit
fi
# INITIALIZE FOLDER
if [[ $CREATE = 1 ]]; then
initialize_folder
exit
fi
# PLOT VTK FILES
if [[ $PLOT = 1 ]]; then
plot_vtk "$VTKFILE" "$VARIABLES"
exit
fi
# File for module specific CMake tests. # File for module specific CMake tests.
# find all required packages # find all required packages
FIND_PACKAGE (HDF5 REQUIRED) FIND_PACKAGE (HDF5 REQUIRED COMPONENTS C)
if(HDF5_IS_PARALLEL)
message(STATUS "Parallel HDF5 library found")
add_definitions(-DHDF5_PARALLEL)
endif()
FIND_PACKAGE (FFTW REQUIRED) FIND_PACKAGE (FFTW REQUIRED)
FIND_PACKAGE (SuperLU REQUIRED) FIND_PACKAGE (SuperLU REQUIRED)
FIND_PACKAGE (MPI REQUIRED) FIND_PACKAGE (MPI REQUIRED)
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
...@@ -29,7 +29,11 @@ ...@@ -29,7 +29,11 @@
#include "datatypes.hh" #include "datatypes.hh"
#include "Vector.hh" #include "Vector.hh"
#include "tools.hh" #include "tools.hh"
#include "H5Tools.hh" #if HDF5_PARALLEL
#include "H5Tools_parallel.hh"
#else
#include "H5Tools_sequential.hh"
#endif
#include "FieldData.hh" #include "FieldData.hh"
#include "random_field_generator.hh" #include "random_field_generator.hh"
......
...@@ -254,7 +254,7 @@ namespace Dune { ...@@ -254,7 +254,7 @@ namespace Dune {
*/ */
H5Tools::h5_pWrite( R_YY H5Tools::h5_Write( R_YY
, fielddata.location + "/R_YY.h5" , fielddata.location + "/R_YY.h5"
, "/R_YY" , "/R_YY"
, nCells_ExtendedDomain , nCells_ExtendedDomain
...@@ -345,7 +345,7 @@ namespace Dune { ...@@ -345,7 +345,7 @@ namespace Dune {
// save FFT of R_YY! // save FFT of R_YY!
H5Tools::h5_pWrite( tmp_vec H5Tools::h5_Write( tmp_vec
, fielddata.location + "/FFT_R_YY.h5" , fielddata.location + "/FFT_R_YY.h5"
, "/FFT_R_YY" , "/FFT_R_YY"
, nCells_ExtendedDomain , nCells_ExtendedDomain
...@@ -435,7 +435,7 @@ namespace Dune { ...@@ -435,7 +435,7 @@ namespace Dune {
//loading in HDF5 //loading in HDF5
Vector<RF> tmp_vec; // temporary vector for the loaded eigenvalues Vector<RF> tmp_vec; // temporary vector for the loaded eigenvalues
H5Tools::h5_pRead( tmp_vec H5Tools::h5_Read( tmp_vec
, fielddata.location + "/FFT_R_YY.h5" , fielddata.location + "/FFT_R_YY.h5"
, "/FFT_R_YY" , "/FFT_R_YY"
, local_count , local_count
...@@ -608,7 +608,7 @@ namespace Dune { ...@@ -608,7 +608,7 @@ namespace Dune {
fftw_free( KField ); fftw_free( KField );
// save the field to disc // save the field to disc
H5Tools::h5_pWrite( tmp, H5Tools::h5_Write( tmp,
fielddata.location + "/YField.h5", fielddata.location + "/YField.h5",
"/YField", "/YField",
fielddata.nCells, fielddata.nCells,
...@@ -620,7 +620,7 @@ namespace Dune { ...@@ -620,7 +620,7 @@ namespace Dune {
l = tmp.size(); l = tmp.size();
tmp.resize(0); tmp.resize(0);
tmp.resize(l,1.0); tmp.resize(l,1.0);
H5Tools::h5_pWrite( tmp, H5Tools::h5_Write( tmp,
fielddata.location + "/matX.h5", fielddata.location + "/matX.h5",
"/X", "/X",
fielddata.nCells, fielddata.nCells,
...@@ -631,8 +631,10 @@ namespace Dune { ...@@ -631,8 +631,10 @@ namespace Dune {
if(comm_size==1){ if(comm_size==1){
H5Tools::h5_Read( YFieldVector, H5Tools::h5_Read( YFieldVector,
fielddata.location + "/YField.h5", fielddata.location + "/YField.h5",
"/YField" "/YField",
); local_count,
local_offset,
comm );
UINT N = YFieldVector.size(); UINT N = YFieldVector.size();
...@@ -645,11 +647,6 @@ namespace Dune { ...@@ -645,11 +647,6 @@ namespace Dune {
}; // End of void generateY() }; // End of void generateY()
// If fielddata.newEV==false and fielddata.newField==false, // If fielddata.newEV==false and fielddata.newField==false,
// we try to load an existing field. // we try to load an existing field.
bool load_from_file() { bool load_from_file() {
...@@ -672,9 +669,16 @@ namespace Dune { ...@@ -672,9 +669,16 @@ namespace Dune {
<< std::endl; << std::endl;
if(comm_size==1){ if(comm_size==1){
Vector<UINT> local_count(dim,0);
Vector<UINT> local_offset(dim,0);
H5Tools::h5_Read( YFieldVector, H5Tools::h5_Read( YFieldVector,
fielddata.location + "/YField.h5", fielddata.location + "/YField.h5",
"/YField" "/YField",
local_count,
local_offset,
comm
); );
UINT N = YFieldVector.size(); UINT N = YFieldVector.size();
...@@ -689,134 +693,6 @@ namespace Dune { ...@@ -689,134 +693,6 @@ namespace Dune {
} }
//
// Read Y-field from HDF5 file.
//
void h5_Read( const std::string& filename, const std::string& groupname ){
Vector<REAL> yfield_vector;
H5Tools::h5_Read( yfield_vector,
filename,
groupname );
import_from_vector( yfield_vector );
}
void import_from_vector(const Vector<RF>& yfield_vector) {
UINT VectorSize = 0;
if (dim == 3) {
const UINT L = fielddata.nCells[2];
const UINT M = fielddata.nCells[1];
const UINT N = fielddata.nCells[0];
VectorSize = L * M * N;
}
else {
const UINT M = fielddata.nCells[1];
const UINT N = fielddata.nCells[0];
VectorSize = M * N;
}
if( yfield_vector.size() != VectorSize ){
// std::cout << "Warning: mismatch at import_from_vector: " << std::endl;
// std::cout << "yfield_vector.size() = " << yfield_vector.size() << std::endl;
// std::cout << "VectorSize = " << VectorSize << std::endl;
DUNE_THROW(RangeError, "Mismatch at import_from vector: \n"
<< "yfield_vector.size() = " << yfield_vector.size() << "\n"
<< "VectorSize = " << VectorSize << ".\n"
<< "Possible reason could be: different dimensions of domain and hdf5-file.");
}
YFieldVector = yfield_vector;
KFieldVector.resize( VectorSize );
for (UINT l=0; l<VectorSize; l++)
KFieldVector[l] = std::exp( yfield_vector[l] );
};
//
// Read Y-field from HDF5 file in parallel mode onto the grid.
//
template<typename GV>
void h5g_pRead( GV gv,
const std::string& filename,
const std::string& groupname
){
Vector<REAL> local_Yfield_vector;
Vector<UINT> local_count;
Vector<UINT> local_offset;
H5Tools::h5g_pRead( local_Yfield_vector,
filename,
groupname,
gv,
fielddata.nCells,
fielddata.gridsizes,
local_count,
local_offset
);
if( my_rank==0 )
std::cout << "Parallel import of Yfield data from " << filename << std::endl;
parallel_import_from_local_vector( local_Yfield_vector, local_count, local_offset );
}
void parallel_import_from_local_vector( const Vector<RF>& local_Yfield_vector,
const Vector<UINT>& local_count,
const Vector<UINT>& local_offset)
{
UINT Nlocal = local_Yfield_vector.size();
LocalYFieldVector.clear();
LocalYFieldVector = local_Yfield_vector; // this vector contains the Y-field data from the current hyperslab
LocalKFieldVector.clear();
LocalKFieldVector.resize( Nlocal );
for( UINT i=0; i<Nlocal; ++i )
LocalKFieldVector[i] = std::exp( local_Yfield_vector[i] );
LocalCount.resize(dim);
LocalOffset.resize(dim);
LocalCount = local_count; // this vector contains the dimensions (the number of cells per dimension) of the current hyperslab
LocalOffset = local_offset; // this vector describes the distance of the current hyperslab from the origin
};
void export_to_vector(OutputVector& yfield_vector )
{
UINT VectorSize = 0;
if (dim == 3)
{
const UINT L = fielddata.nCells[2];
const UINT M = fielddata.nCells[1];
const UINT N = fielddata.nCells[0];
VectorSize = L * M * N;
}
else
{
const UINT M = fielddata.nCells[1];
const UINT N = fielddata.nCells[0];
VectorSize = M * N;
}
//yfield_vector.resize( VectorSize );
for (UINT l = 0; l < VectorSize; l++)
yfield_vector[l] = YFieldVector[l];
return;
};
void init() void init()
{ {
if(my_rank==0) if(my_rank==0)
...@@ -920,11 +796,11 @@ namespace Dune { ...@@ -920,11 +796,11 @@ namespace Dune {
//std::cout << "...exponential variogram..." << std::endl; //std::cout << "...exponential variogram..." << std::endl;
C1 = variance * exp(-h_eff); C1 = variance * exp(-h_eff);
} }
else if( !strcmp( model.c_str(), "lorentz" ) ){ else if( !strcmp( model.c_str(), "lorentz" ) ){
// std::cout << "############################################" << std::endl; // std::cout << "############################################" << std::endl;
// std::cout << "... lorentzian variogram..." << std::endl; // std::cout << "... lorentzian variogram..." << std::endl;
C1 = variance * 1.0/(1+sum); C1 = variance * 1.0/(1+sum);
} }
else{ // gaussian else{ // gaussian
//std::cout << "...gaussian variogram..." << std::endl; //std::cout << "...gaussian variogram..." << std::endl;
C1 = variance * exp(-sum); C1 = variance * exp(-sum);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment