Commit 00d0dd6c authored by Santiago Ospina De Los Ríos's avatar Santiago Ospina De Los Ríos
Browse files

[Transport] Unify tests, and update logging

parent 8273db73
......@@ -17,7 +17,6 @@ TransportSimulation<Traits>::TransportSimulation(
, gv(grid->leafGridView())
, mbe_slop(estimate_mbe_entries<typename MBE::size_type>(Traits::dim,Traits::GridGeometryType))
, mbe_tlop(1)
, verbose(inifile.get<int>("output.verbose"))
, output_type(_inifile.get<bool>("output.asciiVtk") ? Dune::VTK::OutputType::ascii : Dune::VTK::OutputType::base64)
{
Dune::Timer timer;
......@@ -76,14 +75,22 @@ TransportSimulation<Traits>::TransportSimulation(
"./");
}
if(verbose>1 && helper.rank()==0)
std::cout << "::: setup time " << std::setw(12) << std::setprecision(4) << std::scientific << timer.elapsed() << std::endl;
this->_log->info("Setup complete");
}
template<typename Traits>
void TransportSimulation<Traits>::operator_setup()
{
auto dof_count = gfs->globalSize();
this->_log->debug("Setting up grid operators and solvers");
if (helper.size() > 1) {
this->_log->debug(" DOF of this process: {}", dof_count);
}
dof_count = gv.comm().sum(dof_count);
this->_log->debug(" Total number of DOF: {}", dof_count);
if (!gf_water_flux)
DUNE_THROW(Dune::InvalidStateException,
"Pointer to gf_water_flux is invalid!");
......@@ -110,35 +117,24 @@ void TransportSimulation<Traits>::operator_setup()
// --- Time Step Operators ---
osm = std::make_unique<OSM>(*ts_param,*igo,*pdesolver);
osm->setVerbosityLevel(verbose+1);
osm->setVerbosityLevel(0);
gfs->update();
// some output makes it look intelligent
if(verbose>0){
ios_base_all_saver restore(std::cout);
if (helper.rank()==0){
std::cout << "OPERATOR SETUP:" << std::endl;
std::cout << " Finite Element Order: " << 0 << std::endl;
std::cout << " Highest level on grid: " << grid->maxLevel() << std::endl;
}
auto DOFnumber = gfs->globalSize();
if(verbose>1)
std::cout << " Process " << helper.rank() << ": number of DOF: " << DOFnumber << std::endl;
DOFnumber = gv.comm().sum(DOFnumber);
if (helper.rank()==0)
std::cout << " Total number of DOF: " << DOFnumber << std::endl;
}
operator_setup_flag = false;
}
template<typename Traits>
void TransportSimulation<Traits>::step()
{
// long time step log for level 'debug'
if (this->_log->should_log(spdlog::level::debug)) {
this->_log->info("Time Step {}:",
osm->result().successful.timesteps);
}
if (operator_setup_flag)
operator_setup();
bool succeed = false;
bool exception = false;
// Suggest times step for explicit methods.
// This assumes that timestep is never increased on failure!
......@@ -149,24 +145,50 @@ void TransportSimulation<Traits>::step()
controller->suggest_timestep(courant*cfl);
}
while (not succeed)
bool step_succeed = false;
bool exception = false;
while (not step_succeed)
{
// Obtain time variables
const auto t = controller->getTime();
const auto dt = controller->getDT();
const bool solver_warnings = verbose > 0 && helper.rank() == 0 ?
true : false;
const RF time = controller->getTime();
const RF dt = controller->getDT();
bool exception = false;
try
{
// long time step log for level 'debug'
if (this->_log->should_log(spdlog::level::debug)) {
this->_log->debug(" Time {:.2e} + {:.2e} -> {:.2e}",
time, dt, time+dt);
}
const auto iter = controller->getIterations();
_log->trace(" Allowed iterations for Newton solver: {}", iter);
pdesolver->setMaxIterations(iter);
std::shared_ptr<U> unext = std::make_shared<U>(*u);
if (not solver_warnings)
dwarn.push(false);
osm->apply(t, dt, *u, *unext);
if (not solver_warnings)
dwarn.pop();
dwarn.push(false);
osm->apply(time, dt, *u, *unext);
dwarn.pop();
// short time step log for level 'info' (after success)
if (not this->_log->should_log(spdlog::level::debug)) {
this->_log->info("Time Step {}: {:.2e} + {:.2e} -> {:.2e}",
osm->result().successful.timesteps-1,
time,
dt,
time+dt);
}
auto result = osm->result();
this->_log->trace(" Matrix assembly: {:.2e}s (total), {:.2e}s (success)",
result.total.assembler_time,
result.successful.assembler_time);
this->_log->trace(" Linear solver: {:.2e}s (total), {:.2e}s (success)",
result.total.linear_solver_time,
result.successful.linear_solver_time);
u = unext;
}
......@@ -178,12 +200,11 @@ void TransportSimulation<Traits>::step()
std::cerr << "FATAL ERROR occured!" << std::endl;
DUNE_THROW(Dune::Exception,e);
}
succeed = true;
// controller reacts to outcome of solution
step_succeed = controller->validate(exception);
}
// controller reacts to outcome of solution
controller->validate(exception);
if (this->output_policy() == OutputPolicy::EndOfStep)
write_data();
}
......@@ -215,14 +236,23 @@ void TransportSimulation<Traits>::write_data () const
}
try{
vtkwriter->write(time,output_type);
const auto time = controller->getTime();
this->_log->trace("Writing solution at time {:.2e}", time);
vtkwriter->write(time, output_type);
}
catch (Dune::Exception& e) {
this->_log->error("Writing VTK output failed: {}", e.what());
DUNE_THROW(Dune::IOError, "Cannot write VTK output!");
}
catch(...){
DUNE_THROW(Dune::IOError,"Cannot write VTK output!");
this->_log->error("Writing VTK output failed for unknown reason");
DUNE_THROW(Dune::IOError, "Cannot write VTK output!");
}
vtkwriter->clear();
} else
DUNE_THROW(Dune::IOError,"The function write_data() is disabled!");
} else {
this->_log->error("Calling 'write_data' on object without VTK writer");
DUNE_THROW(Dune::InvalidStateException, "No vtk writer configured!");
}
}
} // namespace Dorie
......
......@@ -244,8 +244,6 @@ protected:
std::unique_ptr<Writer> vtkwriter;
const int verbose;
const Dune::VTK::OutputType output_type;
bool operator_setup_flag = true;
public:
......
......@@ -32,29 +32,14 @@ add_custom_target(test_run_ref
COMMAND ctest --output-on-failure --tests-regex ^.+_ref_.+$
)
# trasport tests
# dorie run: Transport coupling tests
dorie_add_metaini_test(
TARGET transport
METAINI test-transport-muphi.mini.in
TARGET dorie
METAINI test-transport-coupling.mini.in
)
# dorie_add_metaini_test(
# TARGET transport
# METAINI test-transport-sand.mini.in
# )
# dorie_add_metaini_test(
# TARGET transport
# METAINI test-transport-silt.mini.in
# )
# dorie_add_metaini_test(
# TARGET transport
# METAINI test-transport-layered.mini.in
# )
add_custom_target(test-transport
COMMAND ctest --output-on-failure --tests-regex ^.+test-transport.+$
add_custom_target(test-transport-coupling
COMMAND ctest --output-on-failure --tests-regex ^.+test-transport-coupling.+$
)
# dorie_add_metaini_test(TARGET dorie METAINI reference_2d.mini.in)
......
......@@ -54,12 +54,8 @@ int main(int argc, char** argv) {
auto [inifile, log, helper] = Dune::Dorie::Setup::init(argc, argv);
log.reset(); // silence compiler warning
auto inifile_transport = inifile.sub("transport");
// move grid extensions into richards category (needed for reading parameters)
inifile_transport["grid.extensions"] = inifile["grid.extensions"];
// configure a global verbose level
inifile["output.verbose"] = inifile_transport["output.verbose"];
// setup transport configuration
Dune::ParameterTree inifile_transport = Dune::Dorie::Setup::prep_ini_for_transport(inifile);
// Read necessary variables
const std::string gtype = inifile.get<std::string>("grid.gridType");
......@@ -71,23 +67,13 @@ int main(int argc, char** argv) {
if (adaptivity)
DUNE_THROW(Dune::NotImplemented,"Adaptivity is not yet supported for transport simulation!");
// Attempt to create output directory
log->info("Creating output directory: {}", outputPath_transport);
mkdir(outputPath_transport.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
auto result = access(outputPath_transport.c_str(), W_OK);
result = access(outputPath_transport.c_str(), W_OK);
if (result != 0)
DUNE_THROW(Dune::IOError,"Output folder " << outputPath_transport << " not writable");
if (helper.rank()==0){
std::cout << "BC FILE TRANSPORT: " << inifile_transport.get<std::string>("boundary.file") << std::endl;
std::cout << "OUTPUT PATH TRANSPORT: " << inifile_transport.get<std::string>("output.outputPath") << std::endl;
if (verbose>0){
if(Dune::MPIHelper::isFake)
std::cout << "MPI: SEQUENTIAL RUN" << std::endl;
else
std::cout << "MPI: PARALLEL RUN ON " << helper.size() << " PROCESS(ES)" << std::endl;
}
}
if (dim==2)
{
if (gtype == "rectangular")
......
include ${CMAKE_BINARY_DIR}/doc/default_files/config.ini
__name = test-transport-silt
_test_command = run
_asset_path = "${CMAKE_CURRENT_LIST_DIR}"
_input = const, pulse | expand input
_case = diffusive, advective | expand case
_solver = explicit, implicit | expand solver
__name = test-transport-coupling-{_input}-{_case}-{_solver}
simulation.mode = richards+transport
grid.gridType = rectangular
grid.initialLevel = 0
grid.cells = 50 50
grid.mappingFile = none
grid.globalIndex = 1
[grid]
gridType = rectangular
initialLevel = 0
cells = 1 160, 1 40, 1 20 | expand prec
#### Richards parameters ####
[richards]
output.fileName = test-transport-silt | unique
output.outputPath = test-transport-silt | unique
output.vertexData = true
time.end = 2E5
time.maxTimestep = 1E5
time.startTimestep = 1E3
output.fileName = {__name}
output.outputPath = {__name}
boundary.file = "{_asset_path}/bcs/infiltration_2d.dat"
parameters.file = "{_asset_path}/param/param.yml"
#### Transport parameters ####
time.end = 2E5
time.maxTimestep = 1E5
time.startTimestep = 1E3
[transport]
output.fileName = test-transport-silt | unique
output.outputPath = test-transport-silt | unique
output.verbose = 0
output.fileName = {__name}
output.outputPath = {__name}
boundary.file = "{_asset_path}/bcs/solute_2d_const.dat", "{_asset_path}/bcs/solute_2d_pulse.dat" | expand input
boundary.file = "{_asset_path}/bcs/solute_2d_{_input}.dat"
parameters.molecularDifussion = 2E-9, 0 | expand diff
parameters.molecularDiffusion = 2E-9, 0 | expand case
time.end = 2E5
time.maxTimestep = 1E4
time.startTimestep = 1E2
numerics.timestepMethod = explicit_euler, implicit_euler | expand solver
numerics.timestepMethod = {_solver}_euler
numerics.courant = 0.5, 0.7 | expand diff
\ No newline at end of file
include ${CMAKE_BINARY_DIR}/doc/default_files/config.ini
__name = test-transport-layered
_test_command = run
_asset_path = "${CMAKE_CURRENT_LIST_DIR}"
simulation.mode = richards+transport
grid.gridType = rectangular, gmsh | expand gridtype
grid.gridFile = {_asset_path}/meshes/square-layered.msh
grid.initialLevel = 2, 1 | expand gridtype
grid.extensions = 2 2
grid.cells = 20 20
grid.mappingFile = "{_asset_path}/maps/cell_ids.h5"
grid.mappingFileDataset = grid_test_2d
#### Richards parameters ####
[richards]
output.fileName = test-transport-layered | unique
output.outputPath = test-transport-layered | unique
output.vertexData = true
time.end = 2E5
time.maxTimestep = 1E5
time.startTimestep = 1E3
boundary.file = "{_asset_path}/bcs/infiltration_2d.dat"
parameters.file = "{_asset_path}/param/param.yml"
#### Transport parameters ####
[transport]
output.fileName = test-transport-layered | unique
output.outputPath = test-transport-layered | unique
output.verbose = 0
boundary.file = "{_asset_path}/bcs/solute_2d_const.dat", "{_asset_path}/bcs/solute_2d_pulse.dat" | expand input
parameters.molecularDiffusion = 2E-9, 0 | expand diff
time.end = 2E5
time.maxTimestep = 1E4
time.startTimestep = 1E2
numerics.timestepMethod = explicit_euler, implicit_euler | expand solver
numerics.courant = 0.5, 0.7 | expand diff
\ No newline at end of file
include ${CMAKE_BINARY_DIR}/doc/default_files/config.ini
__name = test-transport-miller
_test_command = run
_asset_path = "${CMAKE_CURRENT_LIST_DIR}"
simulation.mode = richards+transport
grid.gridType = rectangular
grid.initialLevel = 0
grid.cells = 50 50
adaptivity.useAdaptivity = false
#### Richards parameters ####
[richards]
output.fileName = test-transport-miller | unique
output.outputPath = test-transport-miller | unique
output.vertexData = true
time.end = 2E5
time.maxTimestep = 1E5
time.startTimestep = 1E3
boundary.file = "{_asset_path}/bcs/infiltration_2d.dat"
parameters.arrayFile = "{_asset_path}/parfields/fft_2d_miller.h5"
#### Transport parameters ####
[transport]
output.fileName = test-transport-miller | unique
output.outputPath = test-transport-miller | unique
output.verbose = 0
boundary.file = "{_asset_path}/bcs/solute_2d_const.dat", "{_asset_path}/bcs/solute_2d_pulse.dat" | expand input
parameters.molecularDiffusion = 2E-9, 0 | expand diff
time.end = 2E5
time.maxTimestep = 1E4
time.startTimestep = 1E2
numerics.timestepMethod = explicit_euler, implicit_euler | expand solver
numerics.courant = 0.5, 0.7 | expand diff
\ No newline at end of file
include ${CMAKE_BINARY_DIR}/doc/default_files/config.ini
__name = test-transport-muphi
_test_command = run
_asset_path = "${CMAKE_CURRENT_LIST_DIR}"
simulation.mode = richards+transport
grid.dimensions = 2
grid.initialLevel = 0
grid.gridType = rectangular
grid.cells = 64 64
grid.extensions = 1 1
grid.mappingFile = "{_asset_path}/maps/muphi.h5"
grid.mappingFileDataset = field
adaptivity.useAdaptivity = false
#### Richards parameters ####
[richards]
output.fileName = test-transport-muphi | unique
output.outputPath = test-transport-muphi | unique
output.vertexData = true
time.end = 2E5
time.maxTimestep = 1E5
time.startTimestep = 1E3
boundary.file = "{_asset_path}/bcs/infiltration_2d.dat"
parameters.file = "{_asset_path}/param/param.yml"
#### Transport parameters ####
[transport]
output.fileName = test-transport-muphi | unique
output.outputPath = test-transport-muphi | unique
output.verbose = 0
boundary.file = "{_asset_path}/bcs/solute_2d_const.dat", "{_asset_path}/bcs/solute_2d_pulse.dat" | expand input
parameters.molecularDiffusion = 2E-9, 0 | expand diff
time.end = 2E5
time.maxTimestep = 1E4
time.startTimestep = 1E2
numerics.timestepMethod = explicit_euler, implicit_euler | expand solver
numerics.courant = 0.5, 0.7 | expand diff
\ No newline at end of file
include ${CMAKE_BINARY_DIR}/doc/default_files/config.ini
__name = test-transport-sand
_test_command = run
_asset_path = "${CMAKE_CURRENT_LIST_DIR}"
simulation.mode = richards+transport
grid.gridType = rectangular
grid.initialLevel = 0
grid.cells = 50 50
grid.mappingFile = none
grid.globalIndex = 0
#### Richards parameters ####
[richards]
output.fileName = test-transport-sand | unique
output.outputPath = test-transport-sand | unique
output.vertexData = true
time.end = 2E5
time.maxTimestep = 1E5
time.startTimestep = 1E3
boundary.file = "{_asset_path}/bcs/infiltration_2d.dat"
parameters.file = "{_asset_path}/param/param.yml"
#### Transport parameters ####
[transport]
output.fileName = test-transport-sand | unique
output.outputPath = test-transport-sand | unique
output.verbose = 0
boundary.file = "{_asset_path}/bcs/solute_2d_const.dat", "{_asset_path}/bcs/solute_2d_pulse.dat" | expand input
parameters.molecularDiffusion = 2E-9, 0 | expand diff
time.end = 2E5
time.maxTimestep = 1E4
time.startTimestep = 1E2
numerics.timestepMethod = explicit_euler, implicit_euler | expand solver
numerics.courant = 0.5, 0.7 | expand diff
\ No newline at end of file
Supports Markdown
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