File: vfunc_pargear.cpp

package info (click to toggle)
adolc 2.7.2-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,496 kB
  • sloc: cpp: 40,481; ansic: 19,390; sh: 4,277; makefile: 551; python: 486
file content (738 lines) | stat: -rw-r--r-- 22,825 bytes parent folder | download | duplicates (3)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
/*----------------------------------------------------------------------------
 ADOL-C -- Automatic Differentiation by Overloading in C++
 File:     vfunc_pargear.cpp
 Revision: $Id$
 Contents: Example of function module containing the machine tool example
           of gearing (parametrized version)
 
   Each << function module >> contains:
          
     (1) const char* const controlFileName 
     (2) int indepDim; 
     (3) int depDim; 
     (4) void initProblemParameters( void )
     (5) void initIndependents( double* indeps )
     (6) void originalVectorFunction( double* indeps, double* deps )
     (7) void tapingVectorFunction( int tag, double* indeps, double* deps )   
 
 Copyright (c) Andrea Walther, Andreas Griewank, Andreas Kowarz, 
               Hristo Mitev, Sebastian Schlenkrich, Jean Utke, Olaf Vogel 
  
 This file is part of ADOL-C. This software is provided as open source.
 Any use, reproduction, or distribution of the software constitutes 
 recipient's acceptance of the terms of the accompanying license file.
 
---------------------------------------------------------------------------*/
#define _VFUNC_PARGEAR_C_


/****************************************************************************/
/*                                                                 INCLUDES */
#include <adolc/adolc.h>
#include "rotations.h"

#include <cmath>
#include <time.h>
#include <cstdlib>


/****************************************************************************/
/*                                                         GLOBAL VARIABLES */
#define Pi 3.141592654

/*--------------------------------------------------------------------------*/
/*                                                        Control file name */
const char* controlFileName = "pargearexam.ctrl";

/*--------------------------------------------------------------------------*/
/*                                                               Dimensions */
int indepDim;
int depDim;
int radMotDegree;
int verMotDegree;
int horMotDegree;
int helMotDegree;
int angMotDegree;
int modRolDegree;


/*--------------------------------------------------------------------------*/
/*                                        important machine tool parameters */
// example bet06-23 convex pinion flank

int konvex=     1;          // konvexe oder konkave Flanke
int    zz=      6;          // Zaehnezahl

double xmk=    -17.50195;   // Messerversatz
double ymk=     80.0;       // MK-Versatz
double kopspw=   0.0;       // Kopfspanwinkel
double flaspw=   0.0;       // Flankenspanwinkel
double meschw=   0.0;       // Messerschwenkwinkel
double flkrrd= 101.44158;   // Spitzenradius, Flugkreisr.
double e=        0.0;       // MK-Exzentrizitaet
double exzenw=   0.0;       // Exzentrizitaetswinkel
double thetas=   0.0;       // Messerkopfschwenkung
double thetan=   0.0;       // Messerkopfneigung
double xmw=     24.63350;   // MK-x
double ymw=    -73.69500;   // MK-y
double zmw=     96.15919;   // MK-z
double thetaw=-314.52420;   // Wiegenwinkel=Waelztrommelwinkel
double m=       0.0;        // Erzeugungs-Achsversatz
double zwr=     0.0;        // Verschiebung Werkradachse
double delta=   14.62090;   // Kegelwinkel
double omega=   0.0;
double c=       0.0;
double r=        2.1;       // Kopfradius
double rs=    2594.425;     // Sphaerikradius
double ys=     876.147;     // Sphaerik-Mitte-Y
double zs=   -2442.015;     // Sphaerik-Mitte-Z

/*--------------------------------------------------------------------------*/
/*                                       Other problem dependent parameters */
//static unsigned short int dx[3]; /* variable needed by erand48(.) */


