|
|
|
# Custom parameters
|
|
|
|
|
|
|
|
The W-SLDA toolkit provides a framework for creating flexible parametrization of formulas. List of numbers (of double type) that can be passed from an input file to the code is called *custom parameters*. In the input file they start with tag:
|
|
|
|
```bash
|
|
|
|
# Custom parameters
|
|
|
|
params0 0.0 # value of the parameter
|
|
|
|
params1 1.0 # value of the parameter
|
|
|
|
params2 2.0 # value of the parameter
|
|
|
|
# ... and so on ...
|
|
|
|
```
|
|
|
|
Maximal number of parameters is specified in `predefines.h` by macro-variable:
|
|
|
|
```c
|
|
|
|
// Maximal number of parameters in params array
|
|
|
|
#define MAX_USER_PARAMS 32
|
|
|
|
```
|
|
|
|
When the program reads the input file custom parameters are uploaded into `params` array in a such way that *paramsk* is assigned to `params[k]`. Pointer to the array is passed to each user-defined function, for example:
|
|
|
|
```c
|
|
|
|
double v_ext(int ix, int iy, int iz, int it, int spin, double *params, size_t extra_data_size, void *extra_data)
|
|
|
|
{
|
|
|
|
// ADD HERE FORMULA FOR V_ext(r)
|
|
|
|
double V_ext = 0.0;
|
|
|
|
|
|
|
|
return V_ext;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
During the self-iteration process, before `params` array is passed to user-defined functions the array can be processed by function:
|
|
|
|
```c
|
|
|
|
/**
|
|
|
|
* THIS FUNCTION IS CALLED DURING THE SELF-CONSISTENT PROCESS.
|
|
|
|
* After loading params array from input file, the parameters are processed by this routine.
|
|
|
|
* The routine is executed at beginning of each iteration.
|
|
|
|
* @param params array of size MAX_USER_PARAMS with parameters from input file.
|
|
|
|
* @param kF typical Fermi momentum scale of the problem.
|
|
|
|
* kF=referencekF if the referencekF tag is indicated in the input file,
|
|
|
|
* otherwise to kF value is assigned according formula kF=(3*pi^2*n)^{1/3}, where n corresponds to maximal density.
|
|
|
|
* You can also set kF at request in this function using (*kF)=myvalue;
|
|
|
|
* @param mu array with chemical potentials: mu[SPINA] and mu[SPINB].
|
|
|
|
* @param extra_data_size size of extra_data in bytes, if extra_data size=0 the optional data is not uploaded
|
|
|
|
* @param extra_data optional set of data uploaded by load_extra_data()
|
|
|
|
* */
|
|
|
|
void process_params(double *params, double *kF, double *mu, size_t extra_data_size, void *extra_data)
|
|
|
|
{
|
|
|
|
// PROCESS INPUT FILE PARAMETERS
|
|
|
|
|
|
|
|
}
|
|
|
|
```
|
|
|
|
Usage of `process_params( )` allows for parametrization of user-defined functions in terms of dimensionless values, which are typically more intuitive. For example:
|
|
|
|
```bash
|
|
|
|
params2 2.0 # barrier height, in units of chemical potential mu_a
|
|
|
|
```
|
|
|
|
and `process_params( )` converts *params2* into dimensional quantity
|
|
|
|
```c
|
|
|
|
void process_params(double *params, double *kF, double *mu, size_t extra_data_size, void *extra_data)
|
|
|
|
{
|
|
|
|
params[2]*=mu[SPINA]; // convert to dimensional form
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
# Passing external data to user-defined functions
|
|
|
|
To each user-defined function, arbitrary external data can be passed called *extra data*. The extra data is uploading before the self-consistent starts. In order to activate this option user must provide content of functions:
|
|
|
|
```c
|
|
|
|
/**
|
|
|
|
* This function provides size of extra_data array, in bytes.
|
|
|
|
* The extra_data of specified size will be allocated by the main process.
|
|
|
|
* This function is thread-safe.
|
|
|
|
* @param params with input file parameters.
|
|
|
|
* NOTE: the array contains bare input file values, not processed by process_params()!
|
|
|
|
* @return size of the extra_data array that needs to be allocated, if 0 then extra_data will not be allocated.
|
|
|
|
* */
|
|
|
|
size_t get_extra_data_size(double *params)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
and
|
|
|
|
```c
|
|
|
|
/**
|
|
|
|
* This function loads data into extra_data array.
|
|
|
|
* This function is thread-safe.
|
|
|
|
* @param size size of array computed using function get_extra_data_size()
|
|
|
|
* @param extra_data pointer to array that should be filled with data
|
|
|
|
* @param params with input file parameters.
|
|
|
|
* NOTE: the array contains bare input file values, not processed by process_params()!
|
|
|
|
* @return 0 if load is successful, otherwise return error code. If nonzero value is returned the main code will terminate.
|
|
|
|
* */
|
|
|
|
int load_extra_data(size_t size, void *extra_data, double *params)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
# Predefined variables
|
|
|
|
Each variable defined in `predefines.h` is accessible over entire file `problem-definition.h`. User can defined new variable in `predefines.h`, like
|
|
|
|
```c
|
|
|
|
#define MYVALUE 10.0;
|
|
|
|
```
|
|
|
|
which can be next used in user-defined functions:
|
|
|
|
```c
|
|
|
|
double v_ext(int ix, int iy, int iz, int it, int spin, double *params, size_t extra_data_size, void *extra_data)
|
|
|
|
{
|
|
|
|
// ADD HERE FORMULA FOR V_ext(r)
|
|
|
|
double V_ext = MYVALUE; // it will assign value as given in predefines.h
|
|
|
|
|
|
|
|
return V_ext;
|
|
|
|
}
|
|
|
|
``` |
|
|
|
\ No newline at end of file |