ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
LatticeModel.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020-2023 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
22
23#include <blockforest/StructuredBlockForest.h>
24#include <field/vtk/VTKWriter.h>
25#include <vtk/VTKOutput.h>
26
27#include <memory>
28#include <sstream>
29#include <string>
30
31std::shared_ptr<VTKHandle> LatticeModel::create_vtk(
32 int delta_N, int initial_count, int flag_observables,
33 units_map const &units_conversion, std::string const &identifier,
34 std::string const &base_folder, std::string const &prefix) {
35
36 using walberla::uint_c;
37
38 // VTKOutput object must be unique
39 std::stringstream unique_identifier;
40 unique_identifier << base_folder << "/" << identifier;
41 std::string const vtk_uid = unique_identifier.str();
42 if (m_vtk_auto.find(vtk_uid) != m_vtk_auto.end() or
43 m_vtk_manual.find(vtk_uid) != m_vtk_manual.end()) {
44 throw vtk_runtime_error(vtk_uid, "already exists");
45 }
46
47 // instantiate VTKOutput object
48 auto const &blocks = get_lattice().get_blocks();
49 auto const write_freq = (delta_N) ? static_cast<unsigned int>(delta_N) : 1u;
50 auto vtk_obj = walberla::vtk::createVTKOutput_BlockData(
51 blocks, identifier, uint_c(write_freq), uint_c(0), false, base_folder,
52 prefix, true, true, true, true, uint_c(initial_count));
53
54 // add filters
56
57 // add writers
58 register_vtk_field_writers(*vtk_obj, units_conversion, flag_observables);
59
60 auto vtk_handle = std::make_shared<VTKHandle>(vtk_obj, initial_count, true);
61 if (delta_N) {
62 m_vtk_auto[vtk_uid] = vtk_handle;
63 } else {
64 m_vtk_manual[vtk_uid] = vtk_handle;
65 }
66 return vtk_handle;
67}
68
69void LatticeModel::write_vtk(std::string const &vtk_uid) {
70 if (m_vtk_auto.find(vtk_uid) != m_vtk_auto.end()) {
71 throw vtk_runtime_error(vtk_uid, "is an automatic observable");
72 }
73 if (m_vtk_manual.find(vtk_uid) == m_vtk_manual.end()) {
74 throw vtk_runtime_error(vtk_uid, "doesn't exist");
75 }
76 auto &vtk_handle = m_vtk_manual[vtk_uid];
77 walberla::vtk::writeFiles(vtk_handle->ptr)();
78 vtk_handle->execution_count++;
79}
80
81void LatticeModel::switch_vtk(std::string const &vtk_uid, bool status) {
82 if (m_vtk_manual.find(vtk_uid) != m_vtk_manual.end()) {
83 throw vtk_runtime_error(vtk_uid, "is a manual observable");
84 }
85 if (m_vtk_auto.find(vtk_uid) == m_vtk_auto.end()) {
86 throw vtk_runtime_error(vtk_uid, "doesn't exist");
87 }
88 m_vtk_auto[vtk_uid]->enabled = status;
89}
std::map< std::string, std::shared_ptr< VTKHandle > > m_vtk_auto
VTK writers that are executed automatically.
std::shared_ptr< VTKHandle > create_vtk(int delta_N, int initial_count, int flag_observables, units_map const &units_conversion, std::string const &identifier, std::string const &base_folder, std::string const &prefix)
Create a VTK observable.
virtual void register_vtk_field_writers(walberla::vtk::VTKOutput &vtk_obj, units_map const &units_conversion, int flag_observables)=0
Register VTK writers.
virtual void register_vtk_field_filters(walberla::vtk::VTKOutput &vtk_obj)=0
std::map< std::string, std::shared_ptr< VTKHandle > > m_vtk_manual
VTK writers that are executed manually.
std::unordered_map< std::string, double > units_map
void switch_vtk(std::string const &vtk_uid, bool status)
Toggle a VTK observable on/off.
void write_vtk(std::string const &vtk_uid)
Write a VTK observable to disk.
virtual LatticeWalberla const & get_lattice() const noexcept=0
Get the underlying lattice.