# PetIGA / test / Test_SNES_2D.c

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236``` ```#include "petiga.h" PetscScalar Peaks(PetscReal x, PetscReal y) { PetscReal X = x*3; PetscReal Y = y*3; return 3 * pow(1-X,2) * exp(-pow(X,2) - pow(Y+1,2)) /**/ - 10 * (X/5 - pow(X,3) - pow(Y,5)) * exp(-pow(X,2) - pow(Y,2)) /**/ - 1.0/3 * exp(-pow(X+1,2) - pow(Y,2)); } #undef __FUNCT__ #define __FUNCT__ "Function" PetscErrorCode Function(IGAPoint p,const PetscScalar *Ue,PetscScalar *Fe,void *ctx) { PetscInt nen=p->nen; PetscReal xy[2]; IGAPointFormPoint(p,xy); PetscReal x = xy[0]; PetscReal y = xy[1]; PetscScalar u0[4],u1[4][2]; IGAPointFormValue(p,Ue,&u0[0]); IGAPointFormGrad (p,Ue,&u1[0][0]); PetscScalar PETSC_UNUSED u = u0[0], u_x = u1[0][0], u_y = u1[0][1]; PetscScalar PETSC_UNUSED v = u0[1], v_x = u1[1][0], v_y = u1[1][1]; PetscScalar PETSC_UNUSED w = u0[2], w_x = u1[2][0], w_y = u1[2][1]; PetscScalar PETSC_UNUSED r = u0[3], r_x = u1[3][0], r_y = u1[3][1]; /*const PetscReal *N0, (*N1)[2]; IGAPointGetShapeFuns(p,0,(const PetscReal **)&N0); IGAPointGetShapeFuns(p,1,(const PetscReal **)&N1);*/ PetscReal N0[nen], N1[nen][2]; IGAPointFormShapeFuns(p,0,&N0[0]); IGAPointFormShapeFuns(p,1,&N1[0][0]); PetscInt a; for (a=0; anen; PetscScalar u0[4]; IGAPointFormValue(p,Ue,&u0[0]); PetscScalar PETSC_UNUSED r = u0[3]; const PetscReal *N0, (*N1)[2]; IGAPointGetShapeFuns(p,0,(const PetscReal **)&N0); IGAPointGetShapeFuns(p,1,(const PetscReal **)&N1); PetscInt a,b; for (a=0; anen; PetscScalar u0[4]; IGAPointFormValue(p,Ue,&u0[0]); PetscScalar r = u0[3]; PetscReal N0[nen],N2[nen][2][2]; IGAPointFormShapeFuns(p,0,&N0[0]); IGAPointFormShapeFuns(p,2,&N2[0][0][0]); PetscInt a; for (a=0; acollocation) { ierr = IGASetUserFunction(iga,Function,0);CHKERRQ(ierr); ierr = IGASetUserJacobian(iga,Jacobian,0);CHKERRQ(ierr); } else { ierr = IGASetUserFunction(iga,FunctionCollocation,0);CHKERRQ(ierr); ierr = IGASetUserJacobian(iga,JacobianCollocation,0);CHKERRQ(ierr); } Vec x; ierr = IGACreateVec(iga,&x);CHKERRQ(ierr); SNES snes; ierr = IGACreateSNES(iga,&snes);CHKERRQ(ierr); ierr = SNESSetFromOptions(snes);CHKERRQ(ierr); ierr = SNESSolve(snes,0,x);CHKERRQ(ierr); ierr = VecView(x,PETSC_VIEWER_DRAW_WORLD);CHKERRQ(ierr); ierr = VecDestroy(&x);CHKERRQ(ierr); ierr = SNESDestroy(&snes);CHKERRQ(ierr); ierr = IGADestroy(&iga);CHKERRQ(ierr); ierr = PetscFinalize();CHKERRQ(ierr); return 0; } ```
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.