| misc.c (367c849e96f2729f89d873e43adcb60b6350e603) | misc.c (a424bcd0dd58ea8f8b80ddde5af211268f0b358a) |
|---|---|
| 1// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2// All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3// 4// SPDX-License-Identifier: BSD-2-Clause 5// 6// This file is part of CEED: http://github.com/ceed 7 8/// @file 9/// Miscellaneous utility functions 10 11#include <ceed.h> 12#include <petscdm.h> 13#include <petscsf.h> 14#include <petscts.h> 15 16#include "../navierstokes.h" 17#include "../qfunctions/mass.h" 18 19PetscErrorCode ICs_FixMultiplicity(DM dm, CeedData ceed_data, User user, Vec Q_loc, Vec Q, CeedScalar time) { | 1// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors. 2// All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3// 4// SPDX-License-Identifier: BSD-2-Clause 5// 6// This file is part of CEED: http://github.com/ceed 7 8/// @file 9/// Miscellaneous utility functions 10 11#include <ceed.h> 12#include <petscdm.h> 13#include <petscsf.h> 14#include <petscts.h> 15 16#include "../navierstokes.h" 17#include "../qfunctions/mass.h" 18 19PetscErrorCode ICs_FixMultiplicity(DM dm, CeedData ceed_data, User user, Vec Q_loc, Vec Q, CeedScalar time) { |
| 20 Ceed ceed = user->ceed; |
|
| 20 PetscFunctionBeginUser; 21 22 // --------------------------------------------------------------------------- 23 // Update time for evaluation 24 // --------------------------------------------------------------------------- | 21 PetscFunctionBeginUser; 22 23 // --------------------------------------------------------------------------- 24 // Update time for evaluation 25 // --------------------------------------------------------------------------- |
| 25 if (user->phys->ics_time_label) CeedOperatorSetContextDouble(ceed_data->op_ics_ctx->op, user->phys->ics_time_label, &time); | 26 if (user->phys->ics_time_label) PetscCallCeed(ceed, CeedOperatorSetContextDouble(ceed_data->op_ics_ctx->op, user->phys->ics_time_label, &time)); |
| 26 27 // --------------------------------------------------------------------------- 28 // ICs 29 // --------------------------------------------------------------------------- 30 // -- CEED Restriction 31 CeedVector q0_ceed; | 27 28 // --------------------------------------------------------------------------- 29 // ICs 30 // --------------------------------------------------------------------------- 31 // -- CEED Restriction 32 CeedVector q0_ceed; |
| 32 CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &q0_ceed, NULL); | 33 PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &q0_ceed, NULL)); |
| 33 34 // -- Place PETSc vector in CEED vector 35 PetscCall(ApplyCeedOperatorLocalToGlobal(NULL, Q, ceed_data->op_ics_ctx)); 36 37 // --------------------------------------------------------------------------- 38 // Fix multiplicity for output of ICs 39 // --------------------------------------------------------------------------- 40 // -- CEED Restriction 41 CeedVector mult_vec; | 34 35 // -- Place PETSc vector in CEED vector 36 PetscCall(ApplyCeedOperatorLocalToGlobal(NULL, Q, ceed_data->op_ics_ctx)); 37 38 // --------------------------------------------------------------------------- 39 // Fix multiplicity for output of ICs 40 // --------------------------------------------------------------------------- 41 // -- CEED Restriction 42 CeedVector mult_vec; |
| 42 CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &mult_vec, NULL); | 43 PetscCallCeed(ceed, CeedElemRestrictionCreateVector(ceed_data->elem_restr_q, &mult_vec, NULL)); |
| 43 44 // -- Place PETSc vector in CEED vector 45 PetscMemType m_mem_type; 46 Vec multiplicity_loc; 47 PetscCall(DMGetLocalVector(dm, &multiplicity_loc)); 48 PetscCall(VecP2C(multiplicity_loc, &m_mem_type, mult_vec)); 49 50 // -- Get multiplicity | 44 45 // -- Place PETSc vector in CEED vector 46 PetscMemType m_mem_type; 47 Vec multiplicity_loc; 48 PetscCall(DMGetLocalVector(dm, &multiplicity_loc)); 49 PetscCall(VecP2C(multiplicity_loc, &m_mem_type, mult_vec)); 50 51 // -- Get multiplicity |
| 51 CeedElemRestrictionGetMultiplicity(ceed_data->elem_restr_q, mult_vec); | 52 PetscCallCeed(ceed, CeedElemRestrictionGetMultiplicity(ceed_data->elem_restr_q, mult_vec)); |
| 52 53 // -- Restore vectors 54 PetscCall(VecC2P(mult_vec, m_mem_type, multiplicity_loc)); 55 56 // -- Local-to-Global 57 Vec multiplicity; 58 PetscCall(DMGetGlobalVector(dm, &multiplicity)); 59 PetscCall(VecZeroEntries(multiplicity)); 60 PetscCall(DMLocalToGlobal(dm, multiplicity_loc, ADD_VALUES, multiplicity)); 61 62 // -- Fix multiplicity 63 PetscCall(VecPointwiseDivide(Q, Q, multiplicity)); 64 PetscCall(VecPointwiseDivide(Q_loc, Q_loc, multiplicity_loc)); 65 66 // -- Restore vectors 67 PetscCall(DMRestoreLocalVector(dm, &multiplicity_loc)); 68 PetscCall(DMRestoreGlobalVector(dm, &multiplicity)); 69 70 // Cleanup | 53 54 // -- Restore vectors 55 PetscCall(VecC2P(mult_vec, m_mem_type, multiplicity_loc)); 56 57 // -- Local-to-Global 58 Vec multiplicity; 59 PetscCall(DMGetGlobalVector(dm, &multiplicity)); 60 PetscCall(VecZeroEntries(multiplicity)); 61 PetscCall(DMLocalToGlobal(dm, multiplicity_loc, ADD_VALUES, multiplicity)); 62 63 // -- Fix multiplicity 64 PetscCall(VecPointwiseDivide(Q, Q, multiplicity)); 65 PetscCall(VecPointwiseDivide(Q_loc, Q_loc, multiplicity_loc)); 66 67 // -- Restore vectors 68 PetscCall(DMRestoreLocalVector(dm, &multiplicity_loc)); 69 PetscCall(DMRestoreGlobalVector(dm, &multiplicity)); 70 71 // Cleanup |
| 71 CeedVectorDestroy(&mult_vec); 72 CeedVectorDestroy(&q0_ceed); | 72 PetscCallCeed(ceed, CeedVectorDestroy(&mult_vec)); 73 PetscCallCeed(ceed, CeedVectorDestroy(&q0_ceed)); |
| 73 74 PetscFunctionReturn(PETSC_SUCCESS); 75} 76 77PetscErrorCode DMPlexInsertBoundaryValues_NS(DM dm, PetscBool insert_essential, Vec Q_loc, PetscReal time, Vec face_geom_FVM, Vec cell_geom_FVM, 78 Vec grad_FVM) { 79 Vec Qbc, boundary_mask; 80 PetscFunctionBegin; --- 176 unchanged lines hidden (view full) --- 257} 258 259// Return mass qfunction specification for number of components N 260PetscErrorCode CreateMassQFunction(Ceed ceed, CeedInt N, CeedInt q_data_size, CeedQFunction *qf) { 261 PetscFunctionBeginUser; 262 263 switch (N) { 264 case 1: | 74 75 PetscFunctionReturn(PETSC_SUCCESS); 76} 77 78PetscErrorCode DMPlexInsertBoundaryValues_NS(DM dm, PetscBool insert_essential, Vec Q_loc, PetscReal time, Vec face_geom_FVM, Vec cell_geom_FVM, 79 Vec grad_FVM) { 80 Vec Qbc, boundary_mask; 81 PetscFunctionBegin; --- 176 unchanged lines hidden (view full) --- 258} 259 260// Return mass qfunction specification for number of components N 261PetscErrorCode CreateMassQFunction(Ceed ceed, CeedInt N, CeedInt q_data_size, CeedQFunction *qf) { 262 PetscFunctionBeginUser; 263 264 switch (N) { 265 case 1: |
| 265 CeedQFunctionCreateInterior(ceed, 1, Mass_1, Mass_1_loc, qf); | 266 PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Mass_1, Mass_1_loc, qf)); |
| 266 break; 267 case 5: | 267 break; 268 case 5: |
| 268 CeedQFunctionCreateInterior(ceed, 1, Mass_5, Mass_5_loc, qf); | 269 PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Mass_5, Mass_5_loc, qf)); |
| 269 break; 270 case 7: | 270 break; 271 case 7: |
| 271 CeedQFunctionCreateInterior(ceed, 1, Mass_7, Mass_7_loc, qf); | 272 PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Mass_7, Mass_7_loc, qf)); |
| 272 break; 273 case 9: | 273 break; 274 case 9: |
| 274 CeedQFunctionCreateInterior(ceed, 1, Mass_9, Mass_9_loc, qf); | 275 PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Mass_9, Mass_9_loc, qf)); |
| 275 break; 276 case 22: | 276 break; 277 case 22: |
| 277 CeedQFunctionCreateInterior(ceed, 1, Mass_22, Mass_22_loc, qf); | 278 PetscCallCeed(ceed, CeedQFunctionCreateInterior(ceed, 1, Mass_22, Mass_22_loc, qf)); |
| 278 break; 279 default: 280 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP, "Could not find mass qfunction of size %d", N); 281 } 282 | 279 break; 280 default: 281 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_SUP, "Could not find mass qfunction of size %d", N); 282 } 283 |
| 283 CeedQFunctionAddInput(*qf, "u", N, CEED_EVAL_INTERP); 284 CeedQFunctionAddInput(*qf, "qdata", q_data_size, CEED_EVAL_NONE); 285 CeedQFunctionAddOutput(*qf, "v", N, CEED_EVAL_INTERP); | 284 PetscCallCeed(ceed, CeedQFunctionAddInput(*qf, "u", N, CEED_EVAL_INTERP)); 285 PetscCallCeed(ceed, CeedQFunctionAddInput(*qf, "qdata", q_data_size, CEED_EVAL_NONE)); 286 PetscCallCeed(ceed, CeedQFunctionAddOutput(*qf, "v", N, CEED_EVAL_INTERP)); |
| 286 PetscFunctionReturn(PETSC_SUCCESS); 287} 288 289PetscErrorCode NodalProjectionDataDestroy(NodalProjectionData context) { 290 PetscFunctionBeginUser; 291 if (context == NULL) PetscFunctionReturn(PETSC_SUCCESS); 292 293 PetscCall(DMDestroy(&context->dm)); --- 152 unchanged lines hidden (view full) --- 446 } 447 *array_petsc = NULL; 448 449 PetscFunctionReturn(PETSC_SUCCESS); 450} 451 452// Print information about the given simulation run 453PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData *problem, MPI_Comm comm) { | 287 PetscFunctionReturn(PETSC_SUCCESS); 288} 289 290PetscErrorCode NodalProjectionDataDestroy(NodalProjectionData context) { 291 PetscFunctionBeginUser; 292 if (context == NULL) PetscFunctionReturn(PETSC_SUCCESS); 293 294 PetscCall(DMDestroy(&context->dm)); --- 152 unchanged lines hidden (view full) --- 447 } 448 *array_petsc = NULL; 449 450 PetscFunctionReturn(PETSC_SUCCESS); 451} 452 453// Print information about the given simulation run 454PetscErrorCode PrintRunInfo(User user, Physics phys_ctx, ProblemData *problem, MPI_Comm comm) { |
| 455 Ceed ceed = user->ceed; |
|
| 454 PetscFunctionBeginUser; 455 // Header and rank 456 char host_name[PETSC_MAX_PATH_LEN]; 457 PetscMPIInt rank, comm_size; 458 PetscCall(PetscGetHostName(host_name, sizeof host_name)); 459 PetscCallMPI(MPI_Comm_rank(comm, &rank)); 460 PetscCallMPI(MPI_Comm_size(comm, &comm_size)); 461 PetscCall(PetscPrintf(comm, --- 4 unchanged lines hidden (view full) --- 466 host_name, comm_size)); 467 468 // Problem specific info 469 PetscCall(problem->print_info(user, problem, user->app_ctx)); 470 471 // libCEED 472 const char *used_resource; 473 CeedMemType mem_type_backend; | 456 PetscFunctionBeginUser; 457 // Header and rank 458 char host_name[PETSC_MAX_PATH_LEN]; 459 PetscMPIInt rank, comm_size; 460 PetscCall(PetscGetHostName(host_name, sizeof host_name)); 461 PetscCallMPI(MPI_Comm_rank(comm, &rank)); 462 PetscCallMPI(MPI_Comm_size(comm, &comm_size)); 463 PetscCall(PetscPrintf(comm, --- 4 unchanged lines hidden (view full) --- 468 host_name, comm_size)); 469 470 // Problem specific info 471 PetscCall(problem->print_info(user, problem, user->app_ctx)); 472 473 // libCEED 474 const char *used_resource; 475 CeedMemType mem_type_backend; |
| 474 CeedGetResource(user->ceed, &used_resource); 475 CeedGetPreferredMemType(user->ceed, &mem_type_backend); | 476 PetscCallCeed(ceed, CeedGetResource(user->ceed, &used_resource)); 477 PetscCallCeed(ceed, CeedGetPreferredMemType(user->ceed, &mem_type_backend)); |
| 476 PetscCall(PetscPrintf(comm, 477 " libCEED:\n" 478 " libCEED Backend : %s\n" 479 " libCEED Backend MemType : %s\n", 480 used_resource, CeedMemTypes[mem_type_backend])); 481 // PETSc 482 char box_faces_str[PETSC_MAX_PATH_LEN] = "3,3,3"; 483 if (problem->dim == 2) box_faces_str[3] = '\0'; --- 143 unchanged lines hidden --- | 478 PetscCall(PetscPrintf(comm, 479 " libCEED:\n" 480 " libCEED Backend : %s\n" 481 " libCEED Backend MemType : %s\n", 482 used_resource, CeedMemTypes[mem_type_backend])); 483 // PETSc 484 char box_faces_str[PETSC_MAX_PATH_LEN] = "3,3,3"; 485 if (problem->dim == 2) box_faces_str[3] = '\0'; --- 143 unchanged lines hidden --- |