AMDiS 2.10
The Adaptive Multi-Dimensional Simulation Toolbox
GmshWriter.hpp
1#pragma once
2
3#include <string>
4#include <limits>
5#include <memory>
6#include <utility>
7
8#include <dune/grid/io/file/gmshwriter.hh>
9
10#include <amdis/Initfile.hpp>
11#include <amdis/Output.hpp>
12#include <amdis/common/Filesystem.hpp>
13#include <amdis/io/FileWriterBase.hpp>
14
15namespace AMDiS
16{
18
21 template <class GV>
23 : public FileWriterBase
24 {
25 using GridView = GV;
26 using Writer = Dune::GmshWriter<GridView>;
27
28 public:
30 GmshWriter(std::string const& name, GridView const& gridView,
31 std::vector<int> const& physicalEntities = std::vector<int>(),
32 std::vector<int> const& physicalBoundaries = std::vector<int>())
33 : FileWriterBase(name)
34 , physicalEntities_(physicalEntities)
35 , physicalBoundaries_(physicalBoundaries)
36 {
37 int p = 0;
38 Parameters::get(name + "->animation", animation_);
39 Parameters::get(name + "->precision", p);
40
41 int precision = (p == 0)
42 ? std::numeric_limits<float>::max_digits10
43 : std::numeric_limits<double>::max_digits10;
44
45 writer_ = std::make_shared<Writer>(gridView, precision);
46 }
47
49 void write(AdaptInfo& adaptInfo, bool force) override
50 {
51 std::string filename = this->filename();
52 if (animation_)
53 filename += "_" + std::to_string(adaptInfo.time());
54
55 if (this->doWrite(adaptInfo) || force) {
56 writer_->write(filesystem::path({this->dir(), filename + ".msh"}).string(),
57 physicalEntities_, physicalBoundaries_);
58
59 msg("Grid written to file '{}'.", filesystem::path({this->dir(), filename + ".msh"}).string());
60 }
61 }
62
63 private:
64 std::vector<int> const& physicalEntities_;
65 std::vector<int> const& physicalBoundaries_;
66
67 std::shared_ptr<Writer> writer_;
68
70 bool animation_ = false;
71 };
72
73} // end namespace AMDiS
Holds adapt parameters and infos about the problem.
Definition: AdaptInfo.hpp:26
double const & time() const
Gets time_.
Definition: AdaptInfo.hpp:464
Base class for filewriters.
Definition: FileWriterBase.hpp:39
bool doWrite(AdaptInfo &adaptInfo) const
Return whether to write the current timestep or not.
Definition: FileWriterBase.cpp:24
The GmshWriter just writes the grid of a given gridView to a gmsh compatible .msh file.
Definition: GmshWriter.hpp:24
GmshWriter(std::string const &name, GridView const &gridView, std::vector< int > const &physicalEntities=std::vector< int >(), std::vector< int > const &physicalBoundaries=std::vector< int >())
Constructor.
Definition: GmshWriter.hpp:30
void write(AdaptInfo &adaptInfo, bool force) override
Implements FileWriterBase::write.
Definition: GmshWriter.hpp:49
static std::optional< T > get(std::string const &key)
Get parameter-values from parameter-tree.
Definition: Initfile.hpp:25
Definition: Filesystem.hpp:13