map.c 6.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/*******************************************************************************
 * This file is part of SWIFT.
 * Copyright (c) 2012 Pedro Gonnet (pedro.gonnet@durham.ac.uk),
 *                    Matthieu Schaller (matthieu.schaller@durham.ac.uk)
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 ******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
23
24
#include "error.h"
#include "map.h"
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

/**
 * @brief Mapping function to draw a specific cell (gnuplot).
 */

void map_cells_plot(struct cell *c, void *data) {

  int depth = *(int *)data;
  double *l = c->loc, *h = c->h;

  if (c->depth <= depth) {

    printf("%.16e %.16e %.16e\n", l[0], l[1], l[2]);
    printf("%.16e %.16e %.16e\n", l[0] + h[0], l[1], l[2]);
    printf("%.16e %.16e %.16e\n", l[0] + h[0], l[1] + h[1], l[2]);
    printf("%.16e %.16e %.16e\n\n\n", l[0], l[1] + h[1], l[2]);

    printf("%.16e %.16e %.16e\n", l[0], l[1], l[2] + h[2]);
    printf("%.16e %.16e %.16e\n", l[0] + h[0], l[1], l[2] + h[2]);
    printf("%.16e %.16e %.16e\n", l[0] + h[0], l[1] + h[1], l[2] + h[2]);
    printf("%.16e %.16e %.16e\n\n\n", l[0], l[1] + h[1], l[2] + h[2]);

    printf("%.16e %.16e %.16e\n", l[0], l[1], l[2]);
    printf("%.16e %.16e %.16e\n", l[0], l[1] + h[1], l[2]);
    printf("%.16e %.16e %.16e\n", l[0], l[1] + h[1], l[2] + h[2]);
    printf("%.16e %.16e %.16e\n\n\n", l[0], l[1], l[2] + h[2]);

    printf("%.16e %.16e %.16e\n", l[0] + h[0], l[1], l[2]);
    printf("%.16e %.16e %.16e\n", l[0] + h[0], l[1] + h[1], l[2]);
    printf("%.16e %.16e %.16e\n", l[0] + h[0], l[1] + h[1], l[2] + h[2]);
    printf("%.16e %.16e %.16e\n\n\n", l[0] + h[0], l[1], l[2] + h[2]);

    printf("%.16e %.16e %.16e\n", l[0], l[1], l[2]);
    printf("%.16e %.16e %.16e\n", l[0], l[1], l[2] + h[2]);
    printf("%.16e %.16e %.16e\n", l[0] + h[0], l[1], l[2] + h[2]);
    printf("%.16e %.16e %.16e\n\n\n", l[0] + h[0], l[1], l[2]);

    printf("%.16e %.16e %.16e\n", l[0], l[1] + h[1], l[2]);
    printf("%.16e %.16e %.16e\n", l[0], l[1] + h[1], l[2] + h[2]);
    printf("%.16e %.16e %.16e\n", l[0] + h[0], l[1] + h[1], l[2] + h[2]);
    printf("%.16e %.16e %.16e\n\n\n", l[0] + h[0], l[1] + h[1], l[2]);

    if (!c->split) {
      for (int k = 0; k < c->count; k++)
        printf("0 0 0 %.16e %.16e %.16e\n", c->parts[k].x[0], c->parts[k].x[1],
               c->parts[k].x[2]);
      printf("\n\n");
    }
    /* else
        for ( int k = 0 ; k < 8 ; k++ )
            if ( c->progeny[k] != NULL )
                map_cells_plot( c->progeny[k] , data ); */
  }
}

/**
 * @brief Mapping function for checking if each part is in its box.
 */

/* void map_check ( struct part *p , struct cell *c , void *data ) {

    if ( p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] ||
         p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] ||
         p->x[0] < c->loc[0] || p->x[0] > c->loc[0]+c->h[0] )
        printf( "map_check: particle %i is outside of its box.\n" , p->id );

    } */

/**
 * @brief Mapping function for neighbour count.
 */

