output a compute calculated in loop

Dear lammps users,
In a part of my input file I divide my simulation box to multiple regions (number of regions are {bini}) and for reach region use a different temperature ({tmp}.

label thermostatloop

variable ithermostat loop ${bini}

variable boundary1 equal ({ithermostat}-1)*({binwidth}+${binspace})

variable boundary2 equal ({ithermostat}-1)*({binwidth}+{binspace})+{binwidth}

region region${ithermostat} block EDGE EDGE EDGE EDGE {boundary1} {boundary2} units box

compute temp${ithermostat} nonboundary temp/region region${ithermostat}

variable tmp equal {T_sl}+({ithermostat}-1-{bin_melt})*{G}({binwidth}+{binspace})-{G}*{Vp}({istep}-1)*{n_step}*0.002

fix thermostat${ithermostat} nonboundary temp/rescale 1 {tmp} {tmp} 1.0 1.0

fix_modify thermostat${ithermostat} temp temp${ithermostat}

next ithermostat

jump SELF thermostatloop

The temperatures of all regions will change every few time steps which we is not the subject of this email ( this part is related to change of all temperatures by time : -{G}*{Vp}({istep}-1)*{n_step}0.002. Now I have two questions:
1- In my code I first wanted to define a variable for the temperature of each region as
variable T_ {ithermostat} equal {T_sl}+({ithermostat}-1-{bin_melt})
{Vp}*({istep}-1)*{n_step}*0.002 but in that case in code I had to write fix thermostat{ithermostat} nonboundary temp/rescale 1 { T_ {ithermostat}} { T_ {ithermostat}} 1.0 1.0

That I had problem because I guess lammps did not understand { T_ {ithermostat}}. an it gives the following error:

ERROR on proc 7: Substitution for illegal variable T_${ithermostat (src/input.cpp:545)

Last command: fix thermostat${ithermostat} nonboundary temp/rescale 1 {T_{ithermostat}} {T_{ithermostat}} 1.0 1.0

That’s why I update the variable tmp to set the temperature of each region. Can you think of another way to save the temperature of each region in a separate variable?

2- I would like to output the temperature each region calculated by compute temp${ithermostat} . and in thermo I do not want to manually output the computes as c_temp1 c_temp2 and etc., is there any way to output the computes in a loop?


three comments:

  1. never use fix temp/rescale as a thermostat for any serious simulations.

  2. you are trying to make the LAMMPS script language do complex things that should be done with a real programming/scripting language. you are making your input hard to read and even harder to debug and you are trying to make LAMMPS jump through hoops it was never intended to reach. how about you write a small python script that would generate the corresponding LAMMPS input with the loops made explicit and then include the resulting file.

  3. be careful to not overdo the binning and slicing. keep in mind, that “temperature” is really only well defined for very large systems or when averaging over a long time (for systems in equilibrium) or both. models in the scale of individual particles do not behave like macroscopic (continuous) objects.