Hi everyone,
Thank you in advance for taking the time to read my post. I apologise for bringing C code to a Fortran community but it is necessary to clarify question.
I am currently re-writing my C code for running Quantum Molecular Dynamics simulations in Fortran. In my C code I have essentially taken an OOP approach whereby I define a header file potential.h
#ifndef POTENTIAL_DOT_H
#define POTENTIAL_DOT_H
# include "complex.h"
struct Potential;
struct Potential{
double delta; // parameters
double alpha;
double eps;
double gamma;
double (*func_v)(struct Potential *pot, double *x, unsigned int dim);
void (*func_v12d)(struct Potential *pot, double *x, double *grad, unsigned int dim);
double complex (*func_get_tau)(struct Potential *pot);
};
/* -------------- Construct potential from model systems -------- */
struct Potential *potential_construct(
double (*func_v)(struct Potential *pot, double *x, unsigned int dim),
void (*func_v12)(struct Potential *pot, double *x, double *grad, unsigned int dim),
double complex (*func_get_tau)(struct Potential *pot),
char* potential_name, double param[]);
/* functions to be defined in the model potential*/
double v_v(struct Potential *pot, double *x, unsigned int dim);
void v_vd(struct Potential *pot, double *x, double *grad, unsigned int dim);
/* */
double complex get_tau(struct Potential *pot);
#endif
And then anytime I want to define a new potential I simply include the
header file “potential.h”. For instance, for a Landau-Zener potential:
#include <math.h>
#include "potential.h"
/*
* The Landau-Zener type potential is given in ?
*/
/* Handles construction of potential in the adiabatic representation */
double v_v(struct Potential *pot, double *x, unsigned int dim){
return pot->delta;
}
double v_vd(struct Potential *pot, double *x, unsigned int dim){
return 0.0;
}
double get_tau(struct Potential *pot){
return M_PI * pow(pot->delta,2) / 2 / pot->alpha;
}
I essentially want to do the same in my Fortran code. But which approach is best? An OOP approach or something else? And how should I design the code?