/****************************************************************************/
/*                                                  INIT PROBLEM PARAMETERS */
void initProblemParameters( void ) {
    fprintf(stdout,"PARGEAREXAM (ADOL-C Example)\n\n");

    /* number of indeps & deps */
    depDim   = 3;
    indepDim = 3;

    fprintf(stdout,"   Radial motion degree = ? [-1=no polynomial,0,...,6]");
    fscanf(stdin,"%d",&radMotDegree);
    fprintf(stdout,"\n");
    if (radMotDegree>=0)
        indepDim += radMotDegree + 1;

    fprintf(stdout,"   Vertical motion degree = ? ");
    fscanf(stdin,"%d",&verMotDegree);
    fprintf(stdout,"\n");
    if (verMotDegree>=0)
        indepDim += verMotDegree + 1;

    fprintf(stdout,"   Horizontal motion degree = ? ");
    fscanf(stdin,"%d",&horMotDegree);
    fprintf(stdout,"\n");
    if (horMotDegree>=0)
        indepDim += horMotDegree + 1;

    fprintf(stdout,"   Helical motion degree = ? ");
    fscanf(stdin,"%d",&helMotDegree);
    fprintf(stdout,"\n");
    if (helMotDegree>=0)
        indepDim += helMotDegree + 1;

    fprintf(stdout,"   Angular motion degree = ? ");
    fscanf(stdin,"%d",&angMotDegree);
    fprintf(stdout,"\n");
    if (angMotDegree>=0)
        indepDim += angMotDegree + 1;

    fprintf(stdout,"   Modified roll degree = ? ");
    fscanf(stdin,"%d",&modRolDegree);
    fprintf(stdout,"\n");
    if (modRolDegree>=0)
        indepDim += modRolDegree + 1;

    /* Init erand48(); */
    struct tm s;
    time_t t;
    time(&t);
    s=*localtime(&t);
    srand(s.tm_sec*s.tm_min);
    /*  dx[0]=rand();
      dx[1]=rand();
      dx[2]=rand();*/
}


/****************************************************************************/
/*                                                        INITIALIZE INDEPs */
void initIndependents( double* indeps ) {
    for (int i=0; i<indepDim; i++)
        indeps[i] = (double)rand();
}



/****************************************************************************/
/*                                                 ORIGINAL SCALAR FUNCTION */

/*--------------------------------------------------------------------------*/
/*                                                       The model function */

/*--------------------------------------------------------------------------*/
// parametrized cutting edge
void def_messer(
    double * z,
    double * messer,
    // jetzt kommen die Parameter
    double hgR,   // Kopfradius
    double hgRs,  // Sphaerikradius
    double hgYs,  // Sphaerik-Mitte-Y
    double hgZs   // Sphaerik-Mitte-Z
) {
    double u0, uOri, phi0, h;

    phi0= asin((hgR+hgYs)/(hgR+hgRs));
    if (konvex==1) {
        u0=hgRs*phi0;
        uOri=1.0;
    } else {
        u0=hgRs*(phi0-Pi);
        uOri=-1.0;
    };

    h= (z[0]-u0)/(uOri*hgRs);
    messer[0]=hgZs+hgRs*cos(h);
    messer[1]=0.0;
    messer[2]=-hgYs-hgRs*sin(h);
}

