ViennaSHE 1.3.0
Free open-source semiconductor device simulator using spherical harmonics expansions techniques.
resistor1d-c.c

Simple 1D simulation of a resistor using the C-library libviennashe

/* ============================================================================
Copyright (c) 2011-2022, Institute for Microelectronics,
Institute for Analysis and Scientific Computing,
TU Wien.
-----------------
ViennaSHE - The Vienna Spherical Harmonics Expansion Boltzmann Solver
-----------------
http://viennashe.sourceforge.net/
License: MIT (X11), see file LICENSE in the base directory
=============================================================================== */
#include <stdio.h>
#include <stdlib.h>
/* Main include for libviennashe */
#include "../../libviennashe/include/libviennashe.h"
/* Definition of true and false */
#define FALSE libviennashe_false
#define TRUE libviennashe_true
/* Define the number of points to use for the resistor */
#define POINTSX 51
{
/* Initialize the variables */
char ** names = NULL;
viennashe_index_type num_quan = 0;
/* Get the number of available quantities */
printf("Number of Quanitites: %ld\n", num_quan);
/* Retrieve the quantity names */
names = (char**)malloc(sizeof(char*) * num_quan);
/* Print the names on stdout */
printf("#############################\n");
for (i = 0; i < num_quan; ++i)
{
printf("%3ld: '%s'\n", i, names[i]);
free(names[i]);
}
printf("#############################\n");
/* Do not forget: Free memory! */
free(names); names = NULL;
}
{
/* Initialize the variables */
viennashe_index_type * len = NULL;
double ** values = NULL;
/* First check if there is a quantity named "Electrostatic potential" */
viennashe_has_cell_based_quantity(reg, "Electrostatic potential", &check);
if(check)
{
/* Get the number of cells to preallocate memory */
/* Allocate memory to hold all the values */
/* Retrieve the values */
viennashe_get_cell_based_quantity(reg, "Electrostatic potential", values, len);
/* Print the values to stdout */
for ( i = 0; i < num_cells; ++i)
{
printf("%2ld => ", i);
for ( j = 0; j < len[i]; ++j)
{
printf("%e", values[i][j]);
}
printf("\n");
}
/* Free previously allocated memory */
}
else
{
/* If there is no electrostatic potential print an error message */
printf("Unable to find the electrostatic potential by name ('Electrostatic potential') !\n");
}
}
/*
*
*/
int main()
{
/* Prealloc needed variables */
const double len_x = 1e-6;
const long points_x = POINTSX;
/* Material and doping */
double Nd[POINTSX-1];
double Na[POINTSX-1];
/* Array of cell ids on which to set boundary potentials */
/* Array of boundary potentials */
double bnd_pot[] = { 0.0, 1.0 };
long i = 0;
/* Handles */
viennashe_config conf = NULL;
viennashe_simulator sim = NULL;
/* Init arrays */
Nd[0] = 0;
Nd[points_x-2] = 0;
Na[0] = 0;
Na[points_x-2] = 0;
for (i = 1; i < points_x - 1; i++)
{
Na[i] = 1e7;
Nd[i] = 1e25;
}
/* +++++++++++ */
/* Init ViennaSHE */
/* Create device */
/* Init the device */
/* Create the simulator configuration */
/* Apply standard DD configuration */
/* Get the simulator instance */
/* This is DD, so we do not need to give any inital guess */
/* RUN! */
/* print_potential(dom, reg); */
/* Write solution to CSV files for gnuplot */
viennashe_write_to_gnuplot(reg, "Electrostatic potential", "potential_dd.dat");
viennashe_write_to_gnuplot(reg, "Electron density", "n_dd.dat");
viennashe_write_to_gnuplot(reg, "Hole density", "p_dd.dat");
/* Free the quantity register */
/* A single SHE postprocessing step */
/* Bipolar SHE (n and p) */
/* Get the simulator instance */
/* Transfer DD solution as init guess to SHE */
/* Free memory */
/* RUN SHE! */
/* Get the quantity register for the SHE-simulator */
/* Print some info */
/* Write pot, n and p to CSV files for gnuplot */
viennashe_write_to_gnuplot(reg, "Electrostatic potential", "potential_she.dat");
viennashe_write_to_gnuplot(reg, "Electron density", "n_she.dat");
viennashe_write_to_gnuplot(reg, "Hole density", "p_she.dat");
/* Write the complete SHE result */
/* Write the average carrier energy to file */
viennashe_write_to_gnuplot(reg, "Average electron energy SHE", "n_energy.dat");
/* Free memory */
viennashe_free_simulator(sim); sim = NULL;
viennashe_free_config(conf); conf = NULL;
return (EXIT_SUCCESS);
}
VIENNASHE_EXPORT viennasheErrorCode viennashe_free_config(viennashe_config conf)
@ viennashe_nonlinear_solver_gummel
Definition: config.h:38
VIENNASHE_EXPORT viennasheErrorCode viennashe_config_standard_dd(viennashe_config conf)
VIENNASHE_EXPORT viennasheErrorCode viennashe_set_nonlinear_solver_config(viennashe_config conf, viennashe_nonlinear_solver_id sol_id, long max_iters, double damping)
VIENNASHE_EXPORT viennasheErrorCode viennashe_config_she_bipolar(viennashe_config conf, libviennashe_bool with_traps)
VIENNASHE_EXPORT viennasheErrorCode viennashe_create_config(viennashe_config *conf)
viennashe_config_impl * viennashe_config
Definition: config.h:31
VIENNASHE_EXPORT viennasheErrorCode viennashe_free_device(viennashe_device dev)
VIENNASHE_EXPORT viennasheErrorCode viennashe_set_contact_potential_cells(viennashe_device dev, viennashe_index_type *cell_ids, double *values, viennashe_index_type len)
VIENNASHE_EXPORT viennasheErrorCode viennashe_create_1d_device(viennashe_device *dev, double len_x, size_t points_x)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_num_cells(viennashe_device dev, viennashe_index_type *num)
VIENNASHE_EXPORT viennasheErrorCode viennashe_initalize_device(viennashe_device dev, viennashe_material_id *material_ids, double *doping_n, double *doping_p)
VIENNASHE_EXPORT viennasheErrorCode viennashe_finalize(void)
Finalizes ViennaSHE.
VIENNASHE_EXPORT viennasheErrorCode viennashe_initalize(void)
Initializes ViennaSHE. To be called before ViennaSHE is used.
long viennashe_material_id
Definition: material.h:26
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_metal_id(viennashe_material_id *id)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_silicon_id(viennashe_material_id *id)
int points_x
Definition: resistor.py:39
conf_dd
Create the simulator configuration.
Definition: resistor.py:72
list Nd
Definition: resistor.py:59
list bnd_cells
Definition: resistor.py:64
sim_dd
Apply standard DD configuration.
Definition: resistor.py:79
int len_x
Definition: resistor.py:38
list bnd_pot
Definition: resistor.py:65
reg
This is DD, so we do not need to give any inital guess.
Definition: resistor.py:84
list matids
Definition: resistor.py:54
VIENNASHE_EXPORT viennasheErrorCode viennashe_write_to_gnuplot(viennashe_quan_register reg, char const *name, char const *filename)
VIENNASHE_EXPORT viennasheErrorCode viennashe_write_she_results_to_gnuplot(viennashe_quan_register reg, viennashe_carrier_ids ctype, char const *filename)
viennashe_quan_register_impl * viennashe_quan_register
Definition: quantity.h:31
VIENNASHE_EXPORT viennasheErrorCode viennashe_free_quantity_register(viennashe_quan_register reg)
VIENNASHE_EXPORT viennasheErrorCode viennashe_has_cell_based_quantity(viennashe_quan_register reg, char const *name, libviennashe_bool *exists)
VIENNASHE_EXPORT viennasheErrorCode viennashe_create_quantity_register(viennashe_quan_register *reg, viennashe_simulator sim)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_cell_based_quantity_list(viennashe_quan_register reg, char **names)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_cell_based_quantity(viennashe_quan_register reg, char const *name, double **values, viennashe_index_type *len)
VIENNASHE_EXPORT viennasheErrorCode viennashe_prealloc_cell_based_quantity(viennashe_device dev, double ***uarray, viennashe_index_type **len)
@ viennashe_hole_id
Definition: quantity.h:34
@ viennashe_electron_id
Definition: quantity.h:34
VIENNASHE_EXPORT viennasheErrorCode viennashe_free_cell_based_quantity(viennashe_device dev, double ***uarray, viennashe_index_type **len)
VIENNASHE_EXPORT viennasheErrorCode viennashe_get_num_cell_based(viennashe_quan_register reg, viennashe_index_type *num)
void print_quan_info(viennashe_quan_register reg)
Prints the names of the available quantities in a register
Definition: resistor1d-c.c:31
#define POINTSX
Definition: resistor1d-c.c:28
void print_potential(viennashe_device dev, viennashe_quan_register reg)
Prints the electrostatic potential profile to stdout
Definition: resistor1d-c.c:60
#define FALSE
Definition: resistor1d-c.c:24
int main()
Definition: resistor1d-c.c:108
VIENNASHE_EXPORT viennasheErrorCode viennashe_run(viennashe_simulator sim)
VIENNASHE_EXPORT viennasheErrorCode viennashe_set_initial_guess_from_other_sim(viennashe_simulator sim, viennashe_simulator other_sim)
VIENNASHE_EXPORT viennasheErrorCode viennashe_free_simulator(viennashe_simulator sim)
VIENNASHE_EXPORT viennasheErrorCode viennashe_create_simulator(viennashe_simulator *sim, viennashe_device dev, viennashe_config conf)
Internal C++ to C wrapper for the device. Has typedefs and destructor.
Internal C++ to C wrapper for the simulator. Has typedefs and destructor.
libviennashe_bool
Definition: sys.h:31
unsigned long viennashe_index_type
Definition: sys.h:42