ribi::foam::Files ribi::foam::Mesh::CreateFiles() const noexcept { boost::shared_ptr<BoundaryFile> boundary { CreateBoundary() }; assert(boundary); boost::shared_ptr<FacesFile> faces { CreateFaces() }; assert(faces); boost::shared_ptr<NeighbourFile> neighbour { CreateNeighbour() }; assert(neighbour); boost::shared_ptr<OwnerFile> owner { CreateOwner() }; assert(owner); boost::shared_ptr<PointsFile> points { CreatePoints() }; assert(points); const Files f( boundary, faces, neighbour, owner, points ); return f; }
void StereoFrame::TriangulatePoints(const RowMatcher& matcher, std::aligned_vector<MapPoint> &points, std::vector<Measurement> &measurements)/* const*/ { #if defined(SHOW_PROFILING) && PROFILE_INTERNAL_TRIANGULATE sptam::Timer t_lock, t_create; t_lock.start(); #endif boost::unique_lock<boost::shared_mutex> lock(stereo_frames_mutex_); #if defined(SHOW_PROFILING) && PROFILE_INTERNAL_TRIANGULATE t_lock.stop(); #endif // TODO ImageFeatures podria guardar internamente el vector // de los unmatched, y descartar los matched, total nunca más los uso. // Esto permitiría recibir acá una referencia // retrieve unmatched features from both frames. std::vector<cv::KeyPoint> unmatchedKeypointsLeft, unmatchedKeypointsRight; cv::Mat unmatchedDescriptorsLeft, unmatchedDescriptorsRight; std::vector<size_t> indexesLeft, indexesRight; // Get descritptors for both images frameLeft_.GetUnmatchedKeyPoints(unmatchedKeypointsLeft, unmatchedDescriptorsLeft, indexesLeft); frameRight_.GetUnmatchedKeyPoints(unmatchedKeypointsRight, unmatchedDescriptorsRight, indexesRight); std::list<std::pair<size_t, size_t>> matches; #if defined(SHOW_PROFILING) && PROFILE_INTERNAL_TRIANGULATE t_create.start(); #endif CreatePoints( matcher, unmatchedKeypointsLeft, unmatchedDescriptorsLeft, unmatchedKeypointsRight, unmatchedDescriptorsRight, points, matches ); #if defined(SHOW_PROFILING) && PROFILE_INTERNAL_TRIANGULATE t_create.stop(); #endif measurements.reserve( matches.size() ); for ( auto pair : matches ) { size_t idxLeft = pair.first; size_t idxRight = pair.second; frameLeft_.SetMatchedKeyPoint( indexesLeft[ idxLeft ] ); frameRight_.SetMatchedKeyPoint( indexesRight[ idxRight] ); measurements.push_back( Measurement( Measurement::SRC_TRIANGULATION, unmatchedKeypointsLeft[ idxLeft ], unmatchedDescriptorsLeft.row( idxLeft ), unmatchedKeypointsRight[ idxRight ], unmatchedDescriptorsRight.row( idxRight ) ) ); } #if defined(SHOW_PROFILING) && PROFILE_INTERNAL_TRIANGULATE WriteToLog(" xx triangulate_points-lockStereo: ", t_lock); WriteToLog(" xx triangulate_points-create: ", t_create); #endif }
int main(int argc, char *argv[]) { int i,j,k,l,inmethod,outmethod,info,errorstat; int nogrids,nomeshes,nofile,dim,elementsredone=0; int nodes3d,elements3d,showmem; Real mergeeps; char prefix[MAXFILESIZE]; struct GridType *grids; struct CellType *cell[MAXCASES]; struct FemType data[MAXCASES]; struct BoundaryType *boundaries[MAXCASES]; struct ElmergridType eg; showmem = TRUE; printf("\nStarting program Elmergrid\n"); InitParameters(&eg); grids = (struct GridType*)malloc((size_t) (MAXCASES)*sizeof(struct GridType)); InitGrid(grids); info = TRUE; if(argc <= 1) { errorstat = LoadCommands(argv[1],&eg,grids,argc-1,info); Instructions(); if(errorstat) Goodbye(); } if(argc == 2) { errorstat = LoadCommands(argv[1],&eg,grids,argc-1,info); if(errorstat) Goodbye(); } else if(argc < 4) { Instructions(); Goodbye(); } else { errorstat = InlineParameters(&eg,argc,argv); if(errorstat) Goodbye(); } if(!eg.outmethod || !eg.inmethod) { printf("Please define the input and output formats\n"); } if(eg.inmethod != 1) { if(eg.outmethod == 1 || eg.outmethod == 8 || eg.outmethod == 9 || eg.outmethod == 10) { printf("input of type %d can't create output of type %d\n", eg.inmethod,eg.outmethod); errorstat++; Goodbye(); } } #if 0 if(eg.inmethod != 8 && eg.outmethod == 5) { printf("To write Easymesh format you need to read easymesh format!\n"); errorstat++; } #endif if(eg.timeron) timer_activate(eg.infofile); /**********************************/ printf("\nElmergrid loading data:\n"); printf( "-----------------------\n"); dim = eg.dim; nofile = 0; nomeshes = 0; nogrids = 0; inmethod = eg.inmethod; outmethod = eg.outmethod; read_another_file: timer_show(); switch (inmethod) { case 1: if(LoadElmergrid(&grids,&nogrids,eg.filesin[nofile],eg.relh,info) == 1) { if(dim == 3) ExampleGrid3D(&grids,&nogrids,info); if(dim == 2) ExampleGrid2D(&grids,&nogrids,info); if(dim == 1) ExampleGrid1D(&grids,&nogrids,info); SaveElmergrid(grids,nogrids,eg.filesin[nofile],info); printf("Because file %s didn't exist, it was created for you.\n",eg.filesin[nofile]); Goodbye(); } LoadCommands(eg.filesin[nofile],&eg,grids,2,info); break; case 2: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(LoadElmerInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],info)) Goodbye(); nomeshes++; break; case 3: if(LoadSolutionElmer(&(data[nofile]),TRUE,eg.filesin[nofile],info)) Goodbye(); nomeshes++; break; case 4: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); if(LoadAnsysInput(&(data[0]),boundaries[0],eg.filesin[nofile],info)) Goodbye(); nomeshes++; break; case 5: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(LoadAbaqusInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 6: if(LoadAbaqusOutput(&(data[nofile]),eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 7: if(LoadFidapInput(&(data[nofile]),eg.filesin[nofile],TRUE)) Goodbye(); boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(0 && !eg.usenames) data[nofile].boundarynamesexist = data[nofile].bodynamesexist = FALSE; ElementsToBoundaryConditions(&(data[nofile]),boundaries[nofile],FALSE,TRUE); RenumberBoundaryTypes(&data[nofile],boundaries[nofile],TRUE,0,info); nomeshes++; break; case 8: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadUniversalMesh(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 9: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(LoadComsolMesh(&(data[nofile]),eg.filesin[nofile],info)) Goodbye(); ElementsToBoundaryConditions(&(data[nofile]),boundaries[nofile],FALSE,TRUE); nomeshes++; break; case 10: if(LoadFieldviewInput(&(data[nofile]),eg.filesin[nofile],TRUE)) Goodbye(); boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } ElementsToBoundaryConditions(&(data[nofile]),boundaries[nofile],FALSE,TRUE); nomeshes++; break; case 11: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadTriangleInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 12: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadMeditInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 13: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadGidInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 14: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadGmshInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 15: if(info) printf("Partitioned solution is fused on-the-fly therefore no other operations may be performed.\n"); FuseSolutionElmerPartitioned(eg.filesin[nofile],eg.filesout[nofile],eg.decimals,eg.partjoin, eg.saveinterval[0],eg.saveinterval[1],eg.saveinterval[2],info); if(info) printf("Finishing with the fusion of partitioned Elmer solutions\n"); Goodbye(); break; #if 0 case 16: InitializeKnots(&(data[nofile])); if( Easymesh(argc,argv,&data[nofile].noknots, &data[nofile].noelements,&sides)) Goodbye(); data[nofile].dim = 2; data[nofile].coordsystem = COORD_CART2; data[nofile].maxnodes = 3; AllocateKnots(&(data[nofile])); boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(EasymeshCopy(&(data[nofile]),boundaries[nofile])) Goodbye(); nomeshes++; break; #endif case 17: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadNastranInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; case 18: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if(LoadCGsimMesh(&(data[nofile]),eg.filesin[nofile],info)) Goodbye(); nomeshes++; break; case 19: boundaries[nofile] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) { boundaries[nofile][i].created = FALSE; boundaries[nofile][i].nosides = 0; } if (LoadGeoInput(&(data[nofile]),boundaries[nofile],eg.filesin[nofile],TRUE)) Goodbye(); nomeshes++; break; default: Instructions(); Goodbye(); } nofile++; if(nofile < eg.nofilesin) { printf("\nElmergrid loading data from another file:\n"); goto read_another_file; } /***********************************/ redoelements: printf("\nElmergrid creating and manipulating meshes:\n"); printf( "-------------------------------------------\n"); timer_show(); if(nogrids > nomeshes && outmethod != 1) { nomeshes = nogrids; for(k=0;k<nogrids;k++) { CreateCells(&(grids[k]),&(cell[k]),info); CreateKnots(&(grids[k]),cell[k],&(data[k]),0,0); boundaries[k] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(j=0;j<MAXBOUNDARIES;j++) { boundaries[k][j].created = FALSE; boundaries[k][j].nosides = FALSE; } if(grids[k].noboundaries > 0) { for(j=0;j<grids[k].noboundaries;j++) { if(grids[k].boundsolid[j] < 4) { CreateBoundary(cell[k],&(data[k]),&(boundaries[k][j]), grids[k].boundext[j],grids[k].boundint[j], 1,grids[k].boundtype[j]); } else { CreatePoints(cell[k],&(data[k]),&(boundaries[k][j]), grids[k].boundext[j],grids[k].boundint[j], grids[k].boundsolid[j],grids[k].boundtype[j]); } } } } } /* In some formats the dimension for curved 2D meshes seems to be set to 2. This should fix the problem for all input types. */ if( data->dim < 3 ) { data->dim = GetCoordinateDimension(data,info); } /* Make the discontinous boundary needed, for example, in poor thermal conduction */ for(k=0;k<nomeshes;k++) { if(!eg.discont) { for(j=0;j<grids[k].noboundaries;j++) if(grids[k].boundsolid[j] == 2) { eg.discontbounds[eg.discont] = grids[k].boundtype[j]; eg.discont++; } } if(eg.discont) { for(i=1;i<=eg.discont;i++) SetDiscontinuousBoundary(&(data[k]),boundaries[k],eg.discontbounds[i-1],2,info); } } /* Divide quadrilateral meshes into triangular meshes */ for(k=0;k<nomeshes;k++) if(nogrids && (eg.triangles || grids[k].triangles == TRUE)) { Real criticalangle; criticalangle = MAX(eg.triangleangle , grids[k].triangleangle); ElementsToTriangles(&data[k],boundaries[k],criticalangle,info); } /* Make a boundary layer with two different methods */ if(eg.layers > 0) for(k=0;k<nomeshes;k++) CreateBoundaryLayer(&data[k],boundaries[k],eg.layers, eg.layerbounds, eg.layernumber, eg.layerratios, eg.layerthickness, eg.layerparents, eg.layermove, eg.layereps, info); else if(eg.layers < 0) for(k=0;k<nomeshes;k++) CreateBoundaryLayerDivide(&data[k],boundaries[k],abs(eg.layers), eg.layerbounds, eg.layernumber, eg.layerratios, eg.layerthickness, eg.layerparents, info); /* Take up the infor on rotation */ for(k=0;k<nogrids;k++) if( grids[k].rotatecurve ) { eg.rotatecurve = TRUE; eg.curvezet = grids[k].curvezet; eg.curverad = grids[k].curverad; eg.curveangle = grids[k].curveangle; } if(outmethod != 1 && dim != 2 && eg.dim != 2) { j = MAX(nogrids,1); for(k=0;k<j;k++) { if(grids[k].dimension == 3 || grids[k].rotate) { boundaries[j] = (struct BoundaryType*) malloc((size_t) (MAXBOUNDARIES)*sizeof(struct BoundaryType)); for(i=0;i<MAXBOUNDARIES;i++) boundaries[j][i].created = FALSE; CreateKnotsExtruded(&(data[k]),boundaries[k],&(grids[k]), &(data[j]),boundaries[j],info); if(nogrids) { elements3d = MAX(eg.elements3d, grids[k].wantedelems3d); nodes3d = MAX(eg.nodes3d, grids[k].wantednodes3d); if(elements3d) { if( abs(data[j].noelements - elements3d) / (1.0*elements3d) > 0.01 && elementsredone < 5 ) { grids[k].wantedelems *= pow(1.0*elements3d / data[j].noelements, (2.0/3.0)); elementsredone++; } else elementsredone = 0; } else if(nodes3d) { if( abs(data[j].noknots - nodes3d) / (1.0*nodes3d) > 0.01 && elementsredone < 5 ) { grids[k].wantedelems *= pow(1.0*nodes3d / data[j].noknots, (2.0/3.0)); elementsredone++; } else elementsredone = 0; } if(elementsredone) { nomeshes = 0; for(i=0;i < nogrids;i++) SetElementDivision(&(grids[i]),eg.relh,info); DestroyKnots(&data[j]); DestroyKnots(&data[k]); free(cell[k]); if(info) printf("Iteration %d of elements number targiting %d in 2D\n", elementsredone,grids[k].wantedelems); goto redoelements; } } data[k] = data[j]; boundaries[k] = boundaries[j]; } } } /* If the original mesh was given in polar coordinates make the transformation into cartesian ones */ for(k=0;k<nomeshes;k++) { if(eg.polar || data[k].coordsystem == COORD_POLAR) { if(!eg.polar) eg.polarradius = grids[k].polarradius; PolarCoordinates(&data[k],eg.polarradius,info); } } /* If the original mesh was given in cylindrical coordinates make the transformation into cartesian ones */ for(k=0;k<nomeshes;k++) { if(eg.cylinder || data[k].coordsystem == COORD_CYL) { CylinderCoordinates(&data[k],info); } } if(1) for(k=0;k<nomeshes;k++) RotateTranslateScale(&data[k],&eg,info); /* Rotate may apply to 2d and 3d geometries as well */ for(k=0;k<nomeshes;k++) if(eg.rotatecurve) CylindricalCoordinateCurve(&data[k],eg.curvezet,eg.curverad,eg.curveangle); /* Unite meshes if there are several of them */ if(eg.unitemeshes) { for(k=1;k<nomeshes;k++) UniteMeshes(&data[0],&data[k],boundaries[0],boundaries[k],info); nomeshes = nogrids = 1; } if(eg.clone[0] || eg.clone[1] || eg.clone[2]) { for(k=0;k<nomeshes;k++) { CloneMeshes(&data[k],boundaries[k],eg.clone,eg.clonesize,FALSE,info); mergeeps = fabs(eg.clonesize[0]+eg.clonesize[1]+eg.clonesize[2]) * 1.0e-8; MergeElements(&data[k],boundaries[k],eg.order,eg.corder,mergeeps,TRUE,TRUE); } } if(eg.mirror[0] || eg.mirror[1] || eg.mirror[2]) { for(k=0;k<nomeshes;k++) { MirrorMeshes(&data[k],boundaries[k],eg.mirror,FALSE,eg.clonesize,eg.mirrorbc,info); mergeeps = fabs(eg.clonesize[0]+eg.clonesize[1]+eg.clonesize[2]) * 1.0e-8; MergeElements(&data[k],boundaries[k],eg.order,eg.corder,mergeeps,FALSE,TRUE); } } /* Naming convection for the case of several meshes */ if(nomeshes > 1) { strcpy(prefix,eg.filesout[0]); for(k=0;k<nomeshes;k++) sprintf(eg.filesout[k],"%s%d",prefix,k+1); } for(k=0;k<nomeshes;k++) { if(nogrids && grids[k].reduceordermatmax) { eg.reduce = TRUE; eg.reducemat1 = grids[k].reduceordermatmin; eg.reducemat2 = grids[k].reduceordermatmax; } if(eg.reduce) ReduceElementOrder(&data[k],eg.reducemat1,eg.reducemat2); } for(k=0;k<nomeshes;k++) if(eg.increase) IncreaseElementOrder(&data[k],TRUE); for(k=0;k<nomeshes;k++) { if(eg.merge) MergeElements(&data[k],boundaries[k],eg.order,eg.corder,eg.cmerge,FALSE,TRUE); else if(eg.order == 3) #if PARTMETIS ReorderElementsMetis(&data[k],TRUE); #else printf("Cannot order nodes by Metis as it is not even compiled!\n"); #endif else if(eg.order) ReorderElements(&data[k],boundaries[k],eg.order,eg.corder,TRUE); if(eg.isoparam) IsoparametricElements(&data[k],boundaries[k],TRUE,info); }
int main(int argc, char **argv) { AppCtx ctx; PetscErrorCode (**funcs)(PetscInt dim, PetscReal time, const PetscReal x[], PetscInt Nf, PetscScalar *u, void *ctx); DM dm; PetscFE fe; DMInterpolationInfo interpolator; Vec lu, fieldVals; PetscScalar *vals; const PetscScalar *ivals, *vcoords; PetscReal *pcoords; PetscBool pointsAllProcs=PETSC_TRUE; PetscInt spaceDim, c, Np, p; PetscMPIInt rank, size; PetscViewer selfviewer; PetscErrorCode ierr; ierr = PetscInitialize(&argc, &argv, NULL,help);if (ierr) return ierr; ierr = ProcessOptions(PETSC_COMM_WORLD, &ctx);CHKERRQ(ierr); ierr = CreateMesh(PETSC_COMM_WORLD, &ctx, &dm);CHKERRQ(ierr); ierr = DMGetCoordinateDim(dm, &spaceDim);CHKERRQ(ierr); ierr = MPI_Comm_rank(PETSC_COMM_WORLD, &rank);CHKERRQ(ierr); ierr = MPI_Comm_size(PETSC_COMM_WORLD, &size);CHKERRQ(ierr); /* Create points */ ierr = CreatePoints(dm, &Np, &pcoords, &pointsAllProcs, &ctx);CHKERRQ(ierr); /* Create interpolator */ ierr = DMInterpolationCreate(PETSC_COMM_WORLD, &interpolator);CHKERRQ(ierr); ierr = DMInterpolationSetDim(interpolator, spaceDim);CHKERRQ(ierr); ierr = DMInterpolationAddPoints(interpolator, Np, pcoords);CHKERRQ(ierr); ierr = DMInterpolationSetUp(interpolator, dm, pointsAllProcs);CHKERRQ(ierr); /* Check locations */ for (c = 0; c < interpolator->n; ++c) { ierr = PetscSynchronizedPrintf(PETSC_COMM_WORLD, "[%d]Point %D is in Cell %D\n", rank, c, interpolator->cells[c]);CHKERRQ(ierr); } ierr = PetscSynchronizedFlush(PETSC_COMM_WORLD, NULL);CHKERRQ(ierr); ierr = VecView(interpolator->coords, PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); /* Setup Discretization */ ierr = PetscFECreateDefault(PetscObjectComm((PetscObject) dm), ctx.dim, Nc, ctx.cellSimplex, NULL, -1, &fe);CHKERRQ(ierr); ierr = DMSetField(dm, 0, NULL, (PetscObject) fe);CHKERRQ(ierr); ierr = DMCreateDS(dm);CHKERRQ(ierr); ierr = PetscFEDestroy(&fe);CHKERRQ(ierr); /* Create function */ ierr = PetscCalloc2(Nc, &funcs, Nc, &vals);CHKERRQ(ierr); for (c = 0; c < Nc; ++c) funcs[c] = linear; ierr = DMGetLocalVector(dm, &lu);CHKERRQ(ierr); ierr = DMProjectFunctionLocal(dm, 0.0, funcs, NULL, INSERT_ALL_VALUES, lu);CHKERRQ(ierr); ierr = PetscViewerASCIIPushSynchronized(PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = PetscViewerGetSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&selfviewer);CHKERRQ(ierr); ierr = PetscViewerASCIIPrintf(selfviewer, "[%d]solution\n", rank);CHKERRQ(ierr); ierr = VecView(lu,selfviewer);CHKERRQ(ierr); ierr = PetscViewerRestoreSubViewer(PETSC_VIEWER_STDOUT_WORLD,PETSC_COMM_SELF,&selfviewer);CHKERRQ(ierr); ierr = PetscViewerFlush(PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); ierr = PetscViewerASCIIPopSynchronized(PETSC_VIEWER_STDOUT_WORLD);CHKERRQ(ierr); /* Check interpolant */ ierr = VecCreateSeq(PETSC_COMM_SELF, interpolator->n * Nc, &fieldVals);CHKERRQ(ierr); ierr = DMInterpolationSetDof(interpolator, Nc);CHKERRQ(ierr); ierr = DMInterpolationEvaluate(interpolator, dm, lu, fieldVals);CHKERRQ(ierr); for (p = 0; p < size; ++p) { if (p == rank) { ierr = PetscPrintf(PETSC_COMM_SELF, "[%d]Field values\n", rank);CHKERRQ(ierr); ierr = VecView(fieldVals, PETSC_VIEWER_STDOUT_SELF);CHKERRQ(ierr); } ierr = PetscBarrier((PetscObject) dm);CHKERRQ(ierr); } ierr = VecGetArrayRead(interpolator->coords, &vcoords);CHKERRQ(ierr); ierr = VecGetArrayRead(fieldVals, &ivals);CHKERRQ(ierr); for (p = 0; p < interpolator->n; ++p) { for (c = 0; c < Nc; ++c) { #if defined(PETSC_USE_COMPLEX) PetscReal vcoordsReal[3]; PetscInt i; for (i = 0; i < spaceDim; i++) vcoordsReal[i] = PetscRealPart(vcoords[p * spaceDim + i]); #else const PetscReal *vcoordsReal = &vcoords[p*spaceDim]; #endif (*funcs[c])(ctx.dim, 0.0, vcoordsReal, 1, vals, NULL); if (PetscAbsScalar(ivals[p*Nc+c] - vals[c]) > PETSC_SQRT_MACHINE_EPSILON) SETERRQ4(PETSC_COMM_SELF, PETSC_ERR_PLIB, "Invalid interpolated value %g != %g (%D, %D)", (double) PetscRealPart(ivals[p*Nc+c]), (double) PetscRealPart(vals[c]), p, c); } } ierr = VecRestoreArrayRead(interpolator->coords, &vcoords);CHKERRQ(ierr); ierr = VecRestoreArrayRead(fieldVals, &ivals);CHKERRQ(ierr); /* Cleanup */ ierr = PetscFree(pcoords);CHKERRQ(ierr); ierr = PetscFree2(funcs, vals);CHKERRQ(ierr); ierr = VecDestroy(&fieldVals);CHKERRQ(ierr); ierr = DMRestoreLocalVector(dm, &lu);CHKERRQ(ierr); ierr = DMInterpolationDestroy(&interpolator);CHKERRQ(ierr); ierr = DMDestroy(&dm);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }
std::vector<boost::shared_ptr<ribi::trim::Cell>> ribi::trim::CellsCreator::CreateCells( const boost::shared_ptr<const Template> t, const int n_face_layers, const boost::units::quantity<boost::units::si::length> layer_height, const CreateVerticalFacesStrategy strategy, const bool verbose ) noexcept { assert(t); if (n_face_layers < 2 || t->GetPoints().empty() ) { std::vector<boost::shared_ptr<ribi::trim::Cell>> no_cells; return no_cells; } assert(n_face_layers >= 2); if (verbose) { std::clog << __FILE__ << "(" << (__LINE__) << ") : " << "Create points" << std::endl ; } const std::vector<boost::shared_ptr<Point>> all_points = CreatePoints(t,n_face_layers,layer_height); if (verbose) { std::clog << __FILE__ << "(" << (__LINE__) << ") : " << "Create horizontal faces" << std::endl ; } const std::vector<boost::shared_ptr<Face>> hor_faces = CreateHorizontalFaces(t,all_points,n_face_layers); if (verbose) { std::clog << __FILE__ << "(" << (__LINE__) << ") : " << "Create vertical faces" << std::endl ; } const std::vector<boost::shared_ptr<Face>> ver_faces = CreateVerticalFaces(t,all_points,n_face_layers,layer_height,strategy,verbose); if (verbose) { std::clog << __FILE__ << "(" << (__LINE__) << ") : " << "Created " << ver_faces.size() << " vertical faces" << std::endl ; } if (ver_faces.empty()) { std::vector<boost::shared_ptr<ribi::trim::Cell>> no_cells; return no_cells; } #ifndef NDEBUG for(const auto f:ver_faces) { assert(f); } #endif const int n_hor_faces_per_layer = static_cast<int>(t->GetFaces().size()); const int n_cells_per_layer = n_hor_faces_per_layer; if (verbose) { std::clog << __FILE__ << "(" << (__LINE__) << ") : " << "Creating cells" << std::endl ; } std::vector<boost::shared_ptr<Cell>> cells; for (int layer=0; layer!=n_face_layers-1; ++layer) //-1 because there are no points above the top layer { if (verbose) { std::clog << "."; } for (int i=0; i!=n_cells_per_layer; ++i) { const int bottom_face_index = ((layer + 0) * n_hor_faces_per_layer) + i; const int top_face_index = ((layer + 1) * n_hor_faces_per_layer) + i; assert(bottom_face_index >= 0); assert(top_face_index >= 0); assert(bottom_face_index < static_cast<int>(hor_faces.size())); assert(top_face_index < static_cast<int>(hor_faces.size())); const std::vector<boost::shared_ptr<Face>> these_ver_faces { FindKnownFacesBetween( hor_faces[bottom_face_index], hor_faces[top_face_index] ) }; if (strategy == CreateVerticalFacesStrategy::one_face_per_square ) { #ifndef NDEBUG if (these_ver_faces.size() != 3) { TRACE("BREAK"); } #endif assert(these_ver_faces.size() == 3); assert(hor_faces[bottom_face_index]); assert(hor_faces[top_face_index]); assert(these_ver_faces[0]); assert(these_ver_faces[1]); assert(these_ver_faces[2]); const boost::shared_ptr<Cell> cell( CellFactory().Create( { hor_faces[bottom_face_index], hor_faces[top_face_index], these_ver_faces[0], these_ver_faces[1], these_ver_faces[2] }, strategy ) ); assert(hor_faces[bottom_face_index]); assert(hor_faces[top_face_index]); assert(Helper().IsHorizontal(*hor_faces[bottom_face_index])); assert(Helper().IsHorizontal(*hor_faces[top_face_index])); assert(Helper().IsVertical(*these_ver_faces[0])); assert(Helper().IsVertical(*these_ver_faces[1])); assert(Helper().IsVertical(*these_ver_faces[2])); cells.push_back(cell); } else { assert(these_ver_faces.size() == 6); const boost::shared_ptr<Cell> cell { CellFactory().Create( { hor_faces[bottom_face_index], hor_faces[top_face_index], these_ver_faces[0], these_ver_faces[1], these_ver_faces[2], these_ver_faces[3], these_ver_faces[4], these_ver_faces[5] }, strategy ) }; assert(hor_faces[bottom_face_index]); assert(hor_faces[top_face_index]); assert(Helper().IsHorizontal(*hor_faces[bottom_face_index])); assert(Helper().IsHorizontal(*hor_faces[top_face_index])); assert(Helper().IsVertical(*these_ver_faces[0])); assert(Helper().IsVertical(*these_ver_faces[1])); assert(Helper().IsVertical(*these_ver_faces[2])); assert(Helper().IsVertical(*these_ver_faces[3])); assert(Helper().IsVertical(*these_ver_faces[4])); assert(Helper().IsVertical(*these_ver_faces[5])); cells.push_back(cell); } } } #ifndef NDEBUG if (verbose) { std::clog << __FILE__ << "(" << (__LINE__) << ") : " << "Checking cells" << std::endl ; } CheckCells(cells); #endif // NDEBUG if (verbose) { std::clog << __FILE__ << "(" << (__LINE__) << ") : " << "Done creating cells" << std::endl ; } return cells; }