From 1f86111f57513fc00714bae219d359464a1965bd Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Wed, 19 Jan 2022 22:57:22 +0100 Subject: [PATCH] call SNESSetDM after DMDASNESSetFunctionLocal following example ex5f.F90, seems to resolve segmentation fault --- src/grid/grid_damage_spectral.f90 | 2 +- src/grid/grid_mech_FEM.f90 | 4 ++-- src/grid/grid_mech_spectral_basic.f90 | 2 +- src/grid/grid_mech_spectral_polarisation.f90 | 2 +- src/grid/grid_thermal_spectral.f90 | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/grid/grid_damage_spectral.f90 b/src/grid/grid_damage_spectral.f90 index 5c4f357eb..9ed1dd051 100644 --- a/src/grid/grid_damage_spectral.f90 +++ b/src/grid/grid_damage_spectral.f90 @@ -127,12 +127,12 @@ subroutine grid_damage_spectral_init() [int(grid(1),pPetscInt)],[int(grid(2),pPetscInt)],localK, & ! local grid damage_grid,err_PETSc) ! handle, error CHKERRQ(err_PETSc) - call SNESSetDM(SNES_damage,damage_grid,err_PETSc); CHKERRQ(err_PETSc) ! connect snes to da call DMsetFromOptions(damage_grid,err_PETSc); CHKERRQ(err_PETSc) call DMsetUp(damage_grid,err_PETSc); CHKERRQ(err_PETSc) call DMCreateGlobalVector(damage_grid,solution_vec,err_PETSc); CHKERRQ(err_PETSc) ! global solution vector (grid x 1, i.e. every def grad tensor) call DMDASNESSetFunctionLocal(damage_grid,INSERT_VALUES,formResidual,PETSC_NULL_SNES,err_PETSc) ! residual vector of same shape as solution vector CHKERRQ(err_PETSc) + call SNESSetDM(SNES_damage,damage_grid,err_PETSc); CHKERRQ(err_PETSc) ! connect snes to da call SNESSetFromOptions(SNES_damage,err_PETSc); CHKERRQ(err_PETSc) ! pull it all together with additional CLI arguments call SNESGetType(SNES_damage,snes_type,err_PETSc); CHKERRQ(err_PETSc) if (trim(snes_type) == 'vinewtonrsls' .or. & diff --git a/src/grid/grid_mech_FEM.f90 b/src/grid/grid_mech_FEM.f90 index 681de0860..ed0d01810 100644 --- a/src/grid/grid_mech_FEM.f90 +++ b/src/grid/grid_mech_FEM.f90 @@ -176,8 +176,6 @@ subroutine grid_mechanical_FEM_init [int(grid(1),pPetscInt)],[int(grid(2),pPetscInt)],localK, & ! local grid mechanical_grid,err_PETSc) CHKERRQ(err_PETSc) - call SNESSetDM(mechanical_snes,mechanical_grid,err_PETSc) - CHKERRQ(err_PETSc) call DMsetFromOptions(mechanical_grid,err_PETSc) CHKERRQ(err_PETSc) call DMsetUp(mechanical_grid,err_PETSc) @@ -198,6 +196,8 @@ subroutine grid_mechanical_FEM_init CHKERRQ(err_PETSc) call SNESSetMaxLinearSolveFailures(mechanical_snes, huge(1_pPetscInt), err_PETSc) ! ignore linear solve failures CHKERRQ(err_PETSc) + call SNESSetDM(mechanical_snes,mechanical_grid,err_PETSc) + CHKERRQ(err_PETSc) call SNESSetFromOptions(mechanical_snes,err_PETSc) ! pull it all together with additional cli arguments CHKERRQ(err_PETSc) diff --git a/src/grid/grid_mech_spectral_basic.f90 b/src/grid/grid_mech_spectral_basic.f90 index 74400f160..56c619b7e 100644 --- a/src/grid/grid_mech_spectral_basic.f90 +++ b/src/grid/grid_mech_spectral_basic.f90 @@ -173,7 +173,6 @@ subroutine grid_mechanical_spectral_basic_init [int(grid(1),pPetscInt)],[int(grid(2),pPetscInt)],localK, & ! local grid da,err_PETSc) ! handle, error CHKERRQ(err_PETSc) - call SNESSetDM(snes,da,err_PETSc); CHKERRQ(err_PETSc) ! connect snes to da call DMsetFromOptions(da,err_PETSc); CHKERRQ(err_PETSc) call DMsetUp(da,err_PETSc); CHKERRQ(err_PETSc) call DMcreateGlobalVector(da,solution_vec,err_PETSc); CHKERRQ(err_PETSc) ! global solution vector (grid x 9, i.e. every def grad tensor) @@ -181,6 +180,7 @@ subroutine grid_mechanical_spectral_basic_init CHKERRQ(err_PETSc) call SNESsetConvergenceTest(snes,converged,PETSC_NULL_SNES,PETSC_NULL_FUNCTION,err_PETSc) ! specify custom convergence check function "converged" CHKERRQ(err_PETSc) + call SNESSetDM(snes,da,err_PETSc); CHKERRQ(err_PETSc) ! connect snes to da call SNESsetFromOptions(snes,err_PETSc); CHKERRQ(err_PETSc) ! pull it all together with additional CLI arguments !-------------------------------------------------------------------------------------------------- diff --git a/src/grid/grid_mech_spectral_polarisation.f90 b/src/grid/grid_mech_spectral_polarisation.f90 index 765a1a5a7..ccd26f451 100644 --- a/src/grid/grid_mech_spectral_polarisation.f90 +++ b/src/grid/grid_mech_spectral_polarisation.f90 @@ -193,7 +193,6 @@ subroutine grid_mechanical_spectral_polarisation_init [int(grid(1),pPetscInt)],[int(grid(2),pPetscInt)],localK, & ! local grid da,err_PETSc) ! handle, error CHKERRQ(err_PETSc) - call SNESSetDM(snes,da,err_PETSc); CHKERRQ(err_PETSc) ! connect snes to da call DMsetFromOptions(da,err_PETSc); CHKERRQ(err_PETSc) call DMsetUp(da,err_PETSc); CHKERRQ(err_PETSc) call DMcreateGlobalVector(da,solution_vec,err_PETSc); CHKERRQ(err_PETSc) ! global solution vector (grid x 18, i.e. every def grad tensor) @@ -201,6 +200,7 @@ subroutine grid_mechanical_spectral_polarisation_init CHKERRQ(err_PETSc) call SNESsetConvergenceTest(snes,converged,PETSC_NULL_SNES,PETSC_NULL_FUNCTION,err_PETSc) ! specify custom convergence check function "converged" CHKERRQ(err_PETSc) + call SNESSetDM(snes,da,err_PETSc); CHKERRQ(err_PETSc) ! connect snes to da call SNESsetFromOptions(snes,err_PETSc); CHKERRQ(err_PETSc) ! pull it all together with additional CLI arguments !-------------------------------------------------------------------------------------------------- diff --git a/src/grid/grid_thermal_spectral.f90 b/src/grid/grid_thermal_spectral.f90 index 86acf7c30..ea32f3b68 100644 --- a/src/grid/grid_thermal_spectral.f90 +++ b/src/grid/grid_thermal_spectral.f90 @@ -128,13 +128,13 @@ subroutine grid_thermal_spectral_init(T_0) [int(grid(1),pPetscInt)],[int(grid(2),pPetscInt)],localK, & ! local grid thermal_grid,err_PETSc) ! handle, error CHKERRQ(err_PETSc) - call SNESSetDM(SNES_thermal,thermal_grid,err_PETSc); CHKERRQ(err_PETSc) ! connect snes to da call DMsetFromOptions(thermal_grid,err_PETSc); CHKERRQ(err_PETSc) call DMsetUp(thermal_grid,err_PETSc); CHKERRQ(err_PETSc) call DMCreateGlobalVector(thermal_grid,solution_vec,err_PETSc) ! global solution vector (grid x 1, i.e. every def grad tensor) CHKERRQ(err_PETSc) call DMDASNESSetFunctionLocal(thermal_grid,INSERT_VALUES,formResidual,PETSC_NULL_SNES,err_PETSc) ! residual vector of same shape as solution vector CHKERRQ(err_PETSc) + call SNESSetDM(SNES_thermal,thermal_grid,err_PETSc); CHKERRQ(err_PETSc) ! connect snes to da call SNESSetFromOptions(SNES_thermal,err_PETSc); CHKERRQ(err_PETSc) ! pull it all together with additional CLI arguments !--------------------------------------------------------------------------------------------------