VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
WbWriterSunflow.cpp
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
36#include <cstring>
37
38using namespace std;
39
40/*===============================================================================*/
41std::string WbWriterSunflow::writeTriangles(const string &filename, vector<UbTupleFloat3> &nodes,
42 vector<UbTupleInt3> &triangles)
43{
44 string sunflowFilename = filename + getFileExtension();
45 UBLOG(logDEBUG1, "WbWriterSunflow::writeTriangles to " << sunflowFilename << " - start");
46
47 std::ofstream out(sunflowFilename.c_str());
48 if (!out) {
49 out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!!
51 if (path.size() > 0) {
53 out.open(sunflowFilename.c_str());
54 }
55 if (!out)
56 throw UbException(UB_EXARGS, "couldn't open file " + sunflowFilename);
57 }
58
59 // General part
60
61 // Image details
62 out << "image {" << endl;
63 out << " resolution 640 480" << endl;
64 out << " aa 0 1" << endl;
65 out << " filter mitchell" << endl;
66 out << "}" << endl << endl;
67
68 // Camera position
69 out << "camera {" << endl;
70 out << " type pinhole" << endl;
71 out << " eye -0.25 -0.3 0.13" << endl;
72 out << " target -0.1 0.1 0.13" << endl;
73 out << " up 0 0 1" << endl;
74 out << " fov 60" << endl;
75 out << " aspect 1.333333" << endl;
76 out << "}" << endl << endl;
77
78 // Light
79 out << "light {" << endl;
80 out << " type ibl" << endl;
81 out << " image sky_small.hdr" << endl;
82 out << " center 0 -1 0" << endl;
83 out << " up 0 0 1" << endl;
84 out << " lock true" << endl;
85 out << " samples 200" << endl;
86 out << "}" << endl << endl;
87
88 // Shaders
89 out << "shader {" << endl;
90 out << " name default-shader" << endl;
91 out << " type diffuse" << endl;
92 out << " diff 0.25 0.25 0.25" << endl;
93 out << "}" << endl << endl;
94
95 out << "shader {" << endl;
96 out << " name Glass" << endl;
97 out << " type glass" << endl;
98 out << " eta 1.333" << endl;
99 out << " color 0.1 0.3 0.8" << endl;
100 out << "}" << endl << endl;
101
102 out << "shader {" << endl;
103 out << " name Mirror" << endl;
104 out << " type mirror" << endl;
105 out << " refl 0.7 0.7 0.7" << endl;
106 out << "}" << endl << endl;
107
108 // Objects
109 // a) Ground plane
110 out << "object {" << endl;
111 out << " shader default-shader" << endl;
112 out << " type plane" << endl;
113 out << " p 0 0 0" << endl;
114 out << " n 0 0 1" << endl;
115 out << "}" << endl << endl;
116
117 // b) Mesh
118 out << "object {" << endl;
119 out << " shader Glass" << endl;
120 out << " transform {" << endl;
121 out << " rotatey 270.0" << endl;
122 out << " }" << endl;
123 out << " type generic-mesh" << endl;
124 out << " name polySurfac" << endl << endl;
125
126 // POINTS SECTION
127 int nofNodes = (int)nodes.size();
128 out << " points " << nofNodes << endl;
129 for (int n = 0; n < nofNodes; n++)
130 out << " " << val<1>(nodes[n]) << " " << val<2>(nodes[n]) << " " << val<3>(nodes[n]) << endl;
131
132 // TRIANGLES SECTION
133 int nofTriangles = (int)triangles.size();
134 out << " triangles " << nofTriangles << endl;
135 for (int c = 0; c < nofTriangles; c++)
136 out << " " << val<1>(triangles[c]) << " " << val<2>(triangles[c]) << " " << val<3>(triangles[c]) << endl;
137
138 // FOOTER
139 out << " normals none" << endl;
140 out << " uvs none" << endl;
141 out << "}" << endl;
142
143 out.close();
144 UBLOG(logDEBUG1, "WbWriterSunflow::writeTriangles to " << sunflowFilename << " - end");
145
146 return sunflowFilename;
147}
148/*===============================================================================*/
149
std::string getFileExtension() override
std::shared_ptr< T > SPtr
#define UBLOG(level, logtext)
Definition UbLogger.h:327
#define UB_EXARGS
Definition UbException.h:73
@ logDEBUG1
Definition UbLogger.h:54
std::string writeTriangles(const std::string &filename, std::vector< UbTupleFloat3 > &nodes, std::vector< UbTupleInt3 > &triangles) override
bool makeDirectory(const std::string &dir)
Definition UbSystem.h:280
std::string getPathFromString(const std::string &fileStringWithPath)
Definition UbSystem.h:345