| multigrid.c (a171b6ef1192a8f5f3031330339aaab2ded4c8fb) | multigrid.c (4d00b080eb3f95d2e04e55c0ff369c5c847bb288) |
|---|---|
| 1// Copyright (c) 2017-2024, 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// libCEED + PETSc Example: CEED BPs 3-6 with Multigrid --- 220 unchanged lines hidden (view full) --- 229 PetscCall(PetscPrintf(comm, 230 "\n-- CEED Benchmark Problem %" CeedInt_FMT " -- libCEED + PETSc + PCMG --\n" 231 " PETSc:\n" 232 " PETSc Vec Type : %s\n" 233 " libCEED:\n" 234 " libCEED Backend : %s\n" 235 " libCEED Backend MemType : %s\n" 236 " Mesh:\n" | 1// Copyright (c) 2017-2024, 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// libCEED + PETSc Example: CEED BPs 3-6 with Multigrid --- 220 unchanged lines hidden (view full) --- 229 PetscCall(PetscPrintf(comm, 230 "\n-- CEED Benchmark Problem %" CeedInt_FMT " -- libCEED + PETSc + PCMG --\n" 231 " PETSc:\n" 232 " PETSc Vec Type : %s\n" 233 " libCEED:\n" 234 " libCEED Backend : %s\n" 235 " libCEED Backend MemType : %s\n" 236 " Mesh:\n" |
| 237 " Solution Order (P) : %" CeedInt_FMT "\n" 238 " Quadrature Order (Q) : %" CeedInt_FMT "\n" 239 " Additional quadrature points (q_extra) : %" CeedInt_FMT "\n" | 237 " Solution Order (P) : %" PetscInt_FMT "\n" 238 " Quadrature Order (Q) : %" PetscInt_FMT "\n" 239 " Additional quadrature points (q_extra) : %" PetscInt_FMT "\n" |
| 240 " Global Nodes : %" PetscInt_FMT "\n" 241 " Owned Nodes : %" PetscInt_FMT "\n" 242 " DoF per node : %" PetscInt_FMT "\n" 243 " Element topology : %s\n" 244 " Multigrid:\n" | 240 " Global Nodes : %" PetscInt_FMT "\n" 241 " Owned Nodes : %" PetscInt_FMT "\n" 242 " DoF per node : %" PetscInt_FMT "\n" 243 " Element topology : %s\n" 244 " Multigrid:\n" |
| 245 " Number of Levels : %" CeedInt_FMT "\n", | 245 " Number of Levels : %" PetscInt_FMT "\n", |
| 246 bp_choice + 1, vec_type, used_resource, CeedMemTypes[mem_type_backend], P, Q, q_extra, g_size[fine_level] / num_comp_u, 247 l_size[fine_level] / num_comp_u, num_comp_u, CeedElemTopologies[elem_topo], num_levels)); 248 } 249 250 // Create RHS vector 251 PetscCall(VecDuplicate(X_loc[fine_level], &rhs_loc)); 252 PetscCall(VecZeroEntries(rhs_loc)); 253 CeedVectorCreate(ceed, xl_size[fine_level], &rhs_ceed); 254 PetscCall(VecP2C(rhs_loc, &mem_type, rhs_ceed)); 255 256 // Set up libCEED operators on each level 257 PetscCall(PetscMalloc1(num_levels, &ceed_data)); 258 for (PetscInt i = 0; i < num_levels; i++) { 259 // Print level information 260 if (!test_mode && (i == 0 || i == fine_level)) { 261 PetscCall(PetscPrintf(comm, 262 " Level %" PetscInt_FMT " (%s):\n" | 246 bp_choice + 1, vec_type, used_resource, CeedMemTypes[mem_type_backend], P, Q, q_extra, g_size[fine_level] / num_comp_u, 247 l_size[fine_level] / num_comp_u, num_comp_u, CeedElemTopologies[elem_topo], num_levels)); 248 } 249 250 // Create RHS vector 251 PetscCall(VecDuplicate(X_loc[fine_level], &rhs_loc)); 252 PetscCall(VecZeroEntries(rhs_loc)); 253 CeedVectorCreate(ceed, xl_size[fine_level], &rhs_ceed); 254 PetscCall(VecP2C(rhs_loc, &mem_type, rhs_ceed)); 255 256 // Set up libCEED operators on each level 257 PetscCall(PetscMalloc1(num_levels, &ceed_data)); 258 for (PetscInt i = 0; i < num_levels; i++) { 259 // Print level information 260 if (!test_mode && (i == 0 || i == fine_level)) { 261 PetscCall(PetscPrintf(comm, 262 " Level %" PetscInt_FMT " (%s):\n" |
| 263 " Solution Order (P) : %" CeedInt_FMT "\n" | 263 " Solution Order (P) : %" PetscInt_FMT "\n" |
| 264 " Global Nodes : %" PetscInt_FMT "\n" 265 " Owned Nodes : %" PetscInt_FMT "\n", 266 i, (i ? "fine" : "coarse"), level_degrees[i] + 1, g_size[i] / num_comp_u, l_size[i] / num_comp_u)); 267 } 268 PetscCall(PetscMalloc1(1, &ceed_data[i])); 269 PetscCall(SetupLibceedByDegree(dm[i], ceed, level_degrees[i], dim, q_extra, dim, num_comp_u, g_size[i], xl_size[i], bp_options[bp_choice], 270 ceed_data[i], i == (fine_level), rhs_ceed, &target)); 271 } --- 72 unchanged lines hidden (view full) --- 344 } 345 346 // Assemble coarse grid Jacobian for AMG (or other sparse matrix) solve 347 PetscCall(DMCreateMatrix(dm[0], &mat_coarse)); 348 349 PetscCall(PetscLogEventRegister("AssembleMatrix", MAT_CLASSID, &assemble_event)); 350 { 351 // Assemble matrix analytically | 264 " Global Nodes : %" PetscInt_FMT "\n" 265 " Owned Nodes : %" PetscInt_FMT "\n", 266 i, (i ? "fine" : "coarse"), level_degrees[i] + 1, g_size[i] / num_comp_u, l_size[i] / num_comp_u)); 267 } 268 PetscCall(PetscMalloc1(1, &ceed_data[i])); 269 PetscCall(SetupLibceedByDegree(dm[i], ceed, level_degrees[i], dim, q_extra, dim, num_comp_u, g_size[i], xl_size[i], bp_options[bp_choice], 270 ceed_data[i], i == (fine_level), rhs_ceed, &target)); 271 } --- 72 unchanged lines hidden (view full) --- 344 } 345 346 // Assemble coarse grid Jacobian for AMG (or other sparse matrix) solve 347 PetscCall(DMCreateMatrix(dm[0], &mat_coarse)); 348 349 PetscCall(PetscLogEventRegister("AssembleMatrix", MAT_CLASSID, &assemble_event)); 350 { 351 // Assemble matrix analytically |
| 352 PetscCount num_entries; 353 CeedInt *rows, *cols; 354 CeedVector coo_values; 355 CeedOperatorLinearAssembleSymbolic(op_apply_ctx[0]->op, &num_entries, &rows, &cols); | 352 PetscCount num_entries; 353 CeedInt *rows_ceed, *cols_ceed; 354 PetscInt *rows_petsc, *cols_petsc; |
| 356 ISLocalToGlobalMapping ltog_row, ltog_col; | 355 ISLocalToGlobalMapping ltog_row, ltog_col; |
| 356 CeedVector coo_values; 357 358 CeedOperatorLinearAssembleSymbolic(op_apply_ctx[0]->op, &num_entries, &rows_ceed, &cols_ceed); 359 PetscCall(IntArrayCeedToPetsc(num_entries, &rows_ceed, &rows_petsc)); 360 PetscCall(IntArrayCeedToPetsc(num_entries, &cols_ceed, &cols_petsc)); |
|
| 357 PetscCall(MatGetLocalToGlobalMapping(mat_coarse, <og_row, <og_col)); | 361 PetscCall(MatGetLocalToGlobalMapping(mat_coarse, <og_row, <og_col)); |
| 358 PetscCall(ISLocalToGlobalMappingApply(ltog_row, num_entries, rows, rows)); 359 PetscCall(ISLocalToGlobalMappingApply(ltog_col, num_entries, cols, cols)); 360 PetscCall(MatSetPreallocationCOO(mat_coarse, num_entries, rows, cols)); 361 free(rows); 362 free(cols); | 362 PetscCall(ISLocalToGlobalMappingApply(ltog_row, num_entries, rows_petsc, rows_petsc)); 363 PetscCall(ISLocalToGlobalMappingApply(ltog_col, num_entries, cols_petsc, cols_petsc)); 364 PetscCall(MatSetPreallocationCOO(mat_coarse, num_entries, rows_petsc, cols_petsc)); 365 free(rows_petsc); 366 free(cols_petsc); |
| 363 CeedVectorCreate(ceed, num_entries, &coo_values); 364 PetscCall(PetscLogEventBegin(assemble_event, mat_coarse, 0, 0, 0)); 365 CeedOperatorLinearAssemble(op_apply_ctx[0]->op, coo_values); 366 const CeedScalar *values; 367 CeedVectorGetArrayRead(coo_values, CEED_MEM_HOST, &values); 368 PetscCall(MatSetValuesCOO(mat_coarse, values, ADD_VALUES)); 369 CeedVectorRestoreArrayRead(coo_values, &values); 370 PetscCall(PetscLogEventEnd(assemble_event, mat_coarse, 0, 0, 0)); --- 200 unchanged lines hidden --- | 367 CeedVectorCreate(ceed, num_entries, &coo_values); 368 PetscCall(PetscLogEventBegin(assemble_event, mat_coarse, 0, 0, 0)); 369 CeedOperatorLinearAssemble(op_apply_ctx[0]->op, coo_values); 370 const CeedScalar *values; 371 CeedVectorGetArrayRead(coo_values, CEED_MEM_HOST, &values); 372 PetscCall(MatSetValuesCOO(mat_coarse, values, ADD_VALUES)); 373 CeedVectorRestoreArrayRead(coo_values, &values); 374 PetscCall(PetscLogEventEnd(assemble_event, mat_coarse, 0, 0, 0)); --- 200 unchanged lines hidden --- |