ADMB Documentation  11.1.1955
 All Classes Files Functions Variables Typedefs Friends Defines
ad_f1b1.h
Go to the documentation of this file.
00001 /*
00002  * $Id: ad_f1b1.h 1730 2014-03-04 01:30:47Z johnoel $
00003  *
00004  * Author: David Fournier
00005  * Copyright (c) 2008-2012 Regents of the University of California
00006  *
00007  * ADModelbuilder and associated libraries and documentations are
00008  * provided under the general terms of the "BSD" license.
00009  *
00010  * License:
00011  *
00012  * Redistribution and use in source and binary forms, with or without
00013  * modification, are permitted provided that the following conditions are
00014  * met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright
00017  * notice, this list of conditions and the following disclaimer.
00018  *
00019  * 2.  Redistributions in binary form must reproduce the above copyright
00020  * notice, this list of conditions and the following disclaimer in the
00021  * documentation and/or other materials provided with the distribution.
00022  *
00023  * 3.  Neither the name of the  University of California, Otter Research,
00024  * nor the ADMB Foundation nor the names of its contributors may be used
00025  * to endorse or promote products derived from this software without
00026  * specific prior written permission.
00027  *
00028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00029  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00030  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00031  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00032  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00033  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00034  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00035  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00036  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00037  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00038  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00039  *
00040  */
00045 #if !defined(__AD_F1B1__)
00046 # define __AD_F1B1__
00047 
00048 #include <fvar.hpp>
00049 
00050   class f1b1_variable;
00051 
00056   class f1b1_variable
00057   {
00058   public:
00059     static  double * f1b1_stack_ptr;
00060     static  double * zeroes;
00061     static int _nvar;
00062     static int nbytes;
00063     double *      u;
00064     double *      udot;      // tangent vector for u
00065     double *      uhat;      // adjoint vector for u
00066     double *      uhatdot;   // adjoint vector for udot
00067 
00068     f1b1_variable();
00069     static void setnvar(int n);
00070     static int nvar(void) { return _nvar;}
00071     static void getzeroes(void);
00072     void initialize();
00073   };
00074 
00079   class f1b1_stack
00080   {
00081   public:
00082     double * ptr;
00083     f1b1_stack(int n) { ptr = new double[n]; }
00084     ~f1b1_stack() { delete ptr; ptr=NULL; deassign();}
00085     void assign(void) { f1b1_variable::f1b1_stack_ptr=ptr;}
00086     void deassign(void) { f1b1_variable::f1b1_stack_ptr=NULL;}
00087   };
00088 
00093   class f1b1_init_data : public f1b1_variable
00094   {
00095   public:
00096     f1b1_init_data();
00097     void kludge(double x,int i){*u=x;udot[i]=1;}
00098   };
00099 
00104   class dep_data
00105   {
00106   public:
00107     f1b1_variable * dep;
00108     dep_data(f1b1_variable * t) { dep=t;}
00109   };
00110 
00111   class single_f1b1_function;
00112   class double_f1b1_function;
00113   class virtual_double_f1b1_function;
00114 
00119   class virtual_f1b1_node
00120   {
00121   public:
00122     virtual f1b1_variable * get_dep(void) =0;
00123   };
00124 
00129   class single_f1b1_node : public virtual_f1b1_node
00130   {
00131   public:
00132     f1b1_variable * dep;
00133     f1b1_variable * ind1;
00134     single_f1b1_function * f;
00135     single_f1b1_node(f1b1_variable * _dep, f1b1_variable * _ind1,
00136       single_f1b1_function * _f) : dep(_dep) , ind1(_ind1), f(_f) {}
00137     virtual f1b1_variable * get_dep(void){return dep;}
00138   };
00139 
00144   class double_f1b1_node : virtual_f1b1_node
00145   {
00146   public:
00147     f1b1_variable * dep;
00148     f1b1_variable * ind1;
00149     f1b1_variable * ind2;
00150     virtual_double_f1b1_function * f;
00151     virtual f1b1_variable * get_dep(void){return dep;}
00152     double_f1b1_node(f1b1_variable * _dep, f1b1_variable * _ind1,
00153       f1b1_variable * _ind2,virtual_double_f1b1_function * _f) : dep(_dep),
00154       ind1(_ind1), ind2(_ind2), f(_f) {}
00155   };
00156 
00161   class single_f1b1_function
00162   {
00163   public:
00164     double (*f)(double);
00165     double (*d1f)(double);
00166     double (*d11f)(double);
00167     single_f1b1_function( double  (*_f)(double), double  (*_d1f)(double),
00168       double  (*_d11f)(double));
00169     single_f1b1_node operator () (virtual_f1b1_node& v);
00170     single_f1b1_node single_f1b1_function::operator ()
00171       (f1b1_init_data& v);
00172   };
00173 
00174   typedef double (*D2f1b1)(double,double);
00175 
00180   class virtual_double_f1b1_function
00181   {
00182   public:
00183   //  virtual double_f1b1_node operator ()
00184   //    (virtual_f1b1_node& v, virtual_f1b1_node& w)=0;
00185   //  virtual double_f1b1_node operator ()
00186   //    (f1b1_init_data& v,f1b1_init_data& w)=0;
00187     virtual void node_evaluate(void)=0;
00188   };
00189 
00194   class double_f1b1_function : public virtual_double_f1b1_function
00195   {
00196   public:
00197     double (*f)(double,double);
00198     double (*d1f)(double,double);
00199     double (*d2f)(double,double);
00200     double (*d11f)(double,double);
00201     double (*d12f)(double,double);
00202     double (*d22f)(double,double);
00203     double_f1b1_function( D2f1b1  _f, D2f1b1  _d1f, D2f1b1  _d2f,
00204       D2f1b1  _d11f, D2f1b1  _d12f, D2f1b1  _d22f) : f(_f), d1f(_d1f),
00205       d2f(_d2f), d11f(_d11f), d12f(_d12f), d22f(_d22f) {}
00206 
00207     double_f1b1_node operator () (virtual_f1b1_node& v,
00208       virtual_f1b1_node& w);
00209     double_f1b1_node operator () (f1b1_init_data& v,f1b1_init_data& w);
00210     void node_evaluate(void);
00211   };
00212 
00217   class plus_function : public virtual_double_f1b1_function
00218   {
00219   public:
00220     //virtual double_f1b1_node operator () (virtual_f1b1_node& v,
00221     //  virtual_f1b1_node& w);
00222 
00223     //virtual double_f1b1_node operator()(f1b1_init_data& v,f1b1_init_data& w);
00224     void node_evaluate(void);
00225   };
00226 
00231   class times_function : public virtual_double_f1b1_function
00232   {
00233   public:
00234     //virtual double_f1b1_node operator () (virtual_f1b1_node& v,
00235     //  virtual_f1b1_node& w);
00236 
00237     //virtual double_f1b1_node operator()(f1b1_init_data& v,f1b1_init_data& w);
00238     void node_evaluate(void);
00239   };
00240 
00241   extern plus_function  f1b1_plus;
00242   extern times_function  f1b1_times;
00243 
00244 #endif