Resources for help making a new fix?

Submitted by jtvanlew on Wed, 02/27/2013 - 02:12

Hi everyone,
I've been using LIGGGHTS pretty successfully for a while now and I'm now at the point where I need to make some new fixes to extend the code to my particular research topic. But without any experience at all with c++ I'm struggling mightily. This is a request for general help because on top of not knowing exactly what's going wrong -- I'm not even knowing the right questions to google to find my answers. I'm not looking for someone to help with each line of code, just maybe point me to more specific locations where I can find answers.

Here are my specific problems...

There are a few fixes I'm trying to make, the simplest is one for simulating thermal expansion. I figure it will take as input from the user something like:

fix id group-ID thermalExpansion r0 T0 beta

Then somewhere the simple equation for each particle, i, would be like
rad[i] = r0 * ( 1 + beta * (Temp[i] - T0))

Features for the fix:
* I think the fix should execute after the heat/gran/conduction so that it's using new values of temperature for each particle (although executing with the previous time's temp before integration also seems reasonable).
* The fix should output the new radius to atom data so that the verlet integration has knowledge of the new dimensions

Using other fixes as templates, I believe I can successfully access the inum, ilist, and atom radius. I saw warnings on LAMMPS website about making sure each processor is only working on its local particles but I'm not sure how to heed that warning. I also just copied a snippet from heat/gran for accessing the temperature of pebble i -- but I'm fairly certain it won't work as it stands.

Last and not least, I'm pretty confused at what needs to be in the companion .h file.

With that background -- does anyone have suggestions on what I should do / where I should look? I appreciate any guidance. I'm trying to get up to speed as fast as I can but it'd sure help if someone could hold my hand at the start.

ckloss's picture

ckloss | Wed, 02/27/2013 - 16:55

Hi jtvanlew,

for doing

rad[i] = r0 * ( 1 + beta * (Temp[i] - T0))

you don't need to touch the C++ level, you can do that with fix adapt (which can take variables).

Or you can take fix adapt as starting point and hardcode the radius variation you want to do (which will be a bit more efficient)

In terms of fix programming in general, you are of course invited to visit our upcoming course:
node/34

Cheers
Christoph

jtvanlew | Thu, 02/28/2013 - 22:24

Many thanks for the suggestion! I had tried modifying the example problem of Packing because in it adapt was also used to grow the radius. I gave up because I hadn't read the variable documentation well enough because I thought it woudl only handle scalars and not atom vectors. I didn't want to change all the diameters uniformly, but of course based on their individual temperatures. I thought any atom-specific math had to be done with a whole new fix.

With that figured out this adapt, so far as I can tell, is working beautifully. For completeness: if anyone else searches in the future and has the same problem they want to solve, my solution is as simple as:

#parameters for thermal expansion
variable r0 equal 0.004 # initial/reference particle radius
variable T0 equal 273 # Reference temperature (that the coefficient of expansion is measured to)
variable beta equal 0.0005 # particle's bulk coefficient of linear expansion
variable thermexpandcheck equal 100 # how often to correct the particle radius for expansion
variable temp equal f_Temp # pull out per-particle values of temperature
variable dexpand atom 2*${r0}*(1.+${beta}*(f_Temp-${T0})) # per-particle vector of updated (thermally expanded) diameters
fix grow all adapt ${thermexpandcheck} atom diameter v_dexpand

jon