Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
DLR-AMR
GitHub Repository: DLR-AMR/t8code
Path: blob/main/src/t8.c
898 views
1
/*
2
This file is part of t8code.
3
t8code is a C library to manage a collection (a forest) of multiple
4
connected adaptive space-trees of general element classes in parallel.
5
6
Copyright (C) 2015 the developers
7
8
t8code is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
12
13
t8code is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License
19
along with t8code; if not, write to the Free Software Foundation, Inc.,
20
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21
*/
22
23
/** \file t8.c
24
* Implements functions declared in \ref t8.h.
25
*/
26
27
#include <t8.h>
28
#include <t8_version.h>
29
30
static int t8_package_id = -1;
31
static void (*external_log_fcn) (int category, int priority, const char *msg) = NULL;
32
33
int
34
t8_get_package_id (void)
35
{
36
return t8_package_id;
37
}
38
39
void
40
t8_logv (int category, int priority, const char *fmt, va_list ap)
41
{
42
char buffer[BUFSIZ];
43
44
sc_package_lock (t8_package_id);
45
vsnprintf (buffer, BUFSIZ, fmt, ap);
46
sc_package_unlock (t8_package_id);
47
48
if (external_log_fcn) {
49
external_log_fcn (category, priority, buffer);
50
return;
51
}
52
sc_log ("unknown", -1, t8_package_id, category, priority, buffer);
53
}
54
55
void
56
t8_logf (int category, int priority, const char *fmt, ...)
57
{
58
va_list ap;
59
60
va_start (ap, fmt);
61
t8_logv (category, priority, fmt, ap);
62
va_end (ap);
63
}
64
65
void
66
t8_log_indent_push (void)
67
{
68
sc_log_indent_push_count (t8_get_package_id (), 1);
69
}
70
71
void
72
t8_log_indent_pop (void)
73
{
74
sc_log_indent_pop_count (t8_get_package_id (), 1);
75
}
76
77
void
78
t8_global_errorf (const char *fmt, ...)
79
{
80
va_list ap;
81
82
va_start (ap, fmt);
83
t8_logv (SC_LC_GLOBAL, SC_LP_ERROR, fmt, ap);
84
va_end (ap);
85
}
86
87
void
88
t8_global_essentialf (const char *fmt, ...)
89
{
90
va_list ap;
91
92
va_start (ap, fmt);
93
t8_logv (SC_LC_GLOBAL, SC_LP_ESSENTIAL, fmt, ap);
94
va_end (ap);
95
}
96
97
void
98
t8_global_productionf (const char *fmt, ...)
99
{
100
va_list ap;
101
102
va_start (ap, fmt);
103
t8_logv (SC_LC_GLOBAL, SC_LP_PRODUCTION, fmt, ap);
104
va_end (ap);
105
}
106
107
void
108
t8_global_infof (const char *fmt, ...)
109
{
110
va_list ap;
111
112
va_start (ap, fmt);
113
t8_logv (SC_LC_GLOBAL, SC_LP_INFO, fmt, ap);
114
va_end (ap);
115
}
116
117
void
118
t8_infof (const char *fmt, ...)
119
{
120
va_list ap;
121
122
va_start (ap, fmt);
123
t8_logv (SC_LC_NORMAL, SC_LP_INFO, fmt, ap);
124
va_end (ap);
125
}
126
127
void
128
t8_productionf (const char *fmt, ...)
129
{
130
va_list ap;
131
132
va_start (ap, fmt);
133
t8_logv (SC_LC_NORMAL, SC_LP_PRODUCTION, fmt, ap);
134
va_end (ap);
135
}
136
137
void
138
t8_debugf (__attribute__ ((unused)) const char *fmt, ...)
139
{
140
#if T8_ENABLE_DEBUG
141
va_list ap;
142
143
va_start (ap, fmt);
144
t8_logv (SC_LC_NORMAL, SC_LP_DEBUG, fmt, ap);
145
va_end (ap);
146
#endif
147
}
148
149
void
150
t8_errorf (const char *fmt, ...)
151
{
152
va_list ap;
153
154
va_start (ap, fmt);
155
t8_logv (SC_LC_NORMAL, SC_LP_ERROR, fmt, ap);
156
va_end (ap);
157
}
158
159
void
160
t8_set_external_log_fcn (void (*log_fcn) (int category, int priority, const char *msg))
161
{
162
external_log_fcn = log_fcn;
163
}
164
165
void
166
t8_init (int log_threshold)
167
{
168
int w;
169
170
t8_package_id = sc_package_register (NULL, log_threshold, "t8", "Adaptive discretizations");
171
172
w = 24;
173
t8_global_essentialf ("This is %s\n", t8_get_package_string ());
174
t8_global_productionf ("%-*s %s\n", w, "CXX", T8_CXX);
175
t8_global_productionf ("%-*s %s\n", w, "CXXFLAGS", T8_CXXFLAGS);
176
t8_global_productionf ("%-*s %s\n", w, "CC", T8_CC);
177
t8_global_productionf ("%-*s %s\n", w, "CFLAGS", T8_CFLAGS);
178
t8_global_productionf ("%-*s %s\n", w, "LDFLAGS", T8_LDFLAGS);
179
t8_global_productionf ("%-*s %s\n", w, "LIBS", T8_LIBS);
180
}
181
182
void *
183
t8_sc_array_index_locidx (const sc_array_t *array, const t8_locidx_t it)
184
{
185
T8_ASSERT (it >= 0 && (size_t) it < array->elem_count);
186
187
return array->array + array->elem_size * (size_t) it;
188
}
189
190