-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.cpp
173 lines (125 loc) · 5.41 KB
/
Model.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/*
* File: Model.cpp
* Created by: Rao, Jayghosh Subodh
* Created on: Sat 06 Apr 2019 01:03:26 PM CEST
*
* This class is modeled after and copied from
* BeadsInside from the old mesher.
*
*/
#include "Model.h"
#include "Files.h"
#include <float.h>
#include <gmsh.h>
#include <iostream>
#include <fstream>
#include <iterator>
#include <algorithm>
// uncomment to disable assert()
// #define NDEBUG
#include <cassert>
#define PI 3.1415926535897932
namespace model = gmsh::model;
namespace factory = gmsh::model::occ;
Model::Model(Parameters * prm, Geometry * geom)
{
column = Column(geom->dt_fragmented, prm, prm->periodic);
// remove z from periodic string
// So that inlet/outlet sections don't have internal z periodicity.
std::string periodicInOut = prm->periodic;
periodicInOut.erase(std::remove(periodicInOut.begin(), periodicInOut.end(), 'z'), periodicInOut.end());
if(prm->periodicInlet > 0)
{
columnInlet = Column(geom->dt_fragmentedPeriodicInlet, prm, periodicInOut);
std::cout << "Linking inlet and column... " << std::endl;
columnInlet.linkPeriodicZ(column);
}
if(prm->periodicOutlet > 0)
{
columnOutlet = Column(geom->dt_fragmentedPeriodicOutlet, prm, periodicInOut);
std::cout << "Linking column and outlet... " << std::endl;
column.linkPeriodicZ(columnOutlet);
}
// TODO: re-implement
/* if geometry is imported instead: */
/* std::cout << "Importing geometry: " << prm->geomInfile << "... " << std::flush; */
/* factory::importShapes("geometries/" + prm->geomInfile, dt_fragmented); */
/* std::cout << "done!" << std::endl; */
/* // Synchronize gmsh model with geometry kernel. */
/* std::cout << "Synchronizing... " << std::flush; */
/* factory::synchronize(); */
/* std::cout << "done!" << std::endl; */
/* createNamedGroups(dt_fragmented, prm->containerShape); */
//if write geometry
if(!prm->geomOutfile.empty())
gmsh::write(prm->outpath + "/"+ prm->geomOutfile );
// Synchronize gmsh model with geometry kernel.
std::cout << "Synchronizing... " << std::flush;
factory::synchronize();
std::cout << "done!" << std::endl;
}
Model::~Model()
{
}
void Model::mesh(std::string outfile, Parameters * prm)
{
std::vector<std::pair<int,int>> dummy;
model::getEntities(dummy, 3);
std::cout << "Number of 3D objects: " << dummy.size() << std::endl;
model::getEntities(dummy, 2);
std::cout << "Number of 2D objects: " << dummy.size() << std::endl;
model::getEntities(dummy, 1);
std::cout << "Number of 1D objects: " << dummy.size() << std::endl;
model::getEntities(dummy, 0);
std::cout << "Number of 0D objects: " << dummy.size() << std::endl;
if(prm->dryRun)
return;
std:: string basefilename = remove_extension(outfile);
std:: string extension = get_extension(outfile);
long time_0 = gmsh::logger::getWallTime();
for(int i=1; i<prm->MeshGenerate; i++)
{
std::cout << "Meshing " << i << "D objects..." << std::endl;
long start = gmsh::logger::getWallTime();
model::mesh::generate(i);
long duration = gmsh::logger::getWallTime() - start;
gmsh::logger::write("Wall time for " + std::to_string(i) + "D mesh: " + std::to_string(duration) + " s (" + std::to_string((double)duration/3600) + " h)", "info");
gmsh::logger::write("CPU time for " + std::to_string(i) + "D mesh: " + std::to_string(gmsh::logger::getCpuTime()) + " s", "info");
gmsh::write(prm->outpath + "/"+ basefilename + "_" + std::to_string(i) + "D" + extension );
}
long start = gmsh::logger::getWallTime();
std::cout << "Meshing " << prm->MeshGenerate << "D objects..." << std::endl;
model::mesh::generate(prm->MeshGenerate);
long duration = gmsh::logger::getWallTime() - start;
long durationAll = gmsh::logger::getWallTime() - time_0;
gmsh::logger::write("Wall time: " + std::to_string(duration) + " s (" + std::to_string((double)duration/3600) + " h)", "info");
gmsh::logger::write("CPU time: " + std::to_string(gmsh::logger::getCpuTime()) + " s", "info");
std::cout << "Total meshing wall time: " << durationAll << "s (" << durationAll/3600 << " h)" << std::endl;
}
void Model::write(std::string outfile, Parameters * prm)
{
if(prm->dryRun)
return;
std:: string basefilename = remove_extension(outfile);
std:: string extension = get_extension(outfile);
// Output Full mesh
gmsh::write(prm->outpath + "/" + basefilename + "_FULL" + extension);
std::cout << "Writing main column unit..." << std::endl;
column.write(prm->outpath, basefilename + "_column", extension );
column.meshVolumes(prm);
column.writeFragments(prm->outpath, basefilename + "_column", extension );
if(prm->periodicInlet > 0)
{
std::cout << "Writing periodic inlet unit..." << std::endl;
columnInlet.write(prm->outpath, basefilename + "_inlet", extension );
columnInlet.meshVolumes(prm);
columnInlet.writeFragments(prm->outpath, basefilename + "_inlet", extension );
}
if(prm->periodicOutlet > 0)
{
std::cout << "Writing periodic outlet unit..." << std::endl;
columnOutlet.write(prm->outpath, basefilename + "_outlet", extension );
columnInlet.meshVolumes(prm);
columnOutlet.writeFragments(prm->outpath, basefilename + "_outlet", extension );
}
}