DACE 2.0 API Manual
Differential Algebra Core Engine
daceaux.h
Go to the documentation of this file.
1 /******************************************************************************
2 * *
3 * DIFFERENTIAL ALGEBRA CORE ENGINE *
4 * *
5 *******************************************************************************
6 * *
7 * Copyright 2016 Politecnico di Milano (2014 Dinamica Srl) *
8 * Licensed under the Apache License, Version 2.0 (the "License"); *
9 * you may not use this file except in compliance with the License. *
10 * You may obtain a copy of the License at *
11 * *
12 * http://www.apache.org/licenses/LICENSE-2.0 *
13 * *
14 * Unless required by applicable law or agreed to in writing, software *
15 * distributed under the License is distributed on an "AS IS" BASIS, *
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17 * See the License for the specific language governing permissions and *
18 * limitations under the License. *
19 * *
20 *******************************************************************************/
21 
22 /*
23  * daceaux.h
24  *
25  * Created on: November 18, 2016
26  * Author: Politecnico di Milano
27  */
28 
29 /*
30  This file contains all internal DACE auxiliary functions used by the DACE core.
31  It is not meant to be included publicly by DACE users or high level interfaces.
32 */
37 #ifndef DINAMICA_DACEAUX_H_
38 #define DINAMICA_DACEAUX_H_
39 
40 #include <stdlib.h> // for size_t
41 #include <stdbool.h> // for bool
42 #include <string.h>
43 
44 #include "dace/config.h"
45 
46 // macro to help tell supported compiler which branch is most likely
47 #if __GNUC__ || __clang__
48  #define UNLIKELY(expr) __builtin_expect(!!(expr), 0)
49  #define LIKELY(expr) __builtin_expect(!!(expr), 1)
50 #else
51  #define UNLIKELY(expr) expr
52  #define LIKELY(expr) expr
53 #endif
54 
55 // DACE internal data structure
56 typedef struct dcom {
57  unsigned int *ie1, *ie2, *ieo, *ia1, *ia2;
58  unsigned int nomax, nvmax, nv1, nv2, nmmax;
59  double epsmac;
60 } dacecom;
61 
62 // DACE thread local data structure
63 typedef struct dcom_t {
64  unsigned int nocut;
65  double eps;
66 #ifdef DACE_FILTERING
67  unsigned int *ifi;
68  unsigned int lfi;
69 #endif
70 } dacecom_t;
71 
72 #define ERROR_FUN_SIZE 64
73 #define ERROR_MSG_SIZE 256
74 // DACE error management
75 typedef struct ddbg {
76  unsigned int ierr, ixerr, iyyerr;
77  char name[ERROR_FUN_SIZE];
78  char msg[ERROR_MSG_SIZE];
79 } dacedbg;
80 
81 // Basic memory structure of a monomial
82 typedef struct dmonomial {
83  double cc;
84  unsigned int ii;
85 } monomial;
86 
87 // Basic memory structure of an extended monomial (these are written and read from binary files, so enforce no padding!)
88 #pragma pack(push,1)
89 typedef struct dextendedmonomial {
90  unsigned int i1, i2;
91  double cc;
93 #pragma pack(pop)
94 
95 // 32 bit magic marker to identify beginning of binary DACE blobs (in little endian the letters DA0 and the record separator 1E)
96 #define DACE_BINARY_MAGIC (0x1E304144)
97 
98 // Memory structure of a DACE blob (not public!)
99 #pragma pack(push,1)
100 struct daceblob {
101  unsigned int magic;
102  unsigned int no, nv1, nv2, len;
103  extended_monomial monomials[1];
104 };
105 #pragma pack(pop)
106 
107 // external global symbols for common DACE structures (actually allocated in dacememory.c)
108 extern dacecom DACECom;
109 extern DACE_THREAD_LOCAL dacecom_t DACECom_t;
110 extern DACE_THREAD_LOCAL dacedbg DACEDbg;
111 
113 // math utility routines
114 unsigned int umin(const unsigned int a, const unsigned int b);
115 unsigned int umax(const unsigned int a, const unsigned int b);
116 double pown(double a, unsigned int b);
117 int npown(int a, unsigned int b);
118 
119 #if DACE_MEMORY_MODEL == DACE_MEMORY_HYBRID || DACE_MEMORY_MODEL == DACE_MEMORY_DYNAMIC
120  // dynamic memory allocation wrappers
121  void* dacecalloc(size_t count, size_t size);
122  void* dacemalloc(size_t size);
123  void* dacemalloc0(size_t size);
124  void* dacerealloc(void* ptr, size_t size);
125  void dacefree(void* ptr);
126 #endif
127 
128 // internal memory related routines
129 void daceFreeMemory();
130 void daceVariableInformation(const DACEDA *inc, monomial **ipoc, unsigned int *ilmc, unsigned int *illc);
131 void daceSetLength(DACEDA *inc, const size_t len);
132 bool daceIsSameObject(const DACEDA *ina, const DACEDA *inb);
133 
134 // basic monomial coding integer related routines
135 unsigned int daceEncodeExponents(const unsigned int p[], const unsigned int no, const unsigned int nv);
136 unsigned int daceEncode(const unsigned int p[]);
137 unsigned int daceDecodeExponents(unsigned int ic, const unsigned int no, const unsigned int nv, unsigned int p[]);
138 void daceDecode(const unsigned int ic, unsigned int p[]);
139 unsigned int daceCountMonomials(unsigned int no, unsigned int nv);
140 unsigned int daceNextMonomial(unsigned int p[], const unsigned int no, const unsigned int nv);
141 unsigned int daceNextOrderedMonomial(unsigned int p[], const unsigned int no, const unsigned int nv);
142 
143 // internal routines
144 void daceInitializeThread0();
145 void daceSetError(const char *c, const unsigned int ix, const unsigned int iyy);
146 void dacePack(double *restrict cc, DACEDA *restrict inc);
147 void daceMultiplicativeInverse0(const DACEDA *ina, DACEDA *inc, const double a0);
148 int BesselWrapper(const double x, const int n0, const int n1, const int type, double *bz);
149 int ModifiedBesselWrapper(const double x, const int n0, const int n1, const int type, double *bz);
150 void daceEvaluateBesselFunction(const DACEDA *ina, const double bz[], const double type, const double ktype, DACEDA *inc);
151 void daceEvaluateScaledModifiedBesselFunction(const DACEDA *ina, const double bz[], const double type, DACEDA *inc);
152 void daceLogGammaFunction0(const DACEDA *ina, const double a0, DACEDA *inc);
153 void daceEvaluateSeries(const DACEDA *ina, const double xf[], DACEDA *inc);
155 
156 #endif /* DINAMICA_DACEAUX_H_ */
unsigned int iyyerr
Definition: daceaux.h:76
unsigned int * ia1
Definition: daceaux.h:57
void daceSetError(const char *c, const unsigned int ix, const unsigned int iyy)
Definition: daceerror.c:139
Definition: daceaux.h:63
void daceInitializeThread0()
Definition: daceinit.c:225
void daceMultiplicativeInverse0(const DACEDA *ina, DACEDA *inc, const double a0)
Definition: dacemath.c:900
double pown(double a, unsigned int b)
Definition: daceaux.c:58
void daceEvaluateBesselFunction(const DACEDA *ina, const double bz[], const double type, const double ktype, DACEDA *inc)
Definition: dacemath.c:1776
unsigned int * ieo
Definition: daceaux.h:57
void daceEvaluateScaledModifiedBesselFunction(const DACEDA *ina, const double bz[], const double ktype, DACEDA *inc)
Definition: dacemath.c:1828
unsigned int * ie1
Definition: daceaux.h:57
struct dmonomial monomial
Definition: daceaux.h:75
void daceSetLength(DACEDA *inc, const size_t len)
Definition: dacememory.c:317
unsigned int daceEncodeExponents(const unsigned int p[], const unsigned int no, const unsigned int nv)
Definition: daceaux.c:165
Definition: daceaux.h:56
unsigned int nv2
Definition: daceaux.h:102
void daceVariableInformation(const DACEDA *inc, monomial **ipoc, unsigned int *ilmc, unsigned int *illc)
Definition: dacememory.c:296
unsigned int umin(const unsigned int a, const unsigned int b)
Definition: daceaux.c:46
Definition: daceaux.h:89
struct dextendedmonomial extended_monomial
unsigned int daceNextOrderedMonomial(unsigned int p[], const unsigned int no, const unsigned int nv)
Definition: daceaux.c:257
struct dcom_t dacecom_t
Definition: daceaux.h:100
unsigned int * ia2
Definition: daceaux.h:57
double cc
Definition: daceaux.h:91
struct ddbg dacedbg
int npown(int a, unsigned int b)
Definition: daceaux.c:76
Definition: daceaux.h:82
void daceDecode(const unsigned int jc, unsigned int jj[])
Definition: daceaux.c:320
DACE_THREAD_LOCAL dacedbg DACEDbg
Definition: dacememory.c:49
unsigned int nvmax
Definition: daceaux.h:58
unsigned int ii
Definition: daceaux.h:84
unsigned int i2
Definition: daceaux.h:90
unsigned int nmmax
Definition: daceaux.h:58
unsigned int * ie2
Definition: daceaux.h:57
void dacePack(double *restrict cc, DACEDA *restrict inc)
Definition: daceaux.c:337
bool daceIsSameObject(const DACEDA *ina, const DACEDA *inb)
Definition: dacememory.c:333
unsigned int daceEncode(const unsigned int jj[])
Definition: daceaux.c:290
void daceLogGammaFunction0(const DACEDA *ina, const double a0, DACEDA *inc)
Definition: dacemath.c:1884
void daceFreeMemory()
Definition: dacememory.c:341
unsigned int nomax
Definition: daceaux.h:58
void daceEvaluateSeries(const DACEDA *ina, const double xf[], DACEDA *inc)
Definition: dacemath.c:2003
unsigned int magic
Definition: daceaux.h:101
unsigned int umax(const unsigned int a, const unsigned int b)
Definition: daceaux.c:51
double epsmac
Definition: daceaux.h:59
#define ERROR_MSG_SIZE
Definition: daceaux.h:73
unsigned int nv2
Definition: daceaux.h:58
unsigned int nv1
Definition: daceaux.h:58
unsigned int daceNextMonomial(unsigned int p[], const unsigned int no, const unsigned int nv)
Definition: daceaux.c:221
unsigned int daceDecodeExponents(unsigned int ic, const unsigned int no, const unsigned int nv, unsigned int p[])
Definition: daceaux.c:184
dacecom DACECom
Definition: dacememory.c:47
DACE_THREAD_LOCAL dacecom_t DACECom_t
Definition: dacememory.c:48
struct dcom dacecom
unsigned int daceCountMonomials(unsigned int no, unsigned int nv)
Definition: daceaux.c:274
#define ERROR_FUN_SIZE
Definition: daceaux.h:72
unsigned int size(const DA &da)
Definition: DA.cpp:2549
double eps
Definition: daceaux.h:65
unsigned int nocut
Definition: daceaux.h:64
int DACEDA
Definition: dacebase.h:70
double cc
Definition: daceaux.h:83