How do I do this?

  • Videogamer555
    22nd Jan 2012 Member 0 Permalink
    I want to do 3 things.

    1. I want to make a particle that will treat each other of the same type as insulators and NOT transfer temperature between them on contact, but will transfer temperature between itself and any other type of particle.

    2. I want to make a particle that will not have any defined temperature by itself, not 0k, not 9999k. It will just be missing the temperature property altogether unless it has been assigned it upon creation (which will be in another function I need to write). In other words I want it to ignore the "heat" field of the elementdata.c and instead use an initial temperature that is assigned to it uppon creation. The particle should ONLY be created via the create_part command, and NOT be placed as a standalone element, because I want to have another element create it that will assign it a specific initial temperature upon creation. This needs to be done upon creation, otherwise it will exchange temperature with the particle that created it based upon the elementdata.c "heat" value, BEFORE it can be reassigned a temperature. I have found that unwanted temperature transfer (based on the elementdata.c "heat" value) takes place even if I assign it a temperature in the very next line of code after the create_part line of code. In other words it MUST NOT have an initial temperature of ANY VALUE based on elementdata.c, and it MUST be assigned a temperature in the very same command that creates it.

    This brings me to point number 3.
    3. The create_part function will need to be modified to pass a temperature variable to the particle that it creates, but have it not always do so (passing temperature will need to be an "overload" of the function) in order to keep it from breaking most of the code in TPT. How do I make this work?


    Can someone give me some assistance with doing these three things?
  • mniip
    22nd Jan 2012 Developer 0 Permalink
    @Videogamer555 (View Post)
    3. create a particle then assign temp manually
    Sup?

    im not c coder, i dont know other
  • Videogamer555
    22nd Jan 2012 Member 0 Permalink

    mniip:

    @Videogamer555 (View Post)
    3. create a particle then assign temp manually
    Sup?

    im not c coder, i dont know other

    I figured someone would make a remark like that. So I've revised my above statements into more lengthy statements that very specifically say what I want to accomplish.
  • pilojo
    22nd Jan 2012 Member 0 Permalink
    @Videogamer555 (View Post)
    2. make heat transfer = 0. Then set up some stuff in the .c file to make it transfer between itself
    3. as mniip said, use create_part then manually set temp...
  • Videogamer555
    22nd Jan 2012 Member 0 Permalink

    pilojo:

    @Videogamer555 (View Post)
    2. make heat transfer = 0. Then set up some stuff in the .c file to make it transfer between itself
    3. as mniip said, use create_part then manually set temp...

    Actually I wanted the oposite. I want it to NOT transfer temp between particles of the same type, but transfer to any OTHER type.

    3. Doesn't work as you said, I tried this first. And I end up with a particle that is at 40degC (above normal temp, as assigne) but the emitter particle is at 10degC (BELOW normal temp). This is because I assigned the particle output to be 40degC but the initial value as defined in elementdata.c is about 5degC (so it actually ABSORBED the temperature of the emitter BEFORE it was assigned to the temperature I wantted it to be). Apparantly internally in TPT code, temperature transfer between particles and code for reading data from elementdata.c is handled BEFORE the command parts[i].temp is handled, so even if I assign it a higher temperature, than that in elementdata.c it will have the UNWANTED TEMPERATURE ABSORBPTION!

    I need to know some very technical details about TPT engine itself so I can fix this glitch. Please help. If any official TPT developer is out there reading this now. PLEASE HELP.
  • jacksonmj
    22nd Jan 2012 Developer 0 Permalink
    create_part sets the temperature of the new particle to ptypes[t].heat. There is no temperature transfer between particles in create_part.

    Example:
    int nr = create_part(-1, x+rx, y+ry, PT_THING);
    if (nr!=-1) { //if a particle was created
    parts[nr].temp = restrict_flt(9999999.0f, MIN_TEMP, MAX_TEMP);
    }


    To prevent transfer of heat between particles of the same element, edit the heat conduction code in powder.c. Look for if (rt&&ptypes[rt].hconduct&&(rt!=PT_HSWC||parts[r>>8].life==10)
    &&(t!=PT_FILT||(rt!=PT_BRAY&&rt!=PT_BIZR&&rt!=PT_BIZRG))
    &&(rt!=PT_FILT||(t!=PT_BRAY&&t!=PT_PHOT&&t!=PT_BIZR&&t!=PT_BIZRG)))

    t is the current element and rt is the element it is conducting heat to.

  • Videogamer555
    22nd Jan 2012 Member 0 Permalink
    I have decided to edit the code for create_part function. Originally it said:
    inline int create_part(int p, int x, int y, int tv)

    I've decided to change it to:
    inline int create_part(int p, int x, int y, int tv, float InitialTemp = 0)

    By assigning it a default value it (in this case 0) it should make it an optional parameter (where if it isn't filled it it is assigned to 0 by default). This should eliminate it breaking the rest of the calls to create_part (as they do NOT include an initial temperature being sent to the function), but it leave open the opertunity to make other calls to the function in my own elements, and those CAN use the InitialTemperature variable.

    I read that about this method of creating optional arguments on this page here.
    http://www.cplusplus.com/forum/general/5098/

    Only one problem. It DOES NOT WORK! It gives me an error!
    When I try:
    inline int create_part(int p, int x, int y, int tv, float InitialTemp = 0)

    It gives me this error!
    C:\codeblocks\PowderCBProj\src\powder.c|688|error: expected ';', ',' or ')' before '=' token|

  • jacksonmj
    22nd Jan 2012 Developer 0 Permalink
    C does not have optional arguments. C++ does, but Powder Toy is written in C at the moment.

    create_part does not need a temperature argument, just set the temperature after the call to create_part. There's about 20 places in the code where this method is used, it works fine.
  • Videogamer555
    22nd Jan 2012 Member 0 Permalink

    jacksonmj:

    C does not have optional arguments. C++ does, but Powder Toy is written in C at the moment.

    create_part does not need a temperature argument, just set the temperature after the call to create_part. There's about 20 places in the code where this method is used, it works fine.


    Any plans to port this to C++ eventually? If so, will Codeblocks still work with it?