24 #include "mimmo_parallel.hpp"
25 #include "mimmo_iogeneric.hpp"
30 typedef std::chrono::high_resolution_clock Clock;
53 std::array<double,3> center({{0.0,0.0,0.0}});
54 double radiusin(2.0), radiusout(5.0);
55 double azimuthin(0.0), azimuthout(0.5*BITPIT_PI);
56 double heightbottom(-1.0), heighttop(1.0);
57 int nr(20), nt(20), nh(20);
59 double deltar = (radiusout - radiusin)/
double(nr);
60 double deltat = (azimuthout - azimuthin)/
double(nt);
61 double deltah = (heighttop - heightbottom)/
double(nh);
63 std::vector<std::array<double,3> > verts ((nr+1)*(nt+1)*(nh+1));
66 for(
int k=0; k<=nh; ++k){
67 for(
int j=0; j<=nt; ++j){
68 for(
int i=0; i<=nr; ++i){
69 verts[counter][0] =(radiusin + i*deltar)*std::cos(azimuthin + j*deltat);
70 verts[counter][1] =(radiusin + i*deltar)*std::sin(azimuthin + j*deltat);
71 verts[counter][2] =(heightbottom + k*deltah);
82 mesh->getPatch()->reserveVertices((nr+1)*(nt+1)*(nh+1));
83 mesh->getPatch()->reserveCells(nr*nt*nh);
86 for(
const auto & vertex : verts){
87 mesh->addVertex(vertex);
91 std::vector<long> conn(8,0);
92 for(
int k=0; k<nh; ++k){
93 for(
int j=0; j<nt; ++j){
94 for(
int i=0; i<nr; ++i){
95 conn[0] = (nr+1)*(nt+1)*k + (nr+1)*j + i;
96 conn[1] = (nr+1)*(nt+1)*k + (nr+1)*j + i+1;
97 conn[2] = (nr+1)*(nt+1)*k + (nr+1)*(j+1) + i+1;
98 conn[3] = (nr+1)*(nt+1)*k + (nr+1)*(j+1) + i;
99 conn[4] = (nr+1)*(nt+1)*(k+1) + (nr+1)*j + i;
100 conn[5] = (nr+1)*(nt+1)*(k+1) + (nr+1)*j + i+1;
101 conn[6] = (nr+1)*(nt+1)*(k+1) + (nr+1)*(j+1) + i+1;
102 conn[7] = (nr+1)*(nt+1)*(k+1) + (nr+1)*(j+1) + i;
104 mesh->addConnectedCell(conn, bitpit::ElementType::HEXAHEDRON);
109 bcdir1_vertlist.clear();
110 bcdir2_vertlist.clear();
111 bcdir1_vertlist.reserve(mesh->getNVertices());
112 bcdir2_vertlist.reserve(mesh->getNVertices());
114 for(
int k=0; k<=nh; ++k){
115 for(
int i=0; i<=nr; ++i){
116 bcdir1_vertlist.push_back((nr+1)*(nt+1)*k + i);
117 bcdir2_vertlist.push_back((nr+1)*(nt+1)*k + (nr+1)*nt + i);
122 mesh->updateInterfaces();
137 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
138 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
141 std::vector<long> bc1list, bc2list;
146 livector1D pidlist1 = boundary->getCellFromVertexList(bc1list,
true);
147 livector1D pidlist2 = boundary->getCellFromVertexList(bc2list,
true);
149 for(
long cellid : pidlist1){
150 boundary->setPIDCell(cellid,
long(1));
152 for(
long cellid : pidlist2){
153 boundary->setPIDCell(cellid,
long(2));
161 std::unordered_set<long> potvertices(bc1list.begin(), bc1list.end());
162 potvertices.insert(bc2list.begin(), bc2list.end());
163 for(
long idv: potvertices){
164 bDirMesh->addVertex(boundary->getVertexCoords(idv), idv);
168 std::unordered_set<long> preservedcells (pidlist1.begin(), pidlist1.end());
169 preservedcells.insert(pidlist2.begin(), pidlist2.end());
171 for(
long idc: preservedcells){
172 bDirMesh->addCell(boundary->getPatch()->getCell(idc), idc, rank);
175 bDirMesh->updateInterfaces();
181 mimmo::Partition* partition =
new mimmo::Partition();
182 partition->setPlotInExecution(
true);
183 partition->setGeometry(mesh);
184 partition->setBoundaryGeometry(bDirMesh);
185 partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
186 auto t1 = Clock::now();
188 std::cout <<
"#" << rank <<
" Start Partition mesh " << std::endl;
190 auto t2 = Clock::now();
192 std::cout <<
"#" << rank <<
" Partition mesh execution time: "
193 << std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count()
194 <<
" seconds" << std::endl;
203 mimmoVolumeOut->
setWriteFilename(
"parallel_example_00003.volume.partitioned");
205 mimmoVolumeOut->
exec();
213 mimmoVolumeIn->
setReadFilename(
"parallel_example_00003.volume.partitioned");
217 mimmoVolumeIn->
exec();
222 mimmo::Partition* serialize =
new mimmo::Partition();
223 serialize->setName(
"mimmo.Serialization");
224 serialize->setPlotInExecution(
true);
225 serialize->setGeometry(mesh);
226 serialize->setBoundaryGeometry(bDirMesh);
227 serialize->setPartitionMethod(mimmo::PartitionMethod::SERIALIZE);
231 std::cout <<
"Start Serialize mesh " << std::endl;
235 std::cout <<
"Serialize mesh execution time: "
236 << std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count()
237 <<
" seconds" << std::endl;
249 int main(
int argc,
char *argv[] ) {
255 MPI_Init(&argc, &argv);
263 catch(std::exception & e){
264 std::cout<<
"parallel_example_00003 exited with an error of type : "<<e.what()<<std::endl;