1 /*$Id: e_storag.h,v 1.3 2010-07-16 08:22:01 felix Exp $ -*- C++ -*-
2 * Copyright (C) 2001 Albert Davis
3 * Author: Albert Davis <aldavis@gnu.org>
5 * This file is part of "Gnucap", the Gnu Circuit Analysis Package
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 *------------------------------------------------------------------
22 * "base" class for energy storage elements (L & C)
24 //testing=script,complete 2007.07.13
28 /*--------------------------------------------------------------------------*/
29 //enum METHOD {mTRAPGEAR, mEULER, mTRAP, mGEAR, mTRAPEULER};
30 /*--------------------------------------------------------------------------*/
31 INTERFACE FPOLY1
differentiate(const FPOLY1
* q
, const FPOLY1
* i
, double* time
,
33 /*--------------------------------------------------------------------------*/
34 class INTERFACE STORAGE
: public ELEMENT
{
38 :ELEMENT(), _method_u(meUNKNOWN
), _method_a(mTRAPGEAR
) {}
39 explicit STORAGE(const STORAGE
& p
)
40 :ELEMENT(p
), _method_u(p
._method_u
), _method_a(p
._method_a
) {}
42 public: // override virtual
43 //void precalc_first(); //ELEMENT
44 //void expand(); //COMPONENT
49 virtual void tr_init(double) { unreachable(); }
53 bool tr_needs_eval()const;
54 //void tr_queue_eval() //ELEMENT
55 TIME_PAIR
tr_review();
56 double tr_probe_num(const std::string
&)const;
58 double tr_c_to_g(double c
, double g
)const;
61 const int o
[] = {0, 1, 1, 2, 1, 1};
62 int ord
= o
[_method_a
+1];
63 assert(ord
< OPT::_keep_time_steps
);
64 return min(ord
,ELEMENT::order());
66 double error_factor()const {
67 const double f
[]={1./2., 1./2., 1./12., 1./6., 1./2.};
70 bool uic_now()const {return _sim
->uic_now() && has_ic();}
71 public: // used by commons
72 method_t _method_u
; /* method to use for this part per user */
73 METHOD _method_a
; /* actual integration method (auto) */
75 FPOLY1 _i
[OPT::_keep_time_steps
]; /* deriv of _q */
77 static METHOD method_select
[meNUM_METHODS
][meNUM_METHODS
];
78 void set_ic(double); // protected?? bug??
81 bool has_memory(){return true;}
86 /*--------------------------------------------------------------------------*/
88 // storage should do. I might use this to be sure
89 class INTERFACE STORAGE_HEADLESS
: public STORAGE
{
91 explicit STORAGE_HEADLESS()
93 explicit STORAGE_HEADLESS(const STORAGE_HEADLESS
& p
)
95 ~STORAGE_HEADLESS() {}
99 /*--------------------------------------------------------------------------*/
100 /*--------------------------------------------------------------------------*/
102 // vim:ts=8:sw=2:noet: