On Sun, Jun 17, 2012 at 7:26 AM, TAY wee-beng <zonexo at gmail.com> wrote:
> > On 16/6/2012 9:24 AM, Jed Brown wrote: > > It depends how you want to solve the problem. I usually group all dofs > together. There is a 2D Stokes+Thermodynamics example in SNES ex30 (or 31?). > > > I tried to understand ex30. I have some questions since it's in C and I'm > using to Fortran programming. > This looks about right, see src/dm/examples/tutorials/ex11f90.F. > > Supposed I have a field - u,v,w,p, so in order to use them, I do the > following: > * > type field > > real u,v,w,p > > end type field > > type(field), pointer :: field1(:,:,:) -> make a derived variable* > > Also: > * > Vec field_local,field_global > > call DMDACreate3d with dof = 4 > > call DMCreateGlobalVector(da, field_local,ierr) > > call DMCreateLocalVector(da,field_global,ierr) > > call DMGetLocalVector(da, field_local,ierr) -> To insert values > > call DMDAVecGetArrayF90(da, field_local,field1,ierr) > > do k = zs, zs + zm - 1 > > do j = ys, ys + ym -1 > > do i = xs, xs + xm - 1 > > field1(i,j,k)%u = ... -> evaluate u,v,w,p etc > > end do > > end do > > call DMDAVecRestoreArrayF90(da,field_local,field1,ierr) > > call DMLocalToGlobalBegin(da,field_local,INSERT_VALUES,field_global,ierr) > > call DMLocalToGlobalEnd(da,field_local,INSERT_VALUES,field_global,ierr) > > call DMRestoreLocalVector(da,field_local,ierr)* > > Is this the correct way? > > Also, supposed I now want to solve my u,v,w momentum eqns. Although > they're not coupled together, I believe it's faster if I assemble them into > 1 big matrix. > > So for Ax = b, x = > (field(1,1,1)%u,field(1,1,1)%v,field(1,1,1)%w,field(2,1,1)%u.... ) > > For b, do I duplicate a Vec similar to field_local? > > What about matrix A? Do I use the MatSetValuesStencil? > Yes > > Lastly, the type field contains u,v,w and p. However, I'm only solving > u,v,w. Do I have to skip some values or use identity matrix to solve it? > Why not make a field that contains only u,v,w. I don't see what you're trying to do. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20120617/60503287/attachment.html>
