Computational routine
eng


int_euler_m title

File content


/* Modnumlib Scicos interfacing function
 * Copyright (C) 2009-2011 Alan Layec
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 */
 
/* int_euler_m Scicos discrete integral by euler method block 
 * Type 4 simulation function ver 1.0 - scicoslab 4.3
 * 30 mai 2009 - INRIA - Author : A.Layec
 */

#include <scicos/scicos_block4.h>

/* REVISION HISTORY :
 * $Log$
 */

/* Cette fonction de simulation réalise une intégration discrète
 * du vecteur d'entrée par la méthode d'Euler arrière (dérivée à gauche) :
 * y[k]=h*u[k]+y[k-1]
 * où h est le pas d'intégration, y[k] la sortie,
 * et u[k] l'entrée
 *
 * entrée régulières : u[0..(mu*nu)-1] matrice entrée
 * sorties régulières : y[0..(mu*nu)-1] matrice sortie
 * entrée évènementielle : Instants de déclenchement
 * sortie évènementielle : néant.
 * état discret : oz[0..(mu*nu)-1] états de sortie discrets précédents
 *
 * paramètre réel : rpar[0] pas d'intégration (scalaire)
 */

/*prototype*/
void int_euler_m(scicos_block *block,int flag)
{
  /*déclaration des variables*/
  void *y;
  void *u;
  void *oz;
  SCSREAL_COP *h;
  int i,nu,mu,typu;

  /*récupération de l'adresses des ports réguliers*/
  u=GetInPortPtrs(block,1);
  y=GetOutPortPtrs(block,1);

  /*récupération de l'adresses des états discrets*/
  oz=GetOzPtrs(block,1);

  /*Récupération de la taille du port d'entrée*/
  mu=GetInPortRows(block,1);
  nu=GetInPortCols(block,1);

  /*Récupération du type du port d'entrée*/
  typu=GetInType(block,1);

  /*récupération du pas d'intégration*/
  h=GetRparPtrs(block);

  /*Le flag 1 calcule l'integrale et place le résultat dans le registre y[]*/
  if ((flag==1)) {

    switch (typu)
    {
      case SCSREAL_N : for(i=0;i<nu*mu;i++) {
                         *(((SCSREAL_COP *)y) + i) = *(((SCSREAL_COP *)u) +i)*(*h) + \
                                                     *(((SCSREAL_COP *)oz) +i);
                       }
                       break;

      case SCSCOMPLEX_N : for(i=0;i<2*nu*mu;i++) {
                            *(((SCSREAL_COP *)y) + i) = *(((SCSREAL_COP *)u) +i)*(*h) + \
                                                        *(((SCSREAL_COP *)oz) +i);
                          }
                          break;

      case SCSINT32_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSINT32_COP *)y) + i) = *(((SCSINT32_COP *)u) +i)*(*h) + \
                                                       *(((SCSINT32_COP *)oz) +i);
                        }
                        break;

      case SCSINT16_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSINT16_COP *)y) + i) = *(((SCSINT16_COP *)u) +i)*(*h) + \
                                                       *(((SCSINT16_COP *)oz) +i);
                        }
                        break;

      case SCSINT8_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSINT8_COP *)y) + i) = *(((SCSINT8_COP *)u) +i)*(*h) + \
                                                      *(((SCSINT8_COP *)oz) +i);
                        }
                        break;

      case SCSUINT32_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSUINT32_COP *)y) + i) = *(((SCSUINT32_COP *)u) +i)*(*h) + \
                                                        *(((SCSUINT32_COP *)oz) +i);
                        }
                        break;

      case SCSUINT16_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSUINT16_COP *)y) + i) = *(((SCSUINT16_COP *)u) +i)*(*h) + \
                                                        *(((SCSUINT16_COP *)oz) +i);
                        }
                        break;

      case SCSUINT8_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSUINT8_COP *)y) + i) = *(((SCSUINT8_COP *)u) +i)*(*h) + \
                                                       *(((SCSUINT8_COP *)oz) +i);
                        }
                        break;

    }

  }

  /*le flag 2 place l'état de sortie y dans z*/
  else if ((flag==2)) {

    switch (typu)
    {
      case SCSREAL_N : for(i=0;i<nu*mu;i++) {
                         *(((SCSREAL_COP *)oz) + i) = *(((SCSREAL_COP *)u) +i)*(*h) + \
                                                      *(((SCSREAL_COP *)oz) +i);
                       }
                       break;

      case SCSCOMPLEX_N : for(i=0;i<2*nu*mu;i++) {
                            *(((SCSREAL_COP *)oz) + i) = *(((SCSREAL_COP *)u) +i)*(*h) + \
                                                         *(((SCSREAL_COP *)oz) +i);
                          }
                          break;

      case SCSINT32_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSINT32_COP *)oz) + i) = *(((SCSINT32_COP *)u) +i)*(*h) + \
                                                        *(((SCSINT32_COP *)oz) +i);
                        }
                        break;

      case SCSINT16_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSINT16_COP *)oz) + i) = *(((SCSINT16_COP *)u) +i)*(*h) + \
                                                        *(((SCSINT16_COP *)oz) +i);
                        }
                        break;

      case SCSINT8_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSINT8_COP *)oz) + i) = *(((SCSINT8_COP *)u) +i)*(*h) + \
                                                       *(((SCSINT8_COP *)oz) +i);
                        }
                        break;

      case SCSUINT32_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSUINT32_COP *)oz) + i) = *(((SCSUINT32_COP *)u) +i)*(*h) + \
                                                         *(((SCSUINT32_COP *)oz) +i);
                        }
                        break;

      case SCSUINT16_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSUINT16_COP *)oz) + i) = *(((SCSUINT16_COP *)u) +i)*(*h) + \
                                                         *(((SCSUINT16_COP *)oz) +i);
                        }
                        break;

      case SCSUINT8_N : for(i=0;i<nu*mu;i++) {
                          *(((SCSUINT8_COP *)oz) + i) = *(((SCSUINT8_COP *)u) +i)*(*h) + \
                                                        *(((SCSUINT8_COP *)oz) +i);
                        }
                        break;

    }

  }

}