ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
h5md.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#ifndef ESPRESSO_SRC_SCRIPT_INTERFACE_H5MD_H5MD_HPP
23#define ESPRESSO_SRC_SCRIPT_INTERFACE_H5MD_H5MD_HPP
24
25#include "config/config.hpp"
26
27#ifdef H5MD
28
29#include "core/MpiCallbacks.hpp"
32
35
36#include <memory>
37#include <string>
38#include <vector>
39
40namespace ScriptInterface {
41namespace Writer {
42class H5md : public AutoParameters<H5md> {
43public:
44 H5md() {
46 {{"file_path", m_h5md, &::Writer::H5md::File::file_path},
47 {"script_path", m_h5md, &::Writer::H5md::File::script_path},
48 {"fields", AutoParameter::read_only,
49 [this]() { return make_vector_of_variants(m_output_fields); }},
50 {"mass_unit", m_h5md, &::Writer::H5md::File::mass_unit},
51 {"length_unit", m_h5md, &::Writer::H5md::File::length_unit},
52 {"time_unit", m_h5md, &::Writer::H5md::File::time_unit},
53 {"force_unit", m_h5md, &::Writer::H5md::File::force_unit},
54 {"velocity_unit", m_h5md, &::Writer::H5md::File::velocity_unit},
55 {"charge_unit", m_h5md, &::Writer::H5md::File::charge_unit}});
56 };
57
58private:
59 Variant do_call_method(const std::string &name,
60 const VariantMap &parameters) override;
61
62 void do_construct(VariantMap const &params) override {
63 m_output_fields = get_value<std::vector<std::string>>(params, "fields");
64 m_h5md = make_shared_from_args<::Writer::H5md::File, std::string,
65 std::string, std::vector<std::string>,
66 std::string, std::string, std::string,
67 std::string, std::string, std::string>(
68 params, "file_path", "script_path", "fields", "mass_unit",
69 "length_unit", "time_unit", "force_unit", "velocity_unit",
70 "charge_unit");
71 // MPI communicator is needed to close parallel file handles
72 m_mpi_env_lock = ::Communication::mpiCallbacksHandle()->share_mpi_env();
73 }
74
75 ~H5md() override {
76 m_h5md.reset();
77 m_mpi_env_lock.reset();
78 }
79
80 std::shared_ptr<boost::mpi::environment> m_mpi_env_lock;
81 std::shared_ptr<::Writer::H5md::File> m_h5md;
82 std::vector<std::string> m_output_fields;
83};
84
85} // namespace Writer
86} // namespace ScriptInterface
87
88#endif // H5MD
89#endif
Communication::MpiCallbacks manages MPI communication using a visitor pattern.
Bind parameters in the script interface.
void add_parameters(std::vector< AutoParameter > &&params)
boost::string_ref name() const
void do_construct(VariantMap const &params) override
Definition h5md.hpp:62
Variant do_call_method(const std::string &name, const VariantMap &parameters) override
Definition h5md.cpp:37
Class for writing H5MD files.
auto const & length_unit() const
Retrieve the set length unit.
auto const & time_unit() const
Retrieve the set time unit.
auto file_path() const
Retrieve the path to the hdf5 file.
auto const & force_unit() const
Retrieve the set force unit.
auto const & mass_unit() const
Retrieve the set mass unit.
auto const & charge_unit() const
Retrieve the set charge unit.
auto const & velocity_unit() const
Retrieve the set velocity unit.
auto const & script_path() const
Retrieve the path to the simulation script.
This file contains the defaults for ESPResSo.
This file contains the asynchronous MPI communication.
std::shared_ptr< MpiCallbacks > mpiCallbacksHandle()
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:82
auto make_vector_of_variants(std::vector< T > const &v)
Definition Variant.hpp:101
std::shared_ptr< T > make_shared_from_args(VariantMap const &vals, ArgNames &&...args)
Make a new std::shared_ptr<T> with arguments extracted from a VariantMap.
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:80
static SteepestDescentParameters params
Currently active steepest descent instance.
static constexpr const ReadOnly read_only