/*--------------------------------------------------------------------------*/
// the main function
void gearFunction(
    double* z,       // (u,v,t) Parametrisierung der Bewegung der Messerschneide
    double* f,       // (x,y,z) Bewegte Messerschneide
    // jetzt kommen die ganzen Parameter
    double hgXmk,    // Messerversatz
    double hgYmk,    // MK-Versatz
    double hgKopSpW, // Kopfspanwinkel
    double hgFlaSpW, // Flankenspanwinkel
    double hgMeSchW, // Messerschwenkwinkel
    double hgFlKrRd, // Flugkreisradius
    double hgE,      // Exzentrizitaet
    double hgExzenW, // Exzentrizitaetswinkel
    double hgThetaS, // Messerkopfschwenkung
    double hgThetaN, // Messerkopfneigung
    double hgXmw,    // MK-x
    double hgYmw,    // MK-y
    double hgZmw,    // MK-z
    double hgThetaW, // Wiegenwinkel
    double hgM,      // Achsversatz
    double hgZwr,    // Verschiebung Werkradachse
    double hgDelta,  // Teilkegeloeffnungswinkel
    double hgOmega,  //
    double hgC,
    double hgR,      // Kopfradius
    double hgRs,     // Sphaerikradius
    double hgYs,     // Sphaerik-Mitte-Y
    double hgZs,     // Sphaerik-Mitte-Z
    // jetzt die Zusatzbewegungen
    int     radialMotionDegree,
    double* radialMotionCoeff,
    int     verticalMotionDegree,
    double* verticalMotionCoeff,
    int     horizontalMotionDegree,
    double* horizontalMotionCoeff,
    int     helicalMotionDegree,
    double* helicalMotionCoeff,
    int     angularMotionDegree,
    double* angularMotionCoeff,
    int     modifiedRollDegree,
    double* modifiedRollCoeff
) {
    int i;
    double ah;            // Hilfswert

    // Definition der Schneide
    def_messer(z,f,hgR,hgRs,hgYs,hgZs);

    // Position der Schneide am Messerkopf
    // (jetzt die Ber"ucksichtigung von hgKopSpW, hgFlaSpW, hgMeSchW)
    D2T(f,hgMeSchW);     // Messerschwenkwinkel Theta_M
    D3T(f,hgFlaSpW);     // Flankenspanwinkel Theta_F
    D1(f,hgKopSpW);      // Kopfspanwinkel Theta_K
    // Position der Schneide am Messerkopf
    f[0] += hgFlKrRd;    // Flugkreisradius
    f[1] -= hgXmk;       // Messerversatz

    // Messerkopfrotation mit Parameter v
    D3(f,z[1]);

    // Lage des Messerkopfs auf der Wiege
    f[2] -= hgYmk;

    // Beruecksichtigung der Messerkopf-Exzentrizitaet
    f[0] += hgE * cos(hgExzenW);
    f[1] -= hgE * sin(hgExzenW);

    // Eindrehen in Orientierung der Wiege
    ah = f[0];
    f[0] = f[1];
    f[1] = ah;
    f[2] = -f[2];

    // Beruecksichtigung von Messerkopf-Schwenkwinkel hgThetaS
    // und der Messerkopfneigung hgThetaN
    D3T(f,hgThetaS);     // Einschwenken in die Neigungsachse
    D1T(f,hgThetaN);     // Neigung um x-Achse
    D3(f,hgThetaS);      // Rueckschwenken aus der Neigungsachse

    // Verschiebung
    f[0] -= hgXmw;       // FLB1-x-Achse zeigt nach oben     -> (-xNeu)
    f[1] += hgZmw;       // FLB1-z-Achse zeigt nach rechts   ->  (yNeu)
    f[2] += hgYmw;       // FLB1-y-Achse zeigt aus der Wiege ->  (zNeu)

    // Wiegenwinkel thetaW, entspricht dem wert t=0
    D3(f,hgThetaW);

    // ZUSATZBEWEGUNG Radial motion
    if (radialMotionDegree >= 0) {
        ah = 0.0;
        for (i=radialMotionDegree; i>0; i--) {
            ah += radialMotionCoeff[i];
            ah *= z[2];
        }
        ah += radialMotionCoeff[0];
        f[1] += ah;        // radiale Verschiebung des Messerkopfes
    }

    // Wiegenbewegung mit Parameter t
    D3(f,z[2]);

    // ZUSATZBEWEGUNG Vertical motion
    if (verticalMotionDegree >= 0) {
        ah = 0.0;
        for (i=verticalMotionDegree; i>0; i--) {
            ah += verticalMotionCoeff[i];
            ah *= z[2];
        }
        ah += verticalMotionCoeff[0];
        f[0] += ah;        // Achsversatz in positive x-Richtung
    }

    // originaler Achsversatz
    f[0] += hgM;

    // ZUSATZBEWEGUNG Horizontal motion
    if (horizontalMotionDegree >= 0) {
        ah = 0.0;
        for (i=horizontalMotionDegree; i>0; i--) {
            ah += horizontalMotionCoeff[i];
            ah *= z[2];
        }
        ah += horizontalMotionCoeff[0];
        f[1] += ah;        // Achsversatz in positive y-Richtung
    }

    // ZUSATZBEWEGUNG Helical motion
    if (helicalMotionDegree >= 0) {
        ah = 0.0;
        for (i=helicalMotionDegree; i>0; i--) {
            ah += helicalMotionCoeff[i];
            ah *= z[2];
        }
        ah += helicalMotionCoeff[0];
        f[2] -= ah;        // Tiefenposition in negative z-Richtung
    }

    // Eindrehen in Orientierung des Werkrades
    f[0] = -f[0];
    ah = f[1];
    f[1] = -f[2];
    f[2] = -ah;

    // ZUSATZBEWEGUNG Angular motion
    if (angularMotionDegree >= 0) {
        ah = 0.0;
        for (i=angularMotionDegree; i>0; i--) {
            ah += angularMotionCoeff[i];
            ah *= z[2];
        }
        ah += angularMotionCoeff[0];
        D1(f,ah);        // umgekehrte Drehung um die x-Achse
    }

    // Teilkegeloeffnungswinkel delta - y-Achsen entgegengesetzt
    D1(f,hgDelta);

    // neue Verschiebung der Werkradachse
    f[2] += hgZwr; // z-Achse zeigt zu Spitze

    // ZUSATZBEWEGUNG Modified roll
    if (modifiedRollDegree >= 0) {
        ah = 0.0;
        for (i=modifiedRollDegree; i>1; i--) {
            ah += modifiedRollCoeff[i];
            ah *= z[2];
        }
        if (modifiedRollDegree > 0)
            ah += modifiedRollCoeff[1];
        ah += hgOmega;
        ah *= z[2];
        ah += modifiedRollCoeff[0];
    } else {
        ah = hgOmega;
        ah *= z[2];
    }
    ah += hgC*z[1];   // c*v + omega * t
    // gekoppelte Werkraddrehung in Abhaengigkeit von t und v
    D3(f,ah);
}