void map_cellcheck(struct cell *c, void *data) {

99
  int *count = (int *)data;
100
101
102
  __sync_fetch_and_add(count, c->count);

  /* Loop over all parts and check if they are in the cell. */
103
104
  for (int k = 0; k < c->count; k++) {
    struct part *p = &c->parts[k];
105
106
107
108
109
110
111
112
113
114
115
    if (p->x[0] < c->loc[0] || p->x[1] < c->loc[1] || p->x[2] < c->loc[2] ||
        p->x[0] > c->loc[0] + c->h[0] || p->x[1] > c->loc[1] + c->h[1] ||
        p->x[2] > c->loc[2] + c->h[2]) {
      printf(
          "map_cellcheck: particle at [ %.16e %.16e %.16e ] outside of cell [ "
          "%.16e %.16e %.16e ] - [ %.16e %.16e %.16e ].\n",
          p->x[0], p->x[1], p->x[2], c->loc[0], c->loc[1], c->loc[2],
          c->loc[0] + c->h[0], c->loc[1] + c->h[1], c->loc[2] + c->h[2]);
      error("particle out of bounds!");
    }
  }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131

  /* Loop over all gparts and check if they are in the cell. */
  for (int k = 0; k < c->gcount; k++) {
    struct gpart *p = &c->gparts[k];
    if (p->x[0] < c->loc[0] || p->x[1] < c->loc[1] || p->x[2] < c->loc[2] ||
        p->x[0] > c->loc[0] + c->h[0] || p->x[1] > c->loc[1] + c->h[1] ||
        p->x[2] > c->loc[2] + c->h[2]) {
      printf(
          "map_cellcheck: g-particle at [ %.16e %.16e %.16e ] outside of cell [ "
          "%.16e %.16e %.16e ] - [ %.16e %.16e %.16e ].\n",
          p->x[0], p->x[1], p->x[2], c->loc[0], c->loc[1], c->loc[2],
          c->loc[0] + c->h[0], c->loc[1] + c->h[1], c->loc[2] + c->h[2]);
      error("g-particle out of bounds!");
    }
  }

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
}

/**
 * @brief Mapping function for maxdepth cell count.
 */

void map_maxdepth(struct cell *c, void *data) {

  int maxdepth = ((int *)data)[0];
  int *count = &((int *)data)[1];

  // printf( "%e\n" , p->count );

  if (c->depth == maxdepth) *count += 1;
}

/**
 * @brief Mapping function for neighbour count.
 */

void map_count(struct part *p, struct cell *c, void *data) {

  double *wcount = (double *)data;

  // printf( "%i %e %e\n" , p->id , p->count , p->count_dh );

  *wcount += p->density.wcount;
}

void map_wcount_min(struct part *p, struct cell *c, void *data) {

  struct part **p2 = (struct part **)data;

  if (p->density.wcount < (*p2)->density.wcount) *p2 = p;
}

void map_wcount_max(struct part *p, struct cell *c, void *data) {

  struct part **p2 = (struct part **)data;

  if (p->density.wcount > (*p2)->density.wcount) *p2 = p;
}

void map_h_min(struct part *p, struct cell *c, void *data) {

  struct part **p2 = (struct part **)data;

  if (p->h < (*p2)->h) *p2 = p;
}

void map_h_max(struct part *p, struct cell *c, void *data) {

  struct part **p2 = (struct part **)data;

  if (p->h > (*p2)->h) *p2 = p;
}

/**
 * @brief Mapping function for neighbour count.
 */

void map_icount(struct part *p, struct cell *c, void *data) {

  // int *count = (int *)data;

  // printf( "%i\n" , p->icount );

  // *count += p->icount;
}

/**
 * @brief Mapping function to print the particle position.
 */

void map_dump(struct part *p, struct cell *c, void *data) {

  double *shift = (double *)data;

  printf("%g\t%g\t%g\n", p->x[0] - shift[0], p->x[1] - shift[1],
         p->x[2] - shift[2]);
}