File: patch.util.c

package info (click to toggle)
ga 5.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,472 kB
  • sloc: ansic: 192,963; fortran: 53,761; f90: 11,218; cpp: 5,784; makefile: 2,248; sh: 1,945; python: 1,734; perl: 534; csh: 134; asm: 106
file content (107 lines) | stat: -rw-r--r-- 3,235 bytes parent folder | download | duplicates (10)
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
#if HAVE_CONFIG_H
#   include "config.h"
#endif

/** @file
 * operations on sections of 2D arrays
 */

#include "global.h"       /* used only to define datatypes */
#include "drap.h"

#define PARIO_MAX(a,b) (((a) >= (b)) ? (a) : (b))
#define PARIO_MIN(a,b) (((a) <= (b)) ? (a) : (b))


/**
 * check if two patches are conforming (dimensions are divisible)
 */
logical dai_patches_conforming(
        Integer* ailo, Integer* aihi, Integer* ajlo, Integer* ajhi, 
        Integer* bilo, Integer* bihi, Integer* bjlo, Integer* bjhi)
{
    Integer mismatch;
    Integer adim1, bdim1, adim2, bdim2;
    adim1 = *aihi - *ailo +1;
    adim2 = *ajhi - *ajlo +1;
    bdim1 = *bihi - *bilo +1;
    bdim2 = *bjhi - *bjlo +1;
    mismatch  = (adim1<bdim1) ? bdim1%adim1 : adim1%bdim1;
    mismatch += (adim2<bdim2) ? bdim2%adim2 : adim2%bdim2;
    if(mismatch)return(FALSE);
    else return(TRUE);
}


/**
 * check if patches are identical
 */
logical dai_comp_patch(
        Integer* ilo, Integer* ihi, Integer* jlo, Integer* jhi, 
        Integer* ilop, Integer* ihip, Integer* jlop, Integer* jhip)
{
    if(*ihip != *ihi || *ilop != *ilo || *jhip != *jhi || *jlop != *jlo)
        return(FALSE);
    else return(TRUE);
}


/**
 * check if patches have a nontrivial intersection
 * if yes, find the intersection and update [ilop:ihip, jlop:jhip]
 */
logical dai_patch_intersect(
        Integer ilo, Integer ihi, Integer jlo, Integer jhi,
        Integer* ilop, Integer* ihip, Integer* jlop, Integer* jhip)
{
    /* check consistency of patch coordinates */
    if( ihi < ilo || jhi < jlo)     return FALSE; /* inconsistent */
    if( *ihip < *ilop || *jhip < *jlop) return FALSE; /* inconsistent */

    /* find the intersection and update (ilop: ihip, jlop: jhip) */
    if( ihi < *ilop || *ihip < ilo) return FALSE; /* don't intersect */
    if( jhi < *jlop || *jhip < jlo) return FALSE; /* don't intersect */
    *ilop = PARIO_MAX(ilo,*ilop);
    *ihip = PARIO_MIN(ihi,*ihip);
    *jlop = PARIO_MAX(jlo,*jlop);
    *jhip = PARIO_MIN(jhi,*jhip);

    return(TRUE);
}


/**
 * check if sections have a nontrivial intersection
 * if yes, find the intersection and update [ilop:ihip, jlop:jhip]
 * section format
 */
logical dai_section_intersect(section_t sref, section_t *sadj)
{
    Integer ndim = sref.ndim;
    Integer i;
    logical isconsistent = TRUE;
    /* check that patches have same dimension */
    if (ndim != sadj->ndim) isconsistent = FALSE;
    /* check consistency of patch coordinates */
    if (isconsistent) {
        for (i=0; i<ndim; i++) {
            if (sref.hi[i] < sref.lo[i]) isconsistent = FALSE;
            if (sadj->hi[i] < sadj->lo[i]) isconsistent = FALSE;
        }
    }
    /* check to see if there is an intersection */
    if (isconsistent) {
        for (i=0; i<ndim; i++) {
            if (sref.hi[i] < sadj->lo[i]) isconsistent = FALSE;
            if (sadj->hi[i] < sref.lo[i]) isconsistent = FALSE;
        }
    }
    /* if there is an intersection then return it in sadj */
    if (isconsistent) {
        for (i=0; i<ndim; i++) {
            sadj->lo[i] = PARIO_MAX(sref.lo[i],sadj->lo[i]);
            sadj->hi[i] = PARIO_MIN(sref.hi[i],sadj->hi[i]);
        }
    }
    return (isconsistent);
}