Qucs-core  0.0.19
integrator.cpp
Go to the documentation of this file.
00001 /*
00002  * integrator.cpp - integrator class implementation
00003  *
00004  * Copyright (C) 2004, 2005, 2006 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00025 #if HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include <string.h>
00032 
00033 #include "integrator.h"
00034 
00035 // Some definitions for the save-state variables.
00036 #define STATE_SHIFT 3
00037 #define STATE_NUM   8
00038 #define STATE_MASK  7
00039 
00040 namespace qucs {
00041 
00042 // Constructor creates an unnamed instance of the integrator class.
00043 integrator::integrator () : states<nr_double_t> () {
00044   coefficients = NULL;
00045   order = 0;
00046   state = 0;
00047   integrate_func = NULL;
00048   conductor_func = NULL;
00049 }
00050 
00051 /* The copy constructor creates a new instance based on the given
00052    integrator object. */
00053 integrator::integrator (const integrator & c) : states<nr_double_t> (c) {
00054   coefficients = c.coefficients;
00055   order = c.order;
00056   state = c.state;
00057   integrate_func = c.integrate_func;
00058   conductor_func = c.conductor_func;
00059 }
00060 
00061 // Destructor deletes a integrator object.
00062 integrator::~integrator () {
00063 }
00064 
00065 /* The function evaluates the state of the integration-using component
00066    and runs the appropriate integrator function. */
00067 void integrator::integrate (int qstate, nr_double_t cap, nr_double_t& geq,
00068                             nr_double_t& ceq) {
00069   int cstate = qstate + 1;
00070   if (state & MODE_INIT) fillState (qstate, getState (qstate));
00071   (*integrate_func) (this, qstate, cap, geq, ceq);
00072   if (state & MODE_INIT) fillState (cstate, getState (cstate));
00073 }
00074 
00075 /* This function runs the appropriate conductor function. */
00076 void integrator::conductor (nr_double_t cap, nr_double_t& geq) {
00077   (*conductor_func) (this, cap, geq);
00078 }
00079 
00080 } // namespace qucs