LOCAL_C void MoveFields() { test.Next(_L("Field moving")); // CContactDatabase* db=CntTest->OpenDatabaseL(); // CContactCard* card=CContactCard::NewL(); CleanupStack::PushL(card); TContactItemId testId=db->AddNewContactL(*card); CleanupStack::PopAndDestroy(); // card // CContactItem* item=db->OpenContactL(testId); CleanupStack::PushL(item); for (TInt loop=0;loop<4;loop++) { CContactItemField* field=CContactItemField::NewLC(KStorageTypeText); TBuf<32> text; text.Format(KCardFieldText,123,loop); field->TextStorage()->SetTextL(text); item->AddFieldL(*field); CleanupStack::Pop(); // field } db->CommitContactL(*item); // CContactItemFieldSet& fields=item->CardFields(); fields.Move(0,1); TestFields(fields,1,0,2,3); fields.Move(0,3); TestFields(fields,0,2,3,1); fields.Move(0,2); TestFields(fields,2,3,0,1); fields.Move(1,3); TestFields(fields,2,0,1,3); fields.Move(2,3); TestFields(fields,2,0,3,1); fields.Move(1,2); TestFields(fields,2,3,0,1); // CleanupStack::PopAndDestroy(); // item CntTest->CloseDatabase(); }
int main(int argc,char **argv) { PetscErrorCode ierr; DM dmstag; PetscInt dim; PetscBool setSizes; /* Initialize PETSc and process command line arguments */ ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr; dim = 2; ierr = PetscOptionsGetInt(NULL,NULL,"-dim",&dim,NULL);CHKERRQ(ierr); setSizes = PETSC_FALSE; ierr = PetscOptionsGetBool(NULL,NULL,"-setsizes",&setSizes,NULL);CHKERRQ(ierr); /* Creation (normal) */ if (!setSizes) { switch (dim) { case 1: ierr = DMStagCreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,3,1,1,DMSTAG_STENCIL_BOX,1,NULL,&dmstag);CHKERRQ(ierr); break; case 2: ierr = DMStagCreate2d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,3,2,PETSC_DECIDE,PETSC_DECIDE,1,1,1,DMSTAG_STENCIL_BOX,1,NULL,NULL,&dmstag);CHKERRQ(ierr); break; case 3: ierr = DMStagCreate3d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,3,2,4,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,1,1,1,1,DMSTAG_STENCIL_BOX,1,NULL,NULL,NULL,&dmstag);CHKERRQ(ierr); break; default: SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_SUP,"No support for dimension %D",dim); } } else { /* Creation (test providing decomp exactly)*/ PetscMPIInt size; PetscInt lx[4] = {1,2,3}, ranksx = 3, mx = 6; PetscInt ly[3] = {4,5}, ranksy = 2, my = 9; PetscInt lz[2] = {6,7}, ranksz = 2, mz = 13; ierr = MPI_Comm_size(PETSC_COMM_WORLD,&size);CHKERRQ(ierr); switch (dim) { case 1: if (size != ranksx) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Must run on %D ranks with -dim 1 -setSizes",ranksx); ierr = DMStagCreate1d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,mx,1,1,DMSTAG_STENCIL_BOX,1,lx,&dmstag);CHKERRQ(ierr); break; case 2: if (size != ranksx * ranksy) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Must run on %D ranks with -dim 2 -setSizes",ranksx * ranksy); ierr = DMStagCreate2d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,mx,my,ranksx,ranksy,1,1,1,DMSTAG_STENCIL_BOX,1,lx,ly,&dmstag);CHKERRQ(ierr); break; case 3: if (size != ranksx * ranksy * ranksz) SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_ARG_WRONG,"Must run on %D ranks with -dim 3 -setSizes", ranksx * ranksy * ranksz); ierr = DMStagCreate3d(PETSC_COMM_WORLD,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,DM_BOUNDARY_NONE,mx,my,mz,ranksx,ranksy,ranksz,1,1,1,1,DMSTAG_STENCIL_BOX,1,lx,ly,lz,&dmstag);CHKERRQ(ierr); break; default: SETERRQ1(PETSC_COMM_WORLD,PETSC_ERR_SUP,"No support for dimension %D",dim); } } /* Setup */ ierr = DMSetFromOptions(dmstag);CHKERRQ(ierr); ierr = DMSetUp(dmstag);CHKERRQ(ierr); /* Field Creation */ ierr = TestFields(dmstag);CHKERRQ(ierr); /* Clean up and finalize PETSc */ ierr = DMDestroy(&dmstag);CHKERRQ(ierr); ierr = PetscFinalize(); return ierr; }