Actual source code: meshPeriodic.c
1: #ifdef PETSC_RCS_HEADER
2: static char vcid[] = "$Id: meshPeriodic.c,v 1.00 2001/09/25 06:48:57 knepley Exp $";
3: #endif
5: /*
6: Defines the interface to functions on a periodic mesh
7: */
9: #include src/mesh/meshimpl.h
11: #undef __FUNCT__
13: /*@
14: MeshIsPeriodic - This function returns the periodicity of the mesh.
16: Not collective
18: Input Parameter:
19: . mesh - The mesh
21: Output Parameter:
22: . per - The flag for periodicity
24: Level: intermediate
26: .keywords: mesh, coordinates, periodic
27: .seealso: MeshIsPeriodicDimension(), MeshSetPeriodicDimension(), MeshPeriodicX(), MeshPeriodicRelativeX(), MeshPeriodicDiffX()
28: @*/
29: int MeshIsPeriodic(Mesh mesh, PetscTruth *per)
30: {
34: *per = mesh->isPeriodic;
35: return(0);
36: }
38: #undef __FUNCT__
40: /*@
41: MeshIsPeriodicDimension - This function returns the periodicity of a given dimension the mesh.
43: Not collective
45: Input Parameters:
46: + mesh - The mesh
47: - dir - The coordinate direction
49: Output Parameter:
50: . per - The flag for periodicity
52: Level: intermediate
54: .keywords: mesh, coordinates, periodic. dimension
55: .seealso: MeshIsPeriodic(), MeshSetPeriodicDimension(), MeshPeriodicX(), MeshPeriodicRelativeX(), MeshPeriodicDiffX()
56: @*/
57: int MeshIsPeriodicDimension(Mesh mesh, int dir, PetscTruth *per)
58: {
62: if ((dir < 0) || (dir >= mesh->dim)) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Direction %d does not appear in this mesh", dir)
63: *per = mesh->isPeriodicDim[dir];
64: return(0);
65: }
67: #undef __FUNCT__
69: /*@
70: MeshSetPeriodicDimension - This function sets the periodicity of a given dimension the mesh.
72: Not collective
74: Input Parameters:
75: + mesh - The mesh
76: . dir - The coordinate direction
77: - per - The flag for periodicity
79: Level: intermediate
81: .keywords: mesh, coordinates, periodic. dimension
82: .seealso: MeshIsPeriodic(), MeshIsPeriodicDimension(), MeshPeriodicX(), MeshPeriodicRelativeX(), MeshPeriodicDiffX()
83: @*/
84: int MeshSetPeriodicDimension(Mesh mesh, int dir, PetscTruth per)
85: {
86: int d;
90: if ((dir < 0) || (dir >= mesh->dim)) SETERRQ1(PETSC_ERR_ARG_OUTOFRANGE, "Direction %d does not appear in this mesh", dir)
91: mesh->isPeriodicDim[dir] = per;
92: for(mesh->isPeriodic = PETSC_FALSE, d = 0; d < mesh->dim; d++) {
93: if (mesh->isPeriodicDim[d] == PETSC_TRUE) mesh->isPeriodic = PETSC_TRUE;
94: }
95: return(0);
96: }
98: /* If optimized, these functions are replaced by macros in $PETSC_DIR/include/mesh.h */
99: #ifndef MESH_PERIODIC_OPTIMIZED
101: #undef __FUNCT__
103: /*@C
104: MeshPeriodicX - Returns the value modulo the period of the mesh.
106: Not collective
108: Input Parameters:
109: + mesh - The mesh
110: - x - The original coordinate
112: Output Parameter:
113: . ret - The normalized coordinate
115: Level: intermediate
117: .keywords: mesh, coordinates, periodic
118: .seealso: MeshPeriodicY(), MeshPeriodicZ(), MeshPeriodicRelativeX(), MeshPeriodicDiffX()
119: @*/
120: double MeshPeriodicX(Mesh mesh, double x)
121: {
124: if (mesh->isPeriodicDim[0] == PETSC_FALSE)
125: PetscFunctionReturn(x);
126: if (x - PETSC_MACHINE_EPSILON > mesh->endX) {
127: if (x - mesh->sizeX > mesh->endX) {
128: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than onen", x);
129: PetscFunctionReturn(0.0);
130: }
131: PetscFunctionReturn(x - mesh->sizeX);
132: } else if (x + PETSC_MACHINE_EPSILON < mesh->startX) {
133: if (x + mesh->sizeX < mesh->startX) {
134: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than onen", x);
135: PetscFunctionReturn(0.0);
136: }
137: PetscFunctionReturn(x + mesh->sizeX);
138: } else {
139: PetscFunctionReturn(x);
140: }
141: }
143: #undef __FUNCT__
145: /*@C
146: MeshPeriodicY - Returns the value modulo the period of the mesh.
148: Not collective
150: Input Parameters:
151: + mesh - The mesh
152: - y - The original coordinate
154: Output Parameter:
155: . ret - The normalized coordinate
157: Level: intermediate
159: .keywords: mesh, coordinates, periodic
160: .seealso: MeshPeriodicX(), MeshPeriodicZ(), MeshPeriodicRelativeY(), MeshPeriodicDiffY()
161: @*/
162: double MeshPeriodicY(Mesh mesh, double y)
163: {
166: if (mesh->isPeriodicDim[1] == PETSC_FALSE)
167: PetscFunctionReturn(y);
168: if (y - PETSC_MACHINE_EPSILON > mesh->endY) {
169: if (y - mesh->sizeY > mesh->endY) {
170: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than onen", y);
171: PetscFunctionReturn(0.0);
172: }
173: PetscFunctionReturn(y - mesh->sizeY);
174: } else if (y + PETSC_MACHINE_EPSILON < mesh->startY) {
175: if (y + mesh->sizeY < mesh->startY) {
176: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than onen", y);
177: PetscFunctionReturn(0.0);
178: }
179: PetscFunctionReturn(y + mesh->sizeY);
180: } else {
181: PetscFunctionReturn(y);
182: }
183: }
185: #undef __FUNCT__
187: /*@C
188: MeshPeriodicZ - Returns the value modulo the period of the mesh.
190: Not collective
192: Input Parameters:
193: + mesh - The mesh
194: - z - The original coordinate
196: Output Parameter:
197: . ret - The normalized coordinate
199: Level: intermediate
201: .keywords: mesh, coordinates, periodic
202: .seealso: MeshPeriodicX(), MeshPeriodicY(), MeshPeriodicRelativeZ(), MeshPeriodicDiffZ()
203: @*/
204: double MeshPeriodicZ(Mesh mesh, double z)
205: {
208: if (mesh->isPeriodicDim[2] == PETSC_FALSE)
209: PetscFunctionReturn(z);
210: if (z - PETSC_MACHINE_EPSILON > mesh->endZ) {
211: if (z - mesh->sizeZ > mesh->endZ) {
212: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than onen", z);
213: PetscFunctionReturn(0.0);
214: }
215: PetscFunctionReturn(z - mesh->sizeZ);
216: } else if (z + PETSC_MACHINE_EPSILON < mesh->startZ) {
217: if (z + mesh->sizeZ < mesh->startZ) {
218: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than onen", z);
219: PetscFunctionReturn(0.0);
220: }
221: PetscFunctionReturn(z + mesh->sizeZ);
222: } else {
223: PetscFunctionReturn(z);
224: }
225: }
227: #undef __FUNCT__
229: /*@C
230: MeshPeriodicRelativeX - Returns the value modulo the period of the mesh, relative
231: to a given coordinate.
233: Not collective
235: Input Parameters:
236: + mesh - The mesh
237: . x - The original coordinate
238: - xO - The origin defining the period
240: Output Parameter:
241: . ret - The normalized coordinate
243: Level: intermediate
245: Note:
246: This function is normally used to have a geometric object reside in a single
247: period of the mesh. For instance, a triangle that needs to be drawn.
249: .keywords: mesh, coordinates, periodic
250: .seealso: MeshPeriodicRelativeY(), MeshPeriodicRelativeZ(), MeshPeriodicX(), MeshPeriodicDiffX()
251: @*/
252: double MeshPeriodicRelativeX(Mesh mesh, double x, double xO)
253: {
256: if (mesh->isPeriodicDim[0] == PETSC_FALSE)
257: PetscFunctionReturn(x);
258: if (x - PETSC_MACHINE_EPSILON > xO + 0.5*mesh->sizeX) {
259: if (x - mesh->sizeX > xO + mesh->sizeX) {
260: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than one about %gn", x, xO);
261: PetscFunctionReturn(0.0);
262: }
263: PetscFunctionReturn(x - mesh->sizeX);
264: } else if (x + PETSC_MACHINE_EPSILON < xO - 0.5*mesh->sizeX) {
265: if (x + mesh->sizeX < xO - mesh->sizeX) {
266: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than one about %gn", x, xO);
267: PetscFunctionReturn(0.0);
268: }
269: PetscFunctionReturn(x + mesh->sizeX);
270: } else {
271: PetscFunctionReturn(x);
272: }
273: }
275: #undef __FUNCT__
277: /*@C
278: MeshPeriodicRelativeY - Returns the value modulo the period of the mesh, relative
279: to a given coordinate.
281: Not collective
283: Input Parameters:
284: + mesh - The mesh
285: . y - The original coordinate
286: - yO - The origin defining the period
288: Output Parameter:
289: . ret - The normalized coordinate
291: Level: intermediate
293: Note:
294: This function is normally used to have a geometric object reside in a single
295: period of the mesh. For instance, a triangle that needs to be drawn.
297: .keywords: mesh, coordinates, periodic
298: .seealso: MeshPeriodicRelativeX(), MeshPeriodicRelativeZ(), MeshPeriodicY(), MeshPeriodicDiffY()
299: @*/
300: double MeshPeriodicRelativeY(Mesh mesh, double y, double yO)
301: {
304: if (mesh->isPeriodicDim[1] == PETSC_FALSE)
305: PetscFunctionReturn(y);
306: if (y - PETSC_MACHINE_EPSILON > yO + 0.5*mesh->sizeY) {
307: if (y - mesh->sizeY > yO + mesh->sizeY) {
308: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than one about %gn", y, yO);
309: PetscFunctionReturn(0.0);
310: }
311: PetscFunctionReturn(y - mesh->sizeY);
312: } else if (y + PETSC_MACHINE_EPSILON < yO - 0.5*mesh->sizeY) {
313: if (y + mesh->sizeY < yO - mesh->sizeY) {
314: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than one about %gn", y, yO);
315: PetscFunctionReturn(0.0);
316: }
317: PetscFunctionReturn(y + mesh->sizeY);
318: } else {
319: PetscFunctionReturn(y);
320: }
321: }
323: #undef __FUNCT__
325: /*@C
326: MeshPeriodicRelativeZ - Returns the value modulo the period of the mesh, relative
327: to a given coordinate.
329: Not collective
331: Input Parameters:
332: + mesh - The mesh
333: . z - The original coordinate
334: - zO - The origin defining the period
336: Output Parameter:
337: . ret - The normalized coordinate
339: Level: intermediate
341: Note:
342: This function is normally used to have a geometric object reside in a single
343: period of the mesh. For instance, a triangle that needs to be drawn.
345: .keywords: mesh, coordinates, periodic
346: .seealso: MeshPeriodicRelativeX(), MeshPeriodicRelativeY(), MeshPeriodicZ(), MeshPeriodicDiffZ()
347: @*/
348: double MeshPeriodicRelativeZ(Mesh mesh, double z, double zO)
349: {
352: if (mesh->isPeriodicDim[2] == PETSC_FALSE)
353: PetscFunctionReturn(z);
354: if (z - PETSC_MACHINE_EPSILON > zO + 0.5*mesh->sizeZ) {
355: if (z - mesh->sizeZ > zO + mesh->sizeZ) {
356: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than one about %gn", z, zO);
357: PetscFunctionReturn(0.0);
358: }
359: PetscFunctionReturn(z - mesh->sizeZ);
360: } else if (z + PETSC_MACHINE_EPSILON < zO - 0.5*mesh->sizeZ) {
361: if (z + mesh->sizeZ < zO - mesh->sizeZ) {
362: PetscPrintf(PETSC_COMM_SELF, "ERROR: Coordinate %g has winding number greater than one about %gn", z, zO);
363: PetscFunctionReturn(0.0);
364: }
365: PetscFunctionReturn(z + mesh->sizeZ);
366: } else {
367: PetscFunctionReturn(z);
368: }
369: }
371: #undef __FUNCT__
373: /*@C
374: MeshPeriodicDiffX - Takes the difference of two x-coordinates in the domain, and returns
375: the value modulo the period of the mesh.
377: Not collective
379: Input Parameters:
380: + mesh - The mesh
381: - diff - The original difference
383: Output Parameter:
384: . ret - The normalized difference
386: Level: intermediate
388: .keywords: mesh, coordinates, periodic
389: .seealso: MeshPeriodicDiffY(), MeshPeriodicDiffZ(), MeshPeriodicX(), MeshPeriodicRelativeX()
390: @*/
391: double MeshPeriodicDiffX(Mesh mesh, double diff)
392: {
395: if (mesh->isPeriodicDim[0] == PETSC_FALSE)
396: PetscFunctionReturn(diff);
397: if (diff - PETSC_MACHINE_EPSILON > 0.5*mesh->sizeX) {
398: if (diff - mesh->sizeX > 0.5*mesh->sizeX) {
399: PetscPrintf(PETSC_COMM_SELF, "ERROR: Difference %g has winding number greater than onen", diff);
400: PetscFunctionReturn(0.0);
401: }
402: PetscFunctionReturn(diff - mesh->sizeX);
403: } else if (diff + PETSC_MACHINE_EPSILON < -0.5*mesh->sizeX) {
404: if (diff + mesh->sizeX < -0.5*mesh->sizeX) {
405: PetscPrintf(PETSC_COMM_SELF, "ERROR: Difference %g has winding number greater than onen", diff);
406: PetscFunctionReturn(0.0);
407: }
408: PetscFunctionReturn(diff + mesh->sizeX);
409: } else {
410: PetscFunctionReturn(diff);
411: }
412: }
414: #undef __FUNCT__
416: /*@C
417: MeshPeriodicDiffY - Takes the difference of two y-coordinates in the domain, and returns
418: the value modulo the period of the mesh.
420: Not collective
422: Input Parameters:
423: + mesh - The mesh
424: - diff - The original difference
426: Output Parameter:
427: . ret - The normalized difference
429: Level: intermediate
431: .keywords: mesh, coordinates, periodic
432: .seealso: MeshPeriodicDiffX(), MeshPeriodicDiffZ(), MeshPeriodicY(), MeshPeriodicRelativeY()
433: @*/
434: double MeshPeriodicDiffY(Mesh mesh, double diff)
435: {
438: if (mesh->isPeriodicDim[1] == PETSC_FALSE)
439: PetscFunctionReturn(diff);
440: if (diff - PETSC_MACHINE_EPSILON > 0.5*mesh->sizeY) {
441: if (diff - mesh->sizeY > 0.5*mesh->sizeY) {
442: PetscPrintf(PETSC_COMM_SELF, "ERROR: Difference %g has winding number greater than onen", diff);
443: PetscFunctionReturn(0.0);
444: }
445: PetscFunctionReturn(diff - mesh->sizeY);
446: } else if (diff + PETSC_MACHINE_EPSILON < -0.5*mesh->sizeY) {
447: if (diff + mesh->sizeY < -0.5*mesh->sizeY) {
448: PetscPrintf(PETSC_COMM_SELF, "ERROR: Difference %g has winding number greater than onen", diff);
449: PetscFunctionReturn(0.0);
450: }
451: PetscFunctionReturn(diff + mesh->sizeY);
452: } else {
453: PetscFunctionReturn(diff);
454: }
455: }
457: #undef __FUNCT__
459: /*@C
460: MeshPeriodicDiffZ - Takes the difference of two z-coordinates in the domain, and returns
461: the value modulo the period of the mesh.
463: Not collective
465: Input Parameters:
466: + mesh - The mesh
467: - diff - The original difference
469: Output Parameter:
470: . ret - The normalized difference
472: Level: intermediate
474: .keywords: mesh, coordinates, periodic
475: .seealso: MeshPeriodicDiffX(), MeshPeriodicDiffY(), MeshPeriodicZ(), MeshPeriodicRelativeZ()
476: @*/
477: double MeshPeriodicDiffZ(Mesh mesh, double diff)
478: {
481: if (mesh->isPeriodicDim[2] == PETSC_FALSE)
482: PetscFunctionReturn(diff);
483: if (diff - PETSC_MACHINE_EPSILON > 0.5*mesh->sizeZ) {
484: if (diff - mesh->sizeZ > 0.5*mesh->sizeZ) {
485: PetscPrintf(PETSC_COMM_SELF, "ERROR: Difference %g has winding number greater than onen", diff);
486: PetscFunctionReturn(0.0);
487: }
488: PetscFunctionReturn(diff - mesh->sizeZ);
489: } else if (diff + PETSC_MACHINE_EPSILON < -0.5*mesh->sizeZ) {
490: if (diff + mesh->sizeZ < -0.5*mesh->sizeZ) {
491: PetscPrintf(PETSC_COMM_SELF, "ERROR: Difference %g has winding number greater than onen", diff);
492: PetscFunctionReturn(0.0);
493: }
494: PetscFunctionReturn(diff + mesh->sizeZ);
495: } else {
496: PetscFunctionReturn(diff);
497: }
498: }
500: #endif /* MESH_PERIODIC_OPTIMIZED */