25 #include "mimmo_parallel.hpp"
27 #include "mimmo_propagators.hpp"
31 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);
81 mesh->getPatch()->reserveVertices((nr+1)*(nt+1)*(nh+1));
82 mesh->getPatch()->reserveCells(nr*nt*nh);
85 for(
const auto & vertex : verts){
86 mesh->addVertex(vertex);
90 std::vector<long> conn(8,0);
91 for(
int k=0; k<nh; ++k){
92 for(
int j=0; j<nt; ++j){
93 for(
int i=0; i<nr; ++i){
94 conn[0] = (nr+1)*(nt+1)*k + (nr+1)*j + i;
95 conn[1] = (nr+1)*(nt+1)*k + (nr+1)*j + i+1;
96 conn[2] = (nr+1)*(nt+1)*k + (nr+1)*(j+1) + i+1;
97 conn[3] = (nr+1)*(nt+1)*k + (nr+1)*(j+1) + i;
98 conn[4] = (nr+1)*(nt+1)*(k+1) + (nr+1)*j + i;
99 conn[5] = (nr+1)*(nt+1)*(k+1) + (nr+1)*j + i+1;
100 conn[6] = (nr+1)*(nt+1)*(k+1) + (nr+1)*(j+1) + i+1;
101 conn[7] = (nr+1)*(nt+1)*(k+1) + (nr+1)*(j+1) + i;
103 mesh->addConnectedCell(conn, bitpit::ElementType::HEXAHEDRON);
108 bcdir1_vertlist.clear();
109 bcdir2_vertlist.clear();
110 bcdir1_vertlist.reserve(mesh->getNVertices());
111 bcdir2_vertlist.reserve(mesh->getNVertices());
113 for(
int k=0; k<=nh; ++k){
114 for(
int i=0; i<=nr; ++i){
115 bcdir1_vertlist.push_back((nr+1)*(nt+1)*k + i);
116 bcdir2_vertlist.push_back((nr+1)*(nt+1)*k + (nr+1)*nt + i);
121 mesh->updateInterfaces();
137 MPI_Comm_size(MPI_COMM_WORLD, &nProcs);
138 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
144 std::vector<long> bc1list, bc2list;
151 livector1D pidlist1 = boundary->getCellFromVertexList(bc1list,
true);
152 livector1D pidlist2 = boundary->getCellFromVertexList(bc2list,
true);
154 for(
long cellid : pidlist1){
155 boundary->setPIDCell(cellid,
long(1));
157 for(
long cellid : pidlist2){
158 boundary->setPIDCell(cellid,
long(2));
166 std::unordered_set<long> potvertices(bc1list.begin(), bc1list.end());
167 potvertices.insert(bc2list.begin(), bc2list.end());
168 for(
long idv: potvertices){
169 bdirMesh->addVertex(boundary->getVertexCoords(idv), idv);
173 std::unordered_set<long> preservedcells (pidlist1.begin(), pidlist1.end());
174 preservedcells.insert(pidlist2.begin(), pidlist2.end());
176 for(
long idc: preservedcells){
177 bdirMesh->addCell(boundary->getPatch()->getCell(idc), idc, rank);
180 bdirMesh->updateInterfaces();
183 std::chrono::time_point<Clock> t1,t2;
189 mimmo::Partition* partition =
new mimmo::Partition();
190 partition->setPlotInExecution(
true);
191 partition->setGeometry(mesh);
192 partition->setBoundaryGeometry(bdirMesh);
193 partition->setPartitionMethod(mimmo::PartitionMethod::PARTGEOM);
201 bc_surf_field.reserve(bdirMesh->getNVertices());
203 for(
auto & cell : bdirMesh->getCells()){
204 if (cell.getPID() == 1){
205 for (
long id : cell.getVertexIds()){
206 if (!bc_surf_field.exists(
id))
207 bc_surf_field.insert(
id, {{1., 1., 0.}});
210 if (cell.getPID() == 2){
211 for (
long id : cell.getVertexIds()){
212 if (!bc_surf_field.exists(
id))
213 bc_surf_field.insert(
id, {{0., 0., 0.}});
229 mimmo::PropagateVectorField * prop =
new mimmo::PropagateVectorField();
230 prop->setGeometry(mesh);
231 prop->addDirichletBoundaryPatch(bdirMesh);
232 prop->addDirichletConditions(&bc_surf_field);
233 prop->setSolverMultiStep(10);
234 prop->setPlotInExecution(
true);
235 prop->setApply(
true);
237 prop->setDamping(
true);
238 prop->setDampingType(1);
239 prop->setDampingDecayFactor(1.0);
240 prop->setDampingInnerDistance(0.05);
241 prop->setDampingOuterDistance(0.35);
242 prop->addDampingBoundarySurface(bdirMesh);
244 prop->setNarrowBand(
false);
245 prop->setNarrowBandWidth(0.6);
246 prop->setNarrowBandRelaxation(0.7);
247 prop->addNarrowBandBoundarySurface(bdirMesh);
252 std::cout <<
"Start Propagator vector field " << std::endl;
259 std::cout <<
"Propagator vector field execution time: "
260 << std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count()
261 <<
" seconds" << std::endl;
265 prop->getGeometry()->getPatch()->write(
"deformed");
279 int main(
int argc,
char *argv[] ) {
285 MPI_Init(&argc, &argv);
293 catch(std::exception & e){
294 std::cout<<
"propagators_example_00001 exited with an error of type : "<<e.what()<<std::endl;