/*--------------------------------------------------------------------------*/
/*                                                   The interface function */
void originalVectorFunction( double* indeps, double* deps ) {
    int  i = 3;
    double * radMotCoeff = indeps+i;
    i += radMotDegree;
    double * verMotCoeff = indeps+i;
    i += verMotDegree;
    double * horMotCoeff = indeps+i;
    i += horMotDegree;
    double * helMotCoeff = indeps+i;
    i += helMotDegree;
    double * angMotCoeff = indeps+i;
    i += angMotDegree;
    double * modRolCoeff = indeps+i;

    gearFunction(
        indeps,
        deps,
        // jetzt kommen die ganzen Parameter
        xmk,    // Messerversatz
        ymk,    // MK-Versatz
        kopspw, // Kopfspanwinkel
        flaspw, // Flankenspanwinkel
        meschw, // Messerschwenkwinkel
        flkrrd, // Flugkreisradius
        e,      // Exzentrizitaet
        exzenw, // Exzentrizitaetswinkel
        thetas, // Messerkopfschwenkung
        thetan, // Messerkopfneigung
        xmw,    // MK-x
        ymw,    // MK-y
        zmw,    // MK-z
        thetaw, // Wiegenwinkel
        m,      // Achsversatz
        zwr,    // Verschiebung Werkradachse
        delta,  // Teilkegeloeffnungswinkel
        omega,  //
        c,
        r,      // Kopfradius
        rs,     // Sphaerikradius
        ys,     // Sphaerik-Mitte-Y
        zs,     // Sphaerik-Mitte-Z
        // jetzt die Zusatzbewegungen
        radMotDegree,
        radMotCoeff,
        verMotDegree,
        verMotCoeff,
        horMotDegree,
        horMotCoeff,
        helMotDegree,
        helMotCoeff,
        angMotDegree,
        angMotCoeff,
        modRolDegree,
        modRolCoeff
    );
}


/****************************************************************************/
/*                                                   TAPING SCALAR FUNCTION */


/*--------------------------------------------------------------------------*/
/*                                                       The model function */

/*--------------------------------------------------------------------------*/
// parametrized cutting edge
void def_messer(
    adouble * z,
    adouble * messer,
    // jetzt kommen die Parameter
    double hgR,   // Kopfradius
    double hgRs,  // Sphaerikradius
    double hgYs,  // Sphaerik-Mitte-Y
    double hgZs   // Sphaerik-Mitte-Z
) {
    double u0, uOri, phi0;
    adouble h;

    phi0= asin((hgR+hgYs)/(hgR+hgRs));
    if (konvex==1) {
        u0=hgRs*phi0;
        uOri=1.0;
    } else {
        u0=hgRs*(phi0-Pi);
        uOri=-1.0;
    };

    h= (z[0]-u0)/(uOri*hgRs);
    messer[0]=hgZs+hgRs*cos(h);
    messer[1]=0.0;
    messer[2]=-hgYs-hgRs*sin(h);
}

