Lines Matching refs:sw
170 static PetscErrorCode CreateParticles(DM dm, DM *sw, AppCtx *user) in CreateParticles() argument
188 PetscCall(DMCreate(PetscObjectComm((PetscObject)dm), sw)); in CreateParticles()
189 PetscCall(DMSetType(*sw, DMSWARM)); in CreateParticles()
190 PetscCall(DMSetDimension(*sw, dim)); in CreateParticles()
199 PetscCall(DMSwarmSetType(*sw, DMSWARM_PIC)); in CreateParticles()
200 PetscCall(DMSwarmSetCellDM(*sw, dm)); in CreateParticles()
201 PetscCall(DMSwarmRegisterPetscDatatypeField(*sw, "w_q", 1, PETSC_SCALAR)); in CreateParticles()
202 PetscCall(DMSwarmFinalizeFieldRegister(*sw)); in CreateParticles()
204 PetscCall(DMSwarmSetLocalSizes(*sw, Ncell * Np, 0)); in CreateParticles()
205 PetscCall(DMSetFromOptions(*sw)); in CreateParticles()
207 PetscCall(DMSwarmGetCellDMActive(*sw, &celldm)); in CreateParticles()
210 …PetscCheck(Nfc == 1, PetscObjectComm((PetscObject)sw), PETSC_ERR_SUP, "We only support a single co… in CreateParticles()
212 PetscCall(DMSwarmGetField(*sw, coordFields[0], NULL, NULL, (void **)&coords)); in CreateParticles()
213 PetscCall(DMSwarmGetField(*sw, cellid, NULL, NULL, (void **)&swarm_cellid)); in CreateParticles()
214 PetscCall(DMSwarmGetField(*sw, "w_q", NULL, NULL, (void **)&vals)); in CreateParticles()
253 PetscCall(DMSwarmRestoreField(*sw, coordFields[0], NULL, NULL, (void **)&coords)); in CreateParticles()
254 PetscCall(DMSwarmRestoreField(*sw, cellid, NULL, NULL, (void **)&swarm_cellid)); in CreateParticles()
255 PetscCall(DMSwarmRestoreField(*sw, "w_q", NULL, NULL, (void **)&vals)); in CreateParticles()
258 PetscCall(PetscObjectSetName((PetscObject)*sw, "Particles")); in CreateParticles()
259 PetscCall(DMSwarmVectorDefineField(*sw, "w_q")); in CreateParticles()
260 PetscCall(DMViewFromOptions(*sw, NULL, "-sw_view")); in CreateParticles()
264 static PetscErrorCode CreateParticles_Shape(DM dm, DM *sw, AppCtx *user) in CreateParticles_Shape() argument
284 PetscCall(DMCreate(PetscObjectComm((PetscObject)dm), sw)); in CreateParticles_Shape()
285 PetscCall(DMSetType(*sw, DMSWARM)); in CreateParticles_Shape()
286 PetscCall(DMSetDimension(*sw, dim)); in CreateParticles_Shape()
287 PetscCall(DMSwarmSetType(*sw, DMSWARM_PIC)); in CreateParticles_Shape()
288 PetscCall(DMSwarmSetCellDM(*sw, dm)); in CreateParticles_Shape()
289 PetscCall(DMSwarmGetCellDMActive(*sw, &celldm)); in CreateParticles_Shape()
292 …PetscCheck(Nfc == 1, PetscObjectComm((PetscObject)sw), PETSC_ERR_SUP, "We only support a single co… in CreateParticles_Shape()
293 PetscCall(DMSwarmRegisterPetscDatatypeField(*sw, "w_q", 1, PETSC_REAL)); in CreateParticles_Shape()
294 PetscCall(DMSwarmFinalizeFieldRegister(*sw)); in CreateParticles_Shape()
295 PetscCall(DMSwarmSetLocalSizes(*sw, (cEnd - cStart) * Nq, 0)); in CreateParticles_Shape()
296 PetscCall(DMSetFromOptions(*sw)); in CreateParticles_Shape()
299 PetscCall(DMSwarmGetField(*sw, coordFields[0], NULL, NULL, (void **)&coords)); in CreateParticles_Shape()
300 PetscCall(DMSwarmGetField(*sw, cellid, NULL, NULL, (void **)&swarm_cellid)); in CreateParticles_Shape()
301 PetscCall(DMSwarmGetField(*sw, "w_q", NULL, NULL, (void **)&vals)); in CreateParticles_Shape()
311 PetscCall(DMSwarmRestoreField(*sw, coordFields[0], NULL, NULL, (void **)&coords)); in CreateParticles_Shape()
312 PetscCall(DMSwarmRestoreField(*sw, cellid, NULL, NULL, (void **)&swarm_cellid)); in CreateParticles_Shape()
313 PetscCall(DMSwarmRestoreField(*sw, "w_q", NULL, NULL, (void **)&vals)); in CreateParticles_Shape()
315 PetscCall(DMSwarmMigrate(*sw, PETSC_FALSE)); in CreateParticles_Shape()
316 PetscCall(PetscObjectSetName((PetscObject)*sw, "Particles")); in CreateParticles_Shape()
317 PetscCall(DMSwarmVectorDefineField(*sw, "w_q")); in CreateParticles_Shape()
318 PetscCall(DMViewFromOptions(*sw, NULL, "-sw_view")); in CreateParticles_Shape()
322 static PetscErrorCode computeParticleMoments(DM sw, PetscReal moments[3], AppCtx *user) in computeParticleMoments() argument
331 PetscCall(DMGetDimension(sw, &dim)); in computeParticleMoments()
332 PetscCall(DMSwarmGetCellDM(sw, &dm)); in computeParticleMoments()
334 PetscCall(DMSwarmSortGetAccess(sw)); in computeParticleMoments()
335 PetscCall(DMSwarmGetField(sw, DMSwarmPICField_coor, NULL, NULL, (void **)&coords)); in computeParticleMoments()
336 PetscCall(DMSwarmGetField(sw, "w_q", NULL, NULL, (void **)&w)); in computeParticleMoments()
341 PetscCall(DMSwarmSortGetPointsPerCell(sw, cell, &Np, &pidx)); in computeParticleMoments()
350 PetscCall(DMSwarmSortRestorePointsPerCell(sw, cell, &Np, &pidx)); in computeParticleMoments()
352 PetscCall(DMSwarmRestoreField(sw, DMSwarmPICField_coor, NULL, NULL, (void **)&coords)); in computeParticleMoments()
353 PetscCall(DMSwarmRestoreField(sw, "w_q", NULL, NULL, (void **)&w)); in computeParticleMoments()
354 PetscCall(DMSwarmSortRestoreAccess(sw)); in computeParticleMoments()
355 …PetscCallMPI(MPIU_Allreduce(mom, moments, 3, MPIU_REAL, MPI_SUM, PetscObjectComm((PetscObject)sw))… in computeParticleMoments()
396 static PetscErrorCode TestL2ProjectionParticlesToField(DM dm, DM sw, Vec fhat, AppCtx *user) in TestL2ProjectionParticlesToField() argument
404 PetscCall(DMSwarmProjectFields(sw, dm, 1, fieldnames, fields, SCATTER_FORWARD)); in TestL2ProjectionParticlesToField()
407 PetscCall(computeParticleMoments(sw, pmoments, user)); in TestL2ProjectionParticlesToField()
417 static PetscErrorCode TestL2ProjectionFieldToParticles(DM dm, DM sw, Vec fhat, AppCtx *user) in TestL2ProjectionFieldToParticles() argument
425 PetscCall(DMSwarmProjectFields(sw, dm, 1, fieldnames, fields, SCATTER_REVERSE)); in TestL2ProjectionFieldToParticles()
428 PetscCall(computeParticleMoments(sw, pmoments, user)); in TestL2ProjectionFieldToParticles()
548 static PetscErrorCode TestFieldGradientProjection(DM dm, DM sw, AppCtx *user) in TestFieldGradientProjection() argument
567 PetscCall(DMCreateMassMatrix(sw, dm, &M_p)); in TestFieldGradientProjection()
571 PetscCall(DMSwarmCreateGlobalVectorFromField(sw, "w_q", &f)); in TestFieldGradientProjection()
575 PetscCall(DMSwarmDestroyGlobalVectorFromField(sw, "w_q", &f)); in TestFieldGradientProjection()
592 PetscCall(computeParticleMoments(sw, pmoments, user)); in TestFieldGradientProjection()
608 static PetscErrorCode TestL2Projection_Shape(DM dm, DM sw, AppCtx *user) in TestL2Projection_Shape() argument
621 PetscCall(DMSwarmCreateGlobalVectorFromField(sw, "w_q", &u)); in TestL2Projection_Shape()
624 PetscCall(DMCreateMassMatrix(sw, dm, &mass)); in TestL2Projection_Shape()
628 PetscCall(DMSwarmDestroyGlobalVectorFromField(sw, "w_q", &u)); in TestL2Projection_Shape()
651 DM dm, sw; in main() local
663 PetscCall(CreateParticles(dm, &sw, &user)); in main()
665 PetscCall(TestL2ProjectionParticlesToField(dm, sw, fhat, &user)); in main()
666 PetscCall(TestL2ProjectionFieldToParticles(dm, sw, fhat, &user)); in main()
667 PetscCall(TestFieldGradientProjection(dm, sw, &user)); in main()
670 PetscCall(CreateParticles_Shape(dm, &sw, &user)); in main()
671 PetscCall(TestL2Projection_Shape(dm, sw, &user)); in main()
674 PetscCall(DMDestroy(&sw)); in main()