ViennaLS
Loading...
Searching...
No Matches
lsReader.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 Reader {
13 SmartPointer<Domain<T, D>> levelSet = nullptr;
14 std::string fileName;
15
16public:
17 Reader() {}
18
19 Reader(SmartPointer<Domain<T, D>> passedLevelSet)
20 : levelSet(passedLevelSet) {}
21
22 Reader(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 Reader. Not writing.")
37 .print();
38 return;
39 }
40 // check filename
41 if (fileName.empty()) {
42 Logger::getInstance()
43 .addWarning("No file name specified for Reader. Not writing.")
44 .print();
45 return;
46 }
47 if (fileName.find(".lvst") != fileName.length() - 5) {
48 Logger::getInstance()
49 .addWarning("File name does not end in '.lvst', appending it.")
50 .print();
51 fileName.append(".lvst");
52 }
53
54 // Open file for writing and save serialized level set in it
55 std::ifstream fin(fileName, std::ios::binary);
56
57 levelSet->deserialize(fin);
58
59 fin.close();
60 }
61};
62
63// add all template specialisations for this class
65
66} // namespace viennals
Class containing all information about the level set, including the dimensions of the domain,...
Definition lsDomain.hpp:28
Definition lsReader.hpp:12
Reader(SmartPointer< Domain< T, D > > passedLevelSet, std::string passedFileName)
Definition lsReader.hpp:22
void setLevelSet(SmartPointer< Domain< T, D > > passedLevelSet)
Definition lsReader.hpp:25
Reader(SmartPointer< Domain< T, D > > passedLevelSet)
Definition lsReader.hpp:19
Reader()
Definition lsReader.hpp:17
void apply()
Definition lsReader.hpp:32
void setFileName(std::string passedFileName)
set file name for file to write
Definition lsReader.hpp:30
#define PRECOMPILE_PRECISION_DIMENSION(className)
Definition lsPreCompileMacros.hpp:24
Definition lsAdvect.hpp:46