Page MenuHomec4science

app_core.hpp
No OneTemporary

File Metadata

Created
Wed, Oct 9, 00:28

app_core.hpp

/* =============================================================================
Copyright (c) 2014-2017 F. Georget <fabieng@princeton.edu> Princeton University
Copyright (c) 2017-2018 F. Georget <fabien.georget@epfl.ch> EPFL
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
============================================================================= */
#ifndef SPECMICP_BINREACTMICP_APPCORE_HPP
#define SPECMICP_BINREACTMICP_APPCORE_HPP
#include "specmicp_common/types.hpp"
#include <vector>
#include <memory>
#include "reactmicp/solver/staggers_base/variables_base.hpp"
#include "reactmicp/solver/staggers_base/staggers_base.hpp"
#include "reactmicp/solver/runner.hpp"
#include "specmicp_common/io/safe_config.hpp"
#include "specmicp_common/io/all_io_files.hpp"
#include "specmicp_database/database_fwd.hpp"
#include "dfpm/meshes/mesh1dfwd.hpp"
using namespace specmicp;
using namespace specmicp::reactmicp;
namespace specmicp {
namespace units {
struct UnitsSet;
} // namespace units
} // namespace specmicp
//! \brief Store the different staggers
struct Staggers
{
std::shared_ptr<solver::UpscalingStaggerBase> upscaling; //!< Upscaling stagger
std::shared_ptr<solver::ChemistryStaggerBase> chemistry; //!< Chemistry stagger
std::shared_ptr<solver::TransportStaggerBase> transport; //!< Transport stagger
};
//! \brief Options for the command line interface
struct CliOptions
{
bool done {false}; //!< Set to true if programs need to be ended after parsing
bool allow_overwrite; //!< Allow previous simulation overwrite
bool clean_outputs; //!< Clean outputs of previous simulation
bool only_pretend; //!< Just check that config file can be read
std::string input_filepath; //!< The input file path
std::string database_dir; //!< Directory where to find the database
std::string working_dir; //!< Directory where outputs are written
//! \brief Parse the options and return
CliOptions static parse_cli(int argc, char *argv[]);
//! \brief Return the directories where the database is searched
std::vector<std::string> get_db_dirs() const;
};
// base class
class SystemApp;
//! \brief The main application
class MainApp
{
public:
MainApp();
~MainApp();
//! \brief The main loop
int run(SystemApp& system_app, int argc, char* argv[]);
};
//! \brief Base class for a simulation
class SystemApp
{
public:
SystemApp() {}
//! \brief Open and check the input file
void init_input_file(const std::string& input_filepath);
//! \brief Print program banner
virtual void print_welcome() = 0;
//! \brief Return the drived identification
virtual std::string driver_identification() = 0;
//! \brief Initialize the basic information about simulations
void init_simul_info(const std::string& working_dir);
//! \brief Initialize the file to record inputs/outputs
void init_alliofiles(const CliOptions& cli_opts);
//! \brief Initialize the configuration logger
void init_conf_logger();
//! \brief Initialize the main logger
void init_logger();
//! \brief Initialize the plugin manager
virtual void init_plugin_manager() = 0;
void init_plugin_manager_base(std::vector<std::string> plugin_modules);
//! \brief Initialize the simulations data
virtual void init_simul_data(const std::vector<std::string>& db_dirs) = 0;
//! \brief Initialize the 3 staggers
virtual void init_staggers() = 0;
//! \brief Check the consistency of the simulations data
virtual void check_init_data() = 0;
//! \brief Initialize the ReactMiCP solver
void init_solver();
//! \brief Initialize the timestep runner
void init_runner();
//! \brief Initialize the outputs
virtual void init_output(const std::string& working_dir) =0;
//! \brief Return the variables
virtual solver::VariablesBasePtr get_variables() = 0;
//! \brief Run the simulation
void run();
//! \brief Clean the output files of a previous simulation
void clean_output_files();
io::YAMLConfigHandle& get_config() {return *m_config;}
// common
units::UnitsSet get_units_from_config();
database::RawDatabasePtr get_database_from_config(
const std::vector<std::string> &db_dirs);
mesh::Mesh1DPtr get_mesh_from_config();
protected:
std::unique_ptr<io::YAMLConfigHandle> m_config; //!< The configuration
Staggers m_staggers; //!< The staggers
std::unique_ptr<solver::ReactiveTransportSolver> m_solver; //!< ReactMiCP solver
std::unique_ptr<solver::ReactiveTransportRunner> m_runner; //!< ReactMiCP runner
std::unique_ptr<solver::SimulationInformation> m_simul_info; //!< Simple info about the simulation
std::unique_ptr<io::AllIOFiles> m_all_io_files; //!< Records inputs/outputs
std::unique_ptr<std::ostream> m_out_conf_logger; //!< Output stream for conf logger
std::unique_ptr<std::ostream> m_out_logger; //!< Output stream for logger
};
//! \brief Return plugin name from conf
//!
//! Load extra plugin file if provided
std::string get_plugin_name(io::YAMLConfigHandle& conf);
#endif // SPECMICP_BINREACTMICP_APPCORE_HPP

Event Timeline