Commit 408de613 authored by Jonas Schmitt's avatar Jonas Schmitt

AnyDSL-MD: Included cell and particle creation and initialization

parent 01929289
Pipeline #3260 failed with stage
in 11 minutes and 19 seconds
# Benchmarks
if ( WALBERLA_BUILD_BENCHMARKS )
add_subdirectory ( benchmarks )
else ()
add_subdirectory ( benchmarks EXCLUDE_FROM_ALL )
endif()
#if ( WALBERLA_BUILD_BENCHMARKS )
# add_subdirectory ( benchmarks )
#else ()
# add_subdirectory ( benchmarks EXCLUDE_FROM_ALL )
#endif()
# Tools
......@@ -16,11 +16,11 @@ endif()
# Tutorials
if ( WALBERLA_BUILD_TUTORIALS )
add_subdirectory ( tutorials )
else ()
add_subdirectory ( tutorials EXCLUDE_FROM_ALL )
endif()
#if ( WALBERLA_BUILD_TUTORIALS )
# add_subdirectory ( tutorials )
#else ()
# add_subdirectory ( tutorials EXCLUDE_FROM_ALL )
#endif()
add_subdirectory ( anydsl )
......
......@@ -5,14 +5,17 @@ include_directories(${ANYDSL_RUNTIME_DIR}/src)
set(CLANG_FLAGS -O3 -march=native)
set(IMPALA_FLAGS --log-level info)
set(IMPALA_SRC_DIR anydsl-md/impala)
# examples based on the "mapping"
anydsl_runtime_wrap(IMPALA_OBJECT_FILE
CLANG_FLAGS ${CLANG_FLAGS}
IMPALA_FLAGS ${IMPALA_FLAGS}
FILES anydsl-md/impala/intrinsics/intrinsics_cpu.impala anydsl-md/impala/common.impala anydsl-md/impala/datastructures/linked_cell/cpu.impala anydsl-md/impala/utilities/linked_cell/cpu.impala anydsl-md/impala/algorithm/linked_cell/cpu.impala anydsl-md/impala/initialization/test.impala anydsl-md/impala/potential/lennard_jones.impala anydsl-md/impala/integration/verlet.impala anydsl-md/impala/boundary/rigid_walls.impala anydsl-md/impala/time_integration/cpu.impala anydsl-md/impala/run/cpu.impala)
FILES ${IMPALA_SRC_DIR}/intrinsics/intrinsics_cpu.impala ${IMPALA_SRC_DIR}/common.impala ${IMPALA_SRC_DIR}/datastructures/linked_cell/cpu.impala ${IMPALA_SRC_DIR}/utilities/linked_cell/cpu.impala ${IMPALA_SRC_DIR}/algorithm/linked_cell/cpu.impala ${IMPALA_SRC_DIR}/initialization/test.impala ${IMPALA_SRC_DIR}/potential/lennard_jones.impala ${IMPALA_SRC_DIR}/integration/verlet.impala ${IMPALA_SRC_DIR}/boundary/rigid_walls.impala ${IMPALA_SRC_DIR}/time_integration/cpu.impala
${IMPALA_SRC_DIR}/walberla_runtime/cpu.impala)
waLBerla_add_executable ( NAME md_simulation
FILES md_simulation.cpp ${IMPALA_OBJECT_FILE} anydsl-md/impala/clib/fileIO.c anydsl-md/impala/clib/allocate.c
DEPENDS core blockforest pe domain_decomposition vtk)
FILES ${IMPALA_OBJECT_FILE} ${IMPALA_SRC_DIR}/clib/fileIO.c ${IMPALA_SRC_DIR}/clib/allocate.c md_simulation.cpp
DEPENDS core blockforest pe domain_decomposition vtk
)
target_link_libraries(md_simulation m ${ANYDSL_RUNTIME_LIBRARY} ${ANYDSL_RUNTIME_LIBRARIES})
......@@ -47,6 +47,20 @@ using namespace walberla::timing;
typedef boost::tuple<Sphere, Plane> BodyTuple ;
extern "C" void initialize_particle_system(size_t, size_t, double[]);
extern "C" void reinitialize_particle_system(size_t);
extern "C" void clean_up();
extern "C" void set_coordinates(double[], size_t);
extern "C" void set_velocities(double[], size_t);
extern "C" void set_mass(double, size_t);
extern "C" void sort_particle_system();
extern "C" void print_particle_system_();
extern "C" size_t get_number_of_particles();
extern "C" size_t get_address_at(size_t);
int main( int argc, char ** argv )
{
Environment env(argc, argv);
......@@ -91,9 +105,9 @@ int main( int argc, char ** argv )
WALBERLA_LOG_INFO_ON_ROOT("vMax: " << vMax);
realProperties["vMax"] = vMax;
int warmupSteps = mainConf.getParameter<int>("warmupSteps", 0 );
WALBERLA_LOG_INFO_ON_ROOT("warmupSteps: " << warmupSteps);
integerProperties["warmupSteps"] = warmupSteps;
//int warmupSteps = mainConf.getParameter<int>("warmupSteps", 0 );
//WALBERLA_LOG_INFO_ON_ROOT("warmupSteps: " << warmupSteps);
//integerProperties["warmupSteps"] = warmupSteps;
int simulationSteps = mainConf.getParameter<int>("simulationSteps", 200 );
WALBERLA_LOG_INFO_ON_ROOT("simulationSteps: " << simulationSteps);
......@@ -145,10 +159,9 @@ int main( int argc, char ** argv )
MPI_Barrier(MPI_COMM_WORLD);
// add block data
auto storageID = forest->addBlockData(createStorageDataHandling<BodyTuple>(), "Storage");
auto ccdID = forest->addBlockData(ccd::createHashGridsDataHandling( globalBodyStorage, storageID ), "CCD");
auto fcdID = forest->addBlockData(fcd::createSimpleFCDDataHandling<BodyTuple>(), "FCD");
//auto ccdID = forest->addBlockData(ccd::createHashGridsDataHandling( globalBodyStorage, storageID ), "CCD");
//auto fcdID = forest->addBlockData(fcd::createSimpleFCDDataHandling<BodyTuple>(), "FCD");
//TODO SOLVER
WALBERLA_LOG_INFO_ON_ROOT("*** SYNCCALL ***");
pe::syncNextNeighbors<BodyTuple>(*forest, storageID, &tt, real_c(0.0), false );
......@@ -173,7 +186,6 @@ int main( int argc, char ** argv )
tt.start("Particle Creation");
uint_t numParticles = uint_c(0);
for (auto blkIt = forest->begin(); blkIt != forest->end(); ++blkIt)
{
IBlock & currentBlock = *blkIt;
......@@ -185,28 +197,148 @@ int main( int argc, char ** argv )
if (sp != NULL) ++numParticles;
}
}
tt.stop("Particle Creation");
mpi::reduceInplace(numParticles, mpi::SUM);
WALBERLA_LOG_INFO_ON_ROOT("#particles created: " << numParticles);
WALBERLA_LOG_INFO_ON_ROOT("*** SETUP - END ***");
// synchronize particles
pe::syncNextNeighbors<BodyTuple>(*forest, storageID, &tt, real_c(0.0), false );
pe::syncNextNeighbors<BodyTuple>(*forest, storageID, &tt, real_c(0.0), false );
tt.start("Cell creation");
double l[3];
l[0] = 0.0;
l[1] = 0.0;
l[2] = 0.0;
uint_t np_local = 0;
for (auto blkIt = forest->begin(); blkIt != forest->end(); ++blkIt)
{
IBlock & currentBlock = *blkIt;
auto aabb = currentBlock.getAABB();
if(l[0] < aabb.xMax()) {
l[0] = aabb.xMax();
}
if(l[1] < aabb.yMax()) {
l[1] = aabb.yMax();
}
if(l[2] < aabb.zMax()) {
l[2] = aabb.zMax();
}
Storage * storage = currentBlock.getData< Storage >( storageID );
BodyStorage& localStorage = (*storage)[0];
BodyStorage& shadowStorage = (*storage)[1];
np_local = localStorage.size() + shadowStorage.size();
}
size_t const ghost_layer = 1;
WALBERLA_LOG_INFO_ON_ROOT("#particles on root: " << np_local);
initialize_particle_system(np_local, ghost_layer, l);
//print_particle_system_();
for (auto blkIt = forest->begin(); blkIt != forest->end(); ++blkIt)
{
IBlock & currentBlock = *blkIt;
Storage * storage = currentBlock.getData< Storage >( storageID );
BodyStorage& localStorage = (*storage)[0];
BodyStorage& shadowStorage = (*storage)[1];
/*
size_t j = 0;
for( auto bodyIt = localStorage.begin(); bodyIt != localStorage.end(); ++bodyIt ) {
WALBERLA_LOG_INFO_ON_ROOT("address " << j << " on root: " << get_address_at(j));
++j;
}
for( auto bodyIt = shadowStorage.begin(); bodyIt != shadowStorage.end(); ++bodyIt ) {
WALBERLA_LOG_INFO_ON_ROOT("address " << j << " on root: " << get_address_at(j));
++j;
}
*/
}
tt.stop("Cell creation");
WALBERLA_LOG_INFO_ON_ROOT("*** SIMULATION - START ***");
WcTimingPool tp;
tt.start("Simulation Loop");
tp["Total"].start();
for (int i=0; i < simulationSteps; ++i)
{
if( i % 200 == 0 )
if( i % 10 == 0 )
{
WALBERLA_LOG_DEVEL_ON_ROOT( "Timestep " << i << " / " << simulationSteps );
WALBERLA_LOG_DEVEL_ON_ROOT( "Timestep " << i << " / " << simulationSteps );
}
tp["Solver"].start();
///////////////* Solver Begin */////////////////
for (auto blkIt = forest->begin(); blkIt != forest->end(); ++blkIt)
{
IBlock & currentBlock = *blkIt;
auto aabb = currentBlock.getAABB();
/*
WALBERLA_LOG_INFO_ON_ROOT("xMin: " << aabb.xMin());
WALBERLA_LOG_INFO_ON_ROOT("yMin: " << aabb.yMin());
WALBERLA_LOG_INFO_ON_ROOT("zMin: " << aabb.zMin());
WALBERLA_LOG_INFO_ON_ROOT("xMax: " << aabb.xMax());
WALBERLA_LOG_INFO_ON_ROOT("yMax: " << aabb.yMax());
WALBERLA_LOG_INFO_ON_ROOT("zMax: " << aabb.zMax());
*/
Storage * storage = currentBlock.getData< Storage >( storageID );
BodyStorage& localStorage = (*storage)[0];
BodyStorage& shadowStorage = (*storage)[1];
reinitialize_particle_system(np_local);
np_local = localStorage.size() + shadowStorage.size();
WALBERLA_LOG_INFO_ON_ROOT("#particles on root: " << get_number_of_particles());
size_t j = 0;
for( auto bodyIt = localStorage.begin(); bodyIt != localStorage.end(); ++bodyIt ) {
//WALBERLA_LOG_INFO_ON_ROOT("address " << j << " on root: " << get_address_at(j));
double mass = bodyIt->getMass();
auto position = bodyIt->getPosition();
auto velocity = bodyIt->getLinearVel();
double X[3], Y[3];
for(size_t d = 0; d < 3; ++d) {
X[d] = position[d];
Y[d] = velocity[d];
}
set_mass(mass, j);
set_coordinates(X, j);
set_velocities(Y, j);
++j;
}
for( auto bodyIt = shadowStorage.begin(); bodyIt != shadowStorage.end(); ++bodyIt ) {
//WALBERLA_LOG_INFO_ON_ROOT("address " << j << " on root: " << get_address_at(j));
double mass = bodyIt->getMass();
auto position = bodyIt->getPosition();
auto velocity = bodyIt->getLinearVel();
double X[3], Y[3];
for(size_t d = 0; d < 3; ++d) {
X[d] = position[d];
Y[d] = velocity[d];
}
set_mass(mass, j);
set_coordinates(X, j);
set_velocities(Y, j);
++j;
}
sort_particle_system();
}
///////////////* Solver End */////////////////
tp["Solver"].end();
tp["Sync"].start();
pe::syncNextNeighbors<BodyTuple>(*forest, storageID, &tt, real_c(0.0), false );
......@@ -219,6 +351,7 @@ int main( int argc, char ** argv )
}
tp["Total"].end();
tt.stop("Simulation Loop");
clean_up();
MPI_Barrier(MPI_COMM_WORLD);
WALBERLA_LOG_INFO_ON_ROOT("*** SIMULATION - END ***");
......
CouetteFlow
{
outputSetupForest false;
//////////////////////////////
// GENERAL SIMULATION SPECS //
//////////////////////////////
xBlocks 1;
yBlocks 1;
zBlocks 1;
xCells 10;
yCells 30;
zCells 10;
memoryPerCell 153; // in bytes
processMemoryLimit 2048; // in MiB !
Re 10;
initWithMeanVelocity false; // false = fluid is at rest
///////////////////////
// WHERE TO REFINE ? //
///////////////////////
refineOnBorder false;
borderRefinementLevel 2;
////////////////////////////
// RUNNING THE SIMULATION //
////////////////////////////
outerTimeSteps 1; // total number of time steps = outerTimeSteps * innerTimeSteps
innerTimeSteps 10000; // For each outer loop, performance data is logged.
VolumetricFlowRateEvaluation
{
plotFrequency 0;
logFrequency 10000;
axis <true,false,false>;
point <0.5,0.5,0.5>;
}
AccuracyEvaluation
{
plotFrequency 0;
logFrequency 10000;
}
StabilityChecker
{
checkFrequency 10000;
}
remainingTimeLoggerFrequency 3; // in seconds
vtkBeforeTimeStep true; // false = at the end of time step
logToSqlDB false;
///////////////////////////
// SRT - TRT - MRT setup //
///////////////////////////
omega 0.7;
// magicNumber 0.25; // Used to setup TRT and MRT in case if and only if no additional parameters
// except 'omega' are specified here in the input file. [default: 0.1875]
// lambda_e 1.98; // If "--trt" is used AND 'lambda_e' and 'lambda_d' are both specified here
// lambda_d 1.95; // in the input file then these two parameters are used for setting up TRT.
// Otherwise 'omega' is used to set up TRT.
// Setting up TRT to mimic SRT: set lambda_e and lambda_d to the same value
// If "--mrt" is used AND 's1', 's2', 's4', 's9', 's10', and 's16' are all specified here in the input file
// then these parameters are used for setting up MRT. Otherwise 'omega' is used to set up MRT.
// s1 1.19; // s_e
// s2 1.4; // s_epsilon
// s4 1.2; // s_q
// s9 1.99; // s_nu
// s10 1.4; // s_pi
// s16 1.98; // s_m
// Setting up MRT to mimic SRT: set all parameters to the same value
// Setting up MRT to mimic TRT: set s1, s2, s9, and s10 to lambda_e and s4 and s16 to lambda_d
//////////////////
// CHECK AT END //
//////////////////
check true;
checkFlowRateError 1E-13; // upper bound for rel. error of the flow rate
checkErrorL1 1E-13; // upper bound for L1 norm (normalized to a volume of 1x1x1 and a maximum velocity of 1)
}
/home/staff/schmitt/Research/walberla/apps/benchmarks/CouetteFlow/Test0.dat
\ No newline at end of file
CouetteFlow
{
outputSetupForest false;
//////////////////////////////
// GENERAL SIMULATION SPECS //
//////////////////////////////
xBlocks 1;
yBlocks 3;
zBlocks 1;
xCells 10;
yCells 10;
zCells 10;
memoryPerCell 153; // in bytes
processMemoryLimit 2048; // in MiB !
Re 10;
initWithMeanVelocity false; // false = fluid is at rest
///////////////////////
// WHERE TO REFINE ? //
///////////////////////
refineOnBorder true;
borderRefinementLevel 2;
////////////////////////////
// RUNNING THE SIMULATION //
////////////////////////////
outerTimeSteps 1; // total number of time steps = outerTimeSteps * innerTimeSteps
innerTimeSteps 10000; // For each outer loop, performance data is logged.
VolumetricFlowRateEvaluation
{
plotFrequency 0;
logFrequency 10000;
axis <true,false,false>;
point <0.5,0.5,0.5>;
}
AccuracyEvaluation
{
plotFrequency 0;
logFrequency 10000;
}
StabilityChecker
{
checkFrequency 10000;
}
remainingTimeLoggerFrequency 3; // in seconds
vtkBeforeTimeStep true; // false = at the end of time step
logToSqlDB false;
///////////////////////////
// SRT - TRT - MRT setup //
///////////////////////////
omega 0.7;
// magicNumber 0.25; // Used to setup TRT and MRT in case if and only if no additional parameters
// except 'omega' are specified here in the input file. [default: 0.1875]
// lambda_e 1.98; // If "--trt" is used AND 'lambda_e' and 'lambda_d' are both specified here
// lambda_d 1.95; // in the input file then these two parameters are used for setting up TRT.
// Otherwise 'omega' is used to set up TRT.
// Setting up TRT to mimic SRT: set lambda_e and lambda_d to the same value
// If "--mrt" is used AND 's1', 's2', 's4', 's9', 's10', and 's16' are all specified here in the input file
// then these parameters are used for setting up MRT. Otherwise 'omega' is used to set up MRT.
// s1 1.19; // s_e
// s2 1.4; // s_epsilon
// s4 1.2; // s_q
// s9 1.99; // s_nu
// s10 1.4; // s_pi
// s16 1.98; // s_m
// Setting up MRT to mimic SRT: set all parameters to the same value
// Setting up MRT to mimic TRT: set s1, s2, s9, and s10 to lambda_e and s4 and s16 to lambda_d
//////////////////
// CHECK AT END //
//////////////////
check true;
checkFlowRateError 1E-13; // upper bound for rel. error of the flow rate
checkErrorL1 1E-13; // upper bound for L1 norm (normalized to a volume of 1x1x1 and a maximum velocity of 1)
}
/home/staff/schmitt/Research/walberla/apps/benchmarks/CouetteFlow/Test2.dat
\ No newline at end of file
CouetteFlow
{
outputSetupForest false;
//////////////////////////////
// GENERAL SIMULATION SPECS //
//////////////////////////////
xBlocks 1;
yBlocks 3;
zBlocks 1;
xCells 10;
yCells 10;
zCells 10;
memoryPerCell 153; // in bytes
processMemoryLimit 2048; // in MiB !
Re 10;
initWithMeanVelocity false; // false = fluid is at rest
///////////////////////
// WHERE TO REFINE ? //
///////////////////////
refineOnBorder true;
borderRefinementLevel 2;
////////////////////////////
// RUNNING THE SIMULATION //
////////////////////////////
outerTimeSteps 1; // total number of time steps = outerTimeSteps * innerTimeSteps
innerTimeSteps 2; // For each outer loop, performance data is logged.
StabilityChecker
{
checkFrequency 2;
}
remainingTimeLoggerFrequency 3; // in seconds
vtkBeforeTimeStep true; // false = at the end of time step
logToSqlDB false;
///////////////////////////
// SRT - TRT - MRT setup //
///////////////////////////
omega 0.7;
// magicNumber 0.25; // Used to setup TRT and MRT in case if and only if no additional parameters
// except 'omega' are specified here in the input file. [default: 0.1875]
// lambda_e 1.98; // If "--trt" is used AND 'lambda_e' and 'lambda_d' are both specified here
// lambda_d 1.95; // in the input file then these two parameters are used for setting up TRT.
// Otherwise 'omega' is used to set up TRT.
// Setting up TRT to mimic SRT: set lambda_e and lambda_d to the same value
// If "--mrt" is used AND 's1', 's2', 's4', 's9', 's10', and 's16' are all specified here in the input file
// then these parameters are used for setting up MRT. Otherwise 'omega' is used to set up MRT.
// s1 1.19; // s_e
// s2 1.4; // s_epsilon
// s4 1.2; // s_q
// s9 1.99; // s_nu
// s10 1.4; // s_pi
// s16 1.98; // s_m
// Setting up MRT to mimic SRT: set all parameters to the same value
// Setting up MRT to mimic TRT: set s1, s2, s9, and s10 to lambda_e and s4 and s16 to lambda_d
//////////////////
// CHECK AT END //
//////////////////
check false;
}
/home/staff/schmitt/Research/walberla/apps/benchmarks/CouetteFlow/TestNoCheck.dat
\ No newline at end of file
CouetteFlow
{
// 3 different modes of operation:
// -------------------------------
// NO sbffile and NO saveToFile -> domain decomposition is created on the fly and simulation is run
// sbffile and NO saveToFile -> domain decomposition is loaded from file and simulation is run
// sbffile and saveToFile -> domain decomposition is created and saved to file (simulation is NOT run!)
// sbffile grid.sbf;
// blocksPerProcess 7;
// saveToFile; // does not require additional arguments
outputSetupForest true; // generates: "domain_decomposition.vtk" and "process_distribution.csv"
//////////////////////////////
// GENERAL SIMULATION SPECS //
//////////////////////////////
xBlocks 1;
yBlocks 4;
zBlocks 1;
xCells 10;
yCells 10;
zCells 10;
memoryPerCell 153; // in bytes
processMemoryLimit 2048; // in MiB !
Re 10;
initWithMeanVelocity false; // false = fluid is at rest
///////////////////////
// WHERE TO REFINE ? //
///////////////////////
refineOnBorder false;
borderRefinementLevel 2;
borderRefinementBuffer 0; // in number of cells in the coarsest level
AABBRefinementSelection
{
/*
Region
{
level 2;
region [ <0.499,0.499,0.499>, <0.501,0.501,0.501> ];
}
*/
/*
Region
{
level 2;
region [ <0,0.499,0>, <1,0.501,1> ];
}
*/
/*
Region
{
level 2;
region [ <0,0,0>, <1,1,1> ];
}
*/
}
////////////////////////////
// RUNNING THE SIMULATION //
////////////////////////////
outerTimeSteps 20; // total number of time steps = outerTimeSteps * innerTimeSteps
innerTimeSteps 1000; // For each outer loop, performance data is logged.
VolumetricFlowRateEvaluation
{
plotFrequency 10;
logFrequency 1000;
filename FlowRate.txt;
axis <true,false,false>;
point <0.5,0.5,0.5>;
}
AccuracyEvaluation
{
plotFrequency 10;
logFrequency 1000;
filename Accuracy.txt;
}
AccuracyEvaluationLinePlot
{
y true;
point <0.5,0.5,0.5>;
domain [<-1,-1,-1>,<1,1,1>];
filename linePlot.dat;
}
AccuracyEvaluationLinePlotter
{
frequency 1000;
filename linePlot;
extension dat;
}
MassEvaluation
{
plotFrequency 10;
logFrequency 1000;
filename Mass.txt;
}
StabilityChecker
{
checkFrequency 10;
streamOutput false;
vtkOutput true;
vtkBaseFolder stability_check;
vtkBinary true;
vtkLittleEndian true;
vtkMPIIO true;
}
remainingTimeLoggerFrequency 3; // in seconds
vtkBeforeTimeStep true; // false = at the end of time step
logToSqlDB true;
sqlFile simulation.sqlite; // database used for logging the performance and accuracy of the simulation
///////////////////////////
// SRT - TRT - MRT setup //
///////////////////////////
omega 0.8;
// magicNumber 0.25; // Used to setup TRT and MRT in case if and only if no additional parameters
// except 'omega' are specified here in the input file. [default: 0.1875]
// lambda_e 1.98; // If "--trt" is used AND 'lambda_e' and 'lambda_d' are both specified here
// lambda_d 1.95; // in the input file then these two parameters are used for setting up TRT.
// Otherwise 'omega' is used to set up TRT.
// Setting up TRT to mimic SRT: set lambda_e and lambda_d to the same value
// If "--mrt" is used AND 's1', 's2', 's4', 's9', 's10', and 's16' are all specified here in the input file
// then these parameters are used for setting up MRT. Otherwise 'omega' is used to set up MRT.
// s1 1.19; // s_e
// s2 1.4; // s_epsilon
// s4 1.2; // s_q
// s9 1.99; // s_nu
// s10 1.4; // s_pi
// s16 1.98; // s_m
// Setting up MRT to mimic SRT: set all parameters to the same value
// Setting up MRT to mimic TRT: set s1, s2, s9, and s10 to lambda_e and s4 and s16 to lambda_d
relaxationParametersLevel 0;
//////////////////
// CHECK AT END //
//////////////////
check false;
checkFlowRateError 1E6; // upper bound for rel. error of the flow rate