/*
   This file belongs to Aeneas. Aeneas is a GNU package released under GPL 3 license.
   This code is a simulator for Submicron 3D Semiconductor Devices. 
   It implements the Monte Carlo transport in 3D tetrahedra meshes
   for the simulation of the semiclassical Boltzmann equation for both electrons.
   It also includes all the relevant quantum effects for nanodevices.

   Copyright (C) 2007 Jean Michel Sellier <sellier@dmi.unict.it>
 
   This program 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 3, or (at your option)
   any later version.

   This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*/

// Created on : 15 june 2007, Siracusa, Jean Michel Sellier
// Last modified : 16 august 2007, Siracusa, Jean Michel Sellier

// all dynamical allocations here...

// allocation of the electrostatic potential V
/*  printf("Allocating memory for the electrostatic potential...\n");
  V = malloc((Ng+1)*sizeof(double));
  if(V==NULL){
    printf("dynamical allocation : not enough memory for V allocation!\n");
    system("PAUSE");
    exit(0);
  }
  Vi = malloc((Ng+1)*sizeof(double));
  if(Vi==NULL){
    printf("dynamical allocation : not enough memory for Vi allocation!\n");
    system("PAUSE");
    exit(0);
  }
  printf("Electrostatic potential allocated.\n\n");*/

// allocation of the electric field x-component
/*  printf("Allocating memory for the x-component of electric field...\n");
  Ex = malloc((Ng+1)*sizeof(double));
  if(Ex==NULL){
    printf("dynamical allocation : not enough memory for Ex allocation!\n");
    system("PAUSE");
    exit(0);
  }
  printf("Ex allocated.\n\n");

// allocation of the electric field y-component
  printf("Allocating memory for the y-component of electric field...\n");
  Ey = malloc((Ng+1)*sizeof(double));
  if(Ey==NULL){
    printf("dynamical allocation : not enough memory for Ey allocation!\n");
    system("PAUSE");
    exit(0);
  }
  printf("Ey allocated.\n\n");

// allocation of the electric field z-component
  printf("Allocating memory for the z-component of electric field...\n");
  Ez = malloc((Ng+1)*sizeof(double));
  if(Ez==NULL){
    printf("dynamical allocation : not enough memory for Ez allocation!\n");
    system("PAUSE");
    exit(0);
  }
  printf("Ez allocated.\n\n");*/

// the following arrays are for the linbcg subroutine
/*  p  = malloc((Ng+2)*sizeof(double));
  if(p==NULL){
     printf("dynamical allocation : not enough memory for p!\n");
     system("PAUSE");
     exit(0);
  }
  pp = malloc((Ng+2)*sizeof(double));
  if(pp==NULL){
     printf("dynamical allocation : not enough memory for pp!\n");
     system("PAUSE");
     exit(0);
  }
  r  = malloc((Ng+2)*sizeof(double));
  if(r==NULL){
     printf("dynamical allocation : not enough memory for r!\n");
     system("PAUSE");
     exit(0);
  }
  rr = malloc((Ng+2)*sizeof(double));
  if(rr==NULL){
     printf("dynamical allocation : not enough memory for rr!\n");
     system("PAUSE");
     exit(0);
  }
  z  = malloc((Ng+2)*sizeof(double));
  if(z==NULL){
     printf("dynamical allocation : not enough memory for z!\n");
     system("PAUSE");
     exit(0);
  }
  zz = malloc((Ng+2)*sizeof(double));
  if(zz==NULL){
     printf("dynamical allocation : not enough memory for zz!\n");
     system("PAUSE");
     exit(0);
  }*/

// allocation of the doping density profile array
  printf("Allocating memory for the doping profile...\n");
  ND = malloc((Ne+1)*sizeof(double));
  if(ND==NULL){
    printf("dynamical allocation : not enough memory for the donor doping profile!\n");
    system("PAUSE");
    exit(0);
  }
  NA = malloc((Ne+1)*sizeof(double));
  if(NA==NULL){
    printf("dynamical allocation : not enough memory for the acceptor doping profile!\n");
    system("PAUSE");
    exit(0);
  }
  printf("Doping profile memory allocated allocated.\n\n");
// allocation of the electron density array
  printf("Allocating memory for the electron density...\n");
  NE = malloc((Ng+1)*sizeof(double));
  if(NE==NULL){
    printf("dynamical allocation : not enough memory for the electron density!\n");
    system("PAUSE");
    exit(0);
  }
  printf("Doping profile memory allocated allocated.\n\n");
