lorenzo-rovigatti / oxDNA

A new version of the code to simulate the oxDNA/oxRNA models, now equipped with Python bindings
https://dna.physics.ox.ac.uk/
GNU General Public License v3.0
38 stars 26 forks source link

Modifying existing external force definition #64

Closed TheAutoMan1ac closed 10 months ago

TheAutoMan1ac commented 10 months ago

I am right now trying to change the RepulsiveSphere.cpp file to change the behaviour of the repulsive sphere from keeping elements inside the sphere to keeping them outside.

I just changed the value and potential function to

LR_vector RepulsiveSphere::value(llint step, LR_vector &pos) {
    LR_vector dist = CONFIG_INFO->box->min_image(_center, pos);
    number mdist = dist.module();
    number radius = _r0 + _rate * (number) step;

    std::cout << "Hello World" << std::endl;

    if(mdist >= radius) return LR_vector(0., 0., 0.);   
    else return dist * (_stiff * (1. - radius / mdist));
}

number RepulsiveSphere::potential(llint step, LR_vector &pos) {
    LR_vector dist = CONFIG_INFO->box->min_image(_center, pos);
    number mdist = dist.module();
    number radius = _r0 + _rate * (number) step;

    std::cout << "Hello World"  << std::endl;

    if(mdist >= radius) return 0.;
    else return 1e8;
}

and recompiled oxDNA completely. However, it seems that the repulsiveSphere potential behaves exactly as before (I see elements dragged into the sphere).

I don't think this is a bug but rather me not finding the right code location to change the potential behaviour. Can you tell me if my approach of modifying the potential this way is principally correct?

Best Markus

lorenzo-rovigatti commented 10 months ago

My educated guess is that you are running on the GPU? Because the bit you edited is for CPU simulations.

TheAutoMan1ac commented 10 months ago

Yes it is running on GPU. So I guess I have to make the changes in another file?

lorenzo-rovigatti commented 10 months ago

Yes. All the CUDA stuff is in the src/CUDA folder. In particular, external forces are evaluated in src/CUDA/Backends/CUDA_MD.cuh, in the set_external_forces kernel. Look for the CUDA_REPULSIVE_SPHERE case.

TheAutoMan1ac commented 10 months ago

Thanks for the quick help. After changing it at the correct location it works like a charm.