/*--------------------------------------------------------------------------*/
// the main function
void activeGearFunction(
    adouble* z,      // (u,v,t) Parametrisierung der Bewegung der Messerschneide
    adouble* f,      // (x,y,z) Bewegte Messerschneide
    // jetzt kommen die ganzen Parameter
    double hgXmk,    // Messerversatz
    double hgYmk,    // MK-Versatz
    double hgKopSpW, // Kopfspanwinkel
    double hgFlaSpW, // Flankenspanwinkel
    double hgMeSchW, // Messerschwenkwinkel
    double hgFlKrRd, // Flugkreisradius
    double hgE,      // Exzentrizitaet
    double hgExzenW, // Exzentrizitaetswinkel
    double hgThetaS, // Messerkopfschwenkung
    double hgThetaN, // Messerkopfneigung
    double hgXmw,    // MK-x
    double hgYmw,    // MK-y
    double hgZmw,    // MK-z
    double hgThetaW, // Wiegenwinkel
    double hgM,      // Achsversatz
    double hgZwr,    // Verschiebung Werkradachse
    double hgDelta,  // Teilkegeloeffnungswinkel
    double hgOmega,  //
    double hgC,
    double hgR,      // Kopfradius
    double hgRs,     // Sphaerikradius
    double hgYs,     // Sphaerik-Mitte-Y
    double hgZs,     // Sphaerik-Mitte-Z
    // jetzt die Zusatzbewegungen
    int     radialMotionDegree,
    adouble* radialMotionCoeff,
    int     verticalMotionDegree,
    adouble* verticalMotionCoeff,
    int     horizontalMotionDegree,
    adouble* horizontalMotionCoeff,
    int     helicalMotionDegree,
    adouble* helicalMotionCoeff,
    int     angularMotionDegree,
    adouble* angularMotionCoeff,
    int     modifiedRollDegree,
    adouble* modifiedRollCoeff
) {
    int i;
    adouble ah;

    // Definition der Schneide
    def_messer(z,f,hgR,hgRs,hgYs,hgZs);

    // Position der Schneide am Messerkopf
    // (jetzt die Ber"ucksichtigung von hgKopSpW, hgFlaSpW, hgMeSchW)
    D2T(f,hgMeSchW);     // Messerschwenkwinkel Theta_M
    D3T(f,hgFlaSpW);     // Flankenspanwinkel Theta_F
    D1(f,hgKopSpW);      // Kopfspanwinkel Theta_K
    // Position der Schneide am Messerkopf
    f[0] += hgFlKrRd;    // Flugkreisradius
    f[1] -= hgXmk;       // Messerversatz

    // Messerkopfrotation mit Parameter v
    D3(f,z[1]);

    // Lage des Messerkopfs auf der Wiege
    f[2] -= hgYmk;

    // Beruecksichtigung der Messerkopf-Exzentrizitaet
    f[0] += hgE * cos(hgExzenW);
    f[1] -= hgE * sin(hgExzenW);

    // Eindrehen in Orientierung der Wiege
    ah = f[0];
    f[0] = f[1];
    f[1] = ah;
    f[2] = -f[2];

    // Beruecksichtigung von Messerkopf-Schwenkwinkel hgThetaS
    // und der Messerkopfneigung hgThetaN
    D3T(f,hgThetaS);     // Einschwenken in die Neigungsachse
    D1T(f,hgThetaN);     // Neigung um x-Achse
    D3(f,hgThetaS);      // Rueckschwenken aus der Neigungsachse

    // Verschiebung
    f[0] -= hgXmw;       // FLB1-x-Achse zeigt nach oben     -> (-xNeu)
    f[1] += hgZmw;       // FLB1-z-Achse zeigt nach rechts   ->  (yNeu)
    f[2] += hgYmw;       // FLB1-y-Achse zeigt aus der Wiege ->  (zNeu)

    // Wiegenwinkel thetaW, entspricht dem wert t=0
    D3(f,hgThetaW);

    // ZUSATZBEWEGUNG Radial motion
    if (radialMotionDegree >= 0) {
        ah = 0.0;
        for (i=radialMotionDegree; i>0; i--) {
            ah += radialMotionCoeff[i];
            ah *= z[2];
        }
        ah += radialMotionCoeff[0];
        f[1] += ah;        // radiale Verschiebung des Messerkopfes
    }

    // Wiegenbewegung mit Parameter t
    D3(f,z[2]);

    // ZUSATZBEWEGUNG Vertical motion
    if (verticalMotionDegree >= 0) {
        ah = 0.0;
        for (i=verticalMotionDegree; i>0; i--) {
            ah += verticalMotionCoeff[i];
            ah *= z[2];
        }
        ah += verticalMotionCoeff[0];
        f[0] += ah;        // Achsversatz in positive x-Richtung
    }

    // originaler Achsversatz
    f[0] += hgM;

    // ZUSATZBEWEGUNG Horizontal motion
    if (horizontalMotionDegree >= 0) {
        ah = 0.0;
        for (i=horizontalMotionDegree; i>0; i--) {
            ah += horizontalMotionCoeff[i];
            ah *= z[2];
        }
        ah += horizontalMotionCoeff[0];
        f[1] += ah;        // Achsversatz in positive y-Richtung
    }

    // ZUSATZBEWEGUNG Helical motion
    if (helicalMotionDegree >= 0) {
        ah = 0.0;
        for (i=helicalMotionDegree; i>0; i--) {
            ah += helicalMotionCoeff[i];
            ah *= z[2];
        }
        ah += helicalMotionCoeff[0];
        f[2] -= ah;        // Tiefenposition in negative z-Richtung
    }

    // Eindrehen in Orientierung des Werkrades
    f[0] = -f[0];
    ah = f[1];
    f[1] = -f[2];
    f[2] = -ah;

    // ZUSATZBEWEGUNG Angular motion
    if (angularMotionDegree >= 0) {
        ah = 0.0;
        for (i=angularMotionDegree; i>0; i--) {
            ah += angularMotionCoeff[i];
            ah *= z[2];
        }
        ah += angularMotionCoeff[0];
        D1(f,ah);        // umgekehrte Drehung um die x-Achse
    }

    // Teilkegeloeffnungswinkel delta - y-Achsen entgegengesetzt
    D1(f,hgDelta);

    // neue Verschiebung der Werkradachse
    f[2] += hgZwr; // z-Achse zeigt zu Spitze

    // ZUSATZBEWEGUNG Modified roll
    if (modifiedRollDegree >= 0) {
        ah = 0.0;
        for (i=modifiedRollDegree; i>1; i--) {
            ah += modifiedRollCoeff[i];
            ah *= z[2];
        }
        if (modifiedRollDegree > 0)
            ah += modifiedRollCoeff[1];
        ah += hgOmega;
        ah *= z[2];
        ah += modifiedRollCoeff[0];
    } else {
        ah = hgOmega;
        ah *= z[2];
    }
    ah += hgC*z[1];   // c*v + omega * t
    // gekoppelte Werkraddrehung in Abhaengigkeit von t und v
    D3(f,ah);
}


