<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Dear PETSc team,<div class=""><br class=""></div><div class="">I am working on a code which solves mechanical equilibrium using spectral methods.</div><div class="">I want to make use of the matshell to get the action J*v.</div><div class=""><br class=""></div><div class="">I have been able to successfully implement it using petsc4py. But having difficulties to get it working in a fortran code.</div><div class="">I am using petsc-3.7.6. </div><div class=""><br class=""></div><div class="">Below is a stripped down version of the existing fortran code (module). Can you please help me in figuring out how the right way to do it a code with following structure?</div><div class=""><br class=""></div><div class=""><div class="">!--------------------------------------------------------------------------------------------------</div></div><div class=""><div class="">module spectral_mech_basic</div><div class=""><br class=""></div><div class=""> implicit none</div><div class=""> private</div><div class="">#include <petsc/finclude/petsc.h90></div><div class=""><br class=""></div><div class="">! *PETSc data here*</div><div class=""> DM ..</div><div class=""> SNES ..</div><div class=""> ..</div><div class="">contains</div><div class=""><br class=""></div><div class="">!--------------------------------------------------------------------------------------------------</div><div class="">subroutine basicPETSc_init</div><div class=""><br class=""></div><div class=""> external :: &</div><div class=""> *petsc functions here*</div><div class=""><br class=""></div><div class="">! initialize solver specific parts of PETSc</div><div class=""> call SNESCreate(PETSC_COMM_WORLD,snes,ierr); CHKERRQ(ierr)</div><div class=""> call SNESSetOptionsPrefix(snes,'mech_',ierr);CHKERRQ(ierr) </div><div class=""> call DMDACreate3d(PETSC_COMM_WORLD, &</div><div class=""> DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, DM_BOUNDARY_NONE, & </div><div class=""> DMDA_STENCIL_BOX, & </div><div class=""> grid(1),grid(2),grid(3), & </div><div class=""> 1 , 1, worldsize, &</div><div class=""> 9, 0, & </div><div class=""> grid(1),grid(2),localK, & </div><div class=""> da,ierr) </div><div class=""> CHKERRQ(ierr)</div><div class=""> call SNESSetDM(snes,da,ierr); CHKERRQ(ierr)</div><div class=""> call DMCreateGlobalVector(da,solution_vec,ierr); CHKERRQ(ierr) </div><div class=""> call DMDASNESSetFunctionLocal(da,INSERT_VALUES,BasicPETSC_formResidual,PETSC_NULL_OBJECT,ierr) </div><div class=""> CHKERRQ(ierr) </div><div class=""> call SNESSetDM(snes,da,ierr); CHKERRQ(ierr) </div><div class=""> call SNESGetKSP(snes,ksp,ierr); CHKERRQ(ierr) </div><div class=""> call KSPGetPC(ksp,pc,ierr); CHKERRQ(ierr) </div><div class=""> call PCSetType(pc,PCNONE,ierr); CHKERRQ(ierr) </div><div class=""> call SNESSetFromOptions(snes,ierr); CHKERRQ(ierr) </div><div class=""><br class=""></div><div class="">! init fields </div><div class=""> call DMDAVecGetArrayF90(da,solution_vec,F,ierr); CHKERRQ(ierr) </div><div class=""> call DMDAVecRestoreArrayF90(da,solution_vec,F,ierr); CHKERRQ(ierr) </div><div class=""><br class=""></div><div class="">end subroutine basicPETSc_init</div><div class="">!--------------------------------------------------------------------------------------------------</div><div class=""><br class=""></div><div class="">type(tSolutionState) function &</div><div class=""> basicPETSc_solution(incInfoIn,timeinc,timeinc_old,stress_BC,rotation_BC)</div><div class=""> implicit none</div><div class="">! PETSc Data</div><div class=""> PetscErrorCode :: ierr </div><div class=""> SNESConvergedReason :: reason</div><div class=""> external :: &</div><div class=""> SNESSolve, &</div><div class="">! solve BVP </div><div class=""><span style="font-size: 14px;" class=""> call SNESSolve(snes,PETSC_NULL_OBJECT,solution_vec,ierr)</span></div><div class=""> CHKERRQ(ierr)</div><div class="">end function BasicPETSc_solution</div><div class="">!--------------------------------------------------------------------------------------------------</div><div class="">!> @brief forms the basic residual vector</div><div class="">!--------------------------------------------------------------------------------------------------</div><div class="">subroutine BasicPETSC_formResidual(in,x_scal,f_scal,dummy,ierr)</div><div class=""><br class=""></div><div class=""> implicit none</div><div class=""> DMDALocalInfo, dimension(DMDA_LOCAL_INFO_SIZE) :: &</div><div class=""> in</div><div class=""> PetscScalar, dimension(3,3, &</div><div class=""> XG_RANGE,YG_RANGE,ZG_RANGE), intent(in) :: &</div><div class=""> x_scal</div><div class=""> PetscScalar, dimension(3,3, &</div><div class=""> X_RANGE,Y_RANGE,Z_RANGE), intent(out) :: &</div><div class=""> f_scal</div><div class="">! constructing residual</div><div class="">…..</div><div class="">….</div><div class=""><br class=""></div><div class=""> f_scal = tensorField_real(1:3,1:3,1:grid(1),1:grid(2),1:grid3)</div><div class=""><br class=""></div><div class="">end subroutine BasicPETSc_formResidual</div><div class="">!--------------------------------------------------------------------------------------------------</div><div class=""><br class=""></div><div class="">end module spectral_mech_basic</div></div><div class="">!--------------------------------------------------------------------------------------------------</div><div class=""><br class=""></div></div><div class="">Best regards,</div><div class="">Luv</div><br class=""><div><blockquote type="cite" class=""><div class="">On 3 Nov 2016, at 01:17, Barry Smith <<a href="mailto:bsmith@mcs.anl.gov" class="">bsmith@mcs.anl.gov</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class=""> Is anyone away of cases where PETSc has been used with spectral methods?<br class=""><br class=""> Thanks<br class=""><br class=""> Barry<br class=""><br class=""></div></blockquote></div></body></html>