// some other allocations...
  EPP = malloc((Ne+1)*sizeof(double));
  if(EPP==NULL){
    printf("dynamical allocation : not enough memory for EPP!\n");
    system("PAUSE");
    exit(0);
  }
  VOLUME = malloc((Ne+1)*sizeof(double));
  if(VOLUME==NULL){
    printf("dynamical allocation : not enough memory for VOLUME!\n");
    system("PAUSE");
    exit(0);
  }
// create the vector b
/*  b = malloc((Ng+1)*sizeof(double)); //b[1..Ng];
  if(!b){
    printf("dynamical allocation : not enought memory for b allocation...\n");
    exit(0);
  }
  printf("The rhs Poisson vector has been allocated with success.\n");
  printf("Matrix global sizes: sizeof(b[%d]) = %d bytes\n\n",
          Ng+1, (Ng+1)*sizeof(double));*/
// create NOELEC array
/*  NOELEC = malloc((Ne+1)*sizeof(int));
  if(NOELEC==NULL){
    printf("dynamical allocation : not enough memory for NOELEC!\n");
    system("PAUSE");
    exit(0);
  }*/
// create VIC array
/*  VIC = malloc((Ng+1)*sizeof(double));
  if(VIC==NULL){
    printf("dynamical allocation : not enough memory for VIC!\n");
    system("PAUSE");
    exit(0);
  }*/
  da = malloc((Ng+1)*sizeof(double));
  if(da==NULL){
     printf("dynamical allocation : not enough memory for da!\n");
     system("PAUSE");
     exit(0);
  }
/*  k=malloc((Ng+1)*sizeof(double));
  if(k==NULL){
    printf("dynamical allocation : not enough memory for allocation for k!\n");
    system("PAUSE");
    exit(0);
  }*/
  XVEL=malloc((Ng+1)*sizeof(double));
  if(XVEL==NULL){
    printf("dynamical allocation : not enough memory for allocation for XVEL!\n");
    system("PAUSE");
    exit(0);
  }
  YVEL=malloc((Ng+1)*sizeof(double));
  if(YVEL==NULL){
    printf("dynamical allocation : not enough memory for allocation for YVEL!\n");
    system("PAUSE");
    exit(0);
  }
  ZVEL=malloc((Ng+1)*sizeof(double));
  if(ZVEL==NULL){
    printf("dynamical allocation : not enough memory for allocation for ZVEL!\n");
    system("PAUSE");
    exit(0);
  }
  ENEL=malloc((Ng+1)*sizeof(double));
  if(ENEL==NULL){
    printf("dynamical allocation : not enough memory for allocation for ENEL!\n");
    system("PAUSE");
    exit(0);
  }
/*  {
   int i;
   resr=malloc((Ng+1)*sizeof(double));
   if(resr==NULL){
     printf("dynamical allocation : not enough memory for allocation for resr!\n");
     system("PAUSE");
     exit(0);
   }
   for(i=0;i<Ng+1;i++){
     resr[i]=malloc((Ng+1)*sizeof(double));
     if(resr[i]==NULL){
       printf("dynamical allocation : not enough memory for allocation for resr[%d]!\n",i);
       system("PAUSE");
       exit(0);
     }
   }
  }*/
/*  {
   int i;
   for(i=0;i<4;i++){
     poids_K[i]=malloc((Ne+1)*sizeof(double));
     if(poids_K[i]==NULL){
       printf("dynamical allocation : not enough memory for allocation for poids_K[%d]!\n",i);
//       system("PAUSE");
       exit(0);
     }
   }
  }*/
/*  { int i;
   for(i=0;i<4;i++) vois[i]=malloc((Ne+1)*sizeof(int)); }*/

/*  sa=malloc(100*(Ne+1)*sizeof(double));
  if(sa==NULL){
   printf("dynamical allocation : not enough memory for allocation for sa!\n");
   system("PAUSE");
   exit(0);
  }*/
/*  ija=malloc(100*(Ne+1)*sizeof(int));
  if(ija==NULL){
   printf("dynamical allocation : not enough memory for allocation for ija!\n");
   system("PAUSE");
   exit(0);
  }*/
  
//  { int i,j;
//   for(i=0;i<3;i++) for(j=0;j<3;j++) inv_jac_K[i][j]=malloc((Ne+1)*sizeof(double)); }

//  P=malloc((NPMAX+1)*sizeof(double));
//  {int i; for(i=0;i<NPMAX+1;i++) P[i]=malloc(10*sizeof(double));}