/*--------------------------------------------------------------------------*/
/*                                                   The interface function */
void tapingVectorFunction( int tag, double* indeps, double* deps ) {
    int i;
    trace_on(tag);
    adouble* activeIndeps = new adouble[indepDim];
    adouble* activeDeps   = new adouble[depDim];
    adouble* aIP = activeIndeps;
    double*  iP  = indeps;
    for (i=0; i<indepDim; i++)
        *aIP++ <<= *iP++;

    i = 3;
    adouble * activeRadMotCoeff = activeIndeps+i;
    i += radMotDegree;
    adouble * activeVerMotCoeff = activeIndeps+i;
    i += verMotDegree;
    adouble * activeHorMotCoeff = activeIndeps+i;
    i += horMotDegree;
    adouble * activeHelMotCoeff = activeIndeps+i;
    i += helMotDegree;
    adouble * activeAngMotCoeff = activeIndeps+i;
    i += angMotDegree;
    adouble * activeModRolCoeff = activeIndeps+i;

    activeGearFunction(
        activeIndeps,
        activeDeps,
        // jetzt kommen die ganzen Parameter
        xmk,    // Messerversatz
        ymk,    // MK-Versatz
        kopspw, // Kopfspanwinkel
        flaspw, // Flankenspanwinkel
        meschw, // Messerschwenkwinkel
        flkrrd, // Flugkreisradius
        e,      // Exzentrizitaet
        exzenw, // Exzentrizitaetswinkel
        thetas, // Messerkopfschwenkung
        thetan, // Messerkopfneigung
        xmw,    // MK-x
        ymw,    // MK-y
        zmw,    // MK-z
        thetaw, // Wiegenwinkel
        m,      // Achsversatz
        zwr,    // Verschiebung Werkradachse
        delta,  // Teilkegeloeffnungswinkel
        omega,  //
        c,
        r,      // Kopfradius
        rs,     // Sphaerikradius
        ys,     // Sphaerik-Mitte-Y
        zs,     // Sphaerik-Mitte-Z
        // jetzt die Zusatzbewegungen
        radMotDegree,
        activeRadMotCoeff,
        verMotDegree,
        activeVerMotCoeff,
        horMotDegree,
        activeHorMotCoeff,
        helMotDegree,
        activeHelMotCoeff,
        angMotDegree,
        activeAngMotCoeff,
        modRolDegree,
        activeModRolCoeff
    );

    aIP = activeDeps;
    iP  = deps;
    for (i=0; i<depDim; i++)
        *aIP++ >>= *iP++;
    trace_off();

    delete [] activeDeps;
    delete [] activeIndeps;
}

#undef _VFUNC_GEAR_C_