models:adding_analytic_functions
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
models:adding_analytic_functions [2019/02/23 09:51] – ↷ Page moved from adding_analytic_functions to models:adding_analytic_functions daniel | models:adding_analytic_functions [2019/06/20 11:00] (current) – Major update daniel | ||
---|---|---|---|
Line 3: | Line 3: | ||
---- | ---- | ||
- | This howto describes how you can add your own analytic potential function to //potfit//. | + | This page describes how you can add your own analytic potential function to //potfit//. |
- | If you are familiar with C-programming you can continue with the [[#Quick Guide|Quick Guide]]. If you think you need a detailed explanation skip the Quick Guide and go directly | + | First you should choose |
- | to [[#Detailed Guide|Section 2]]. | + | program |
- | + | ||
- | ====== Quick Guide ====== | + | |
- | + | ||
- | ==== Templates ==== | + | |
- | + | ||
- | For your convenience there are templates provided int the source code to create new potentials. | + | |
- | Just copy these templates and adjust the names and parameters to your needs. | + | |
- | You can find the templates in the sourcecode starting with | + | |
- | + | ||
- | < | + | |
- | + | ||
- | and ending with | + | |
- | + | ||
- | < | + | |
==== Things you need to adjust ==== | ==== Things you need to adjust ==== | ||
- | To add a new potential you only have to edit 2 files: | + | To add a new potential you have to edit the following two files in the src/ directory: |
- | * functions.h | + | * functions.itm |
- | * functions.c | + | * functions_impl.c |
- | === functions.h === | + | === functions.itm === |
- | The part of functions.h you have to edit is after the first block of declarations. | + | This file is used to declare your new potential function. The only thing you have |
- | You should choose a unique | + | do is add a new line anywhere which uses the FUNCTION macro. The macro takes two arguments, |
- | program to avoid naming conflicts. In this case we simply call it " | + | the first one being the name of your function |
- | To add the declaration for your potential use something like: | + | parameters |
- | <code c>void example_value(double, double *, double *);</ | + | For our example function " |
- | === functions.c === | + | < |
- | In functions.c you have to make two changes. First you have to add your potential function to the internal | + | Please note that there are **no** quotes around |
- | This is done in the '' | + | |
- | < | + | === functions_impl.c === |
- | The first argument is the name of your potential function | + | The actual definition |
+ | Just add it at the very end of the file if you are not sure where you should put it. | ||
- | Then you have to add your potential | + | The name of the function |
- | It might look like this: | + | For our example function " |
<code c> | <code c> | ||
- | void example_value(double r, double *p, double *f) { | + | void my_function_value(const double r, const double* p, double* f) { |
*f = r * p[[0]] + p[[1]] * sin(r); | *f = r * p[[0]] + p[[1]] * sin(r); | ||
} | } | ||
Line 55: | Line 41: | ||
The parameters passed to this function are: | The parameters passed to this function are: | ||
- | * '' | + | * '' |
- | * '' | + | * '' |
- | * '' | + | * '' |
---- | ---- | ||
Line 63: | Line 49: | ||
====== Detailed Guide ====== | ====== Detailed Guide ====== | ||
- | This howto will guide you through the process of adding a new analytic potential to | + | If you are not too familiar with C programming here are some more details which should |
- | the //potfit// program. | + | with the process |
- | + | ||
- | ===== Step 1 - Editing the file '' | + | |
- | + | ||
- | First you have to open the file functions.h in the potfit directory | + | |
- | favorite editor. Scroll down until you see the template provided to create new potential functions: | + | |
- | <code c> | + | |
- | /* template for new potential function called newpot */ | + | |
- | + | ||
- | /* " | + | |
- | void newpot_value(double, | + | |
- | + | ||
- | /* end of template */ | + | |
- | </ | + | |
- | All you have to do is copy the lines 3 and 4 and paste them above the template. | + | |
- | + | ||
- | Now you have to rename the potential and adjust the comment. Choose | + | |
- | identifier for your potential, consisting of letters, numbers and no special characters ( _ is fine). | + | |
- | For now we call our potential " | + | |
- | + | ||
- | If you are finished with editing functions.h, | + | |
- | <code c> | + | |
- | /* example potential */ | + | |
- | void example_value(double, | + | |
- | + | ||
- | /* template for new potential | + | |
- | + | ||
- | /* " | + | |
- | void newpot_value(double, | + | |
- | + | ||
- | /* end of template */ | + | |
- | </ | + | |
- | Don't forget | + | |
- | + | ||
- | ===== Step 2 - Editing the file '' | + | |
- | + | ||
- | Now you have to open the file functions.c. This time you have to edit | + | |
- | the file at 2 different places. | + | |
- | + | ||
- | ==== functions.c - part I ==== | + | |
- | First scroll down until you find the function | + | |
- | <code c> | + | |
- | void apot_init(void) | + | |
- | </ | + | |
- | This function is used to determine the number of parameters of an analytic | + | |
- | potential and assign the internal functions used. | + | |
- | + | ||
- | To make your potential function available in // | + | |
- | that looks like this: | + | |
- | <code c> | + | |
- | add_pot(example, | + | |
- | </ | + | |
- | Replace '' | + | |
- | + | ||
- | ==== functions.c - part II ==== | + | |
- | + | ||
- | This is the last step and then you can use the new potential. | + | |
- | Now you actually have to tell the program what your potential looks like. | + | |
- | Therefore you have to add a new function that implements your analytic | + | |
- | potential. But as always, there is a template provided, you only have to copy | + | |
- | it. | + | |
- | + | ||
- | Search the file for the following line: | + | |
- | /* template for new function */ | + | |
- | Copy and edit the provided | + | Copy the following |
<code c> | <code c> | ||
/ | / | ||
* | * | ||
- | | + | |
* | * | ||
| | ||
- | void example_value(double r, double *p, double *f) | + | void my_function_value(const double r, const double* p, double* f) |
{ | { | ||
*f = r + p[[0]] + p[[1]]; | *f = r + p[[0]] + p[[1]]; | ||
Line 168: | Line 91: | ||
Suppose we have a potential like | Suppose we have a potential like | ||
- | $$\Phi(r) = \gamma*\exp\left(\frac{-r}{\alpha}\right)*\cos\left(\beta*r\right)$$ | + | $$\phi(r) = \gamma\exp\left(\frac{-r}{\alpha}\right)\cos\left(\beta r\right)$$ |
Then our potential function could look like this, assuming the potential file from above is used | Then our potential function could look like this, assuming the potential file from above is used | ||
<code c> | <code c> | ||
- | void example_value(double r, double *p, double *f) | + | void example_value(const double r, const double* p, double* f) |
{ | { | ||
*f = p[[2]] * exp(-r / p[[0]]) * cos(p[[1]] * r); | *f = p[[2]] * exp(-r / p[[0]]) * cos(p[[1]] * r); | ||
Line 178: | Line 101: | ||
</ | </ | ||
- | ===== Step 3 - recompiling | + | ===== Recompiling |
- | If you are finished with all of the above it's time | + | If you are finished with all of the above it's time to recompile // |
- | to recompile //potfit//. First you should issue a '' | + | simply calling |
- | followed by '' | + | |
- | If you encounter any errors be sure to check the syntax of | + | If you encounter any errors be sure to check the syntax of the lines you changed. |
- | the lines you changed. | + | Usually the compiler will give you some hint what is wrong or where you have to look. |
- | ===== Step 4 - testing | + | ===== Testing |
In order to test the changes you made, you can set the parameter | In order to test the changes you made, you can set the parameter | ||
Line 196: | Line 118: | ||
compare it to your references. | compare it to your references. | ||
- | ====== If you still need help ====== | + | ===== If you still need help ===== |
If you still need help with adding analytic potentials to //potfit//, feel free | If you still need help with adding analytic potentials to //potfit//, feel free | ||
- | to contact the authors | + | to contact the authors |
models/adding_analytic_functions.1550911876.txt.gz · Last modified: 2019/02/23 09:51 by daniel