ViennaLS
Loading...
Searching...
No Matches
lsWriter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <fstream>
4
5#include <lsDomain.hpp>
7
8namespace viennals {
9
10using namespace viennacore;
11
12template <class T, int D> class Writer {
13 SmartPointer<Domain<T, D>> levelSet = nullptr;
14 std::string fileName;
15
16public:
17 Writer() {}
18
19 Writer(SmartPointer<Domain<T, D>> passedLevelSet)
20 : levelSet(passedLevelSet) {}
21
22 Writer(SmartPointer<Domain<T, D>> passedLevelSet, std::string passedFileName)
23 : levelSet(passedLevelSet), fileName(passedFileName) {}
24
25 void setLevelSet(SmartPointer<Domain<T, D>> passedLevelSet) {
26 levelSet = passedLevelSet;
27 }
28
30 void setFileName(std::string passedFileName) { fileName = passedFileName; }
31
32 void apply() {
33 // check mesh
34 if (levelSet == nullptr) {
35 Logger::getInstance()
36 .addWarning("No mesh was passed to Writer. Not writing.")
37 .print();
38 return;
39 }
40 // check filename
41 if (fileName.empty()) {
42 Logger::getInstance()
43 .addWarning("No file name specified for Writer. Not writing.")
44 .print();
45 return;
46 }
47
48 if (fileName.find(".lvst") != fileName.length() - 5) {
49 Logger::getInstance()
50 .addWarning("File name does not end in '.lvst', appending it.")
51 .print();
52 fileName.append(".lvst");
53 }
54
55 // Open file for writing and save serialized level set in it
56 std::ofstream fout(fileName, std::ios::binary);
57
58 levelSet->serialize(fout);
59
60 fout.close();
61 }
62};
63
64// add all template specialisations for this class
66
67} // namespace viennals
Class containing all information about the level set, including the dimensions of the domain,...
Definition lsDomain.hpp:28
Definition lsWriter.hpp:12
Writer(SmartPointer< Domain< T, D > > passedLevelSet, std::string passedFileName)
Definition lsWriter.hpp:22
Writer(SmartPointer< Domain< T, D > > passedLevelSet)
Definition lsWriter.hpp:19
void setFileName(std::string passedFileName)
set file name for file to write
Definition lsWriter.hpp:30
void setLevelSet(SmartPointer< Domain< T, D > > passedLevelSet)
Definition lsWriter.hpp:25
void apply()
Definition lsWriter.hpp:32
Writer()
Definition lsWriter.hpp:17
#define PRECOMPILE_PRECISION_DIMENSION(className)
Definition lsPreCompileMacros.hpp:24
Definition lsAdvect.hpp:46