davidkleiven / APAL

Alloy Phasefield Abstraction Layer
MIT License
0 stars 0 forks source link

Optimise derivative #25

Closed davidkleiven closed 5 years ago

davidkleiven commented 5 years ago

Currently derivative is performed via local least squares

double TwoPhaseLandau::partial_deriv_conc(double x[]) const{
    const unsigned int N = 5;
    const double dx = 0.05/N;
    double current_conc = x[0]-dx/2.0;
    double concs[N];
    double energies[N];

    for (unsigned int i=0;i<N;i++){
        concs[i] = current_conc;
        x[0] = current_conc;
        current_conc += dx;
        energies[i] = this->evaluate(x);
    }
   return least_squares_slope(concs, energies, N);

Maybe it is faster to calculate the slope via local least squares before, and interpolate the result at runtime.

davidkleiven commented 5 years ago

Difficult to use pre calculations since the derivative depend on all four fields.