Forum: Forums topas RSS
INP_File and Run_Number not expanding
rowlesmr #1
Member since Oct 2011 · 159 posts
Group memberships: Members
Show profile · Link to this post
Subject: INP_File and Run_Number not expanding
I'm having some issues on how INP_File and Run_Number are expanded in macros.

I want to write a nice macro to easily do sequential refinements.

What I've got so far is:
macro Sequential_Refinement(numruns, ident, output)
{
    #prm number_of_runs =numruns;
    num_runs #out number_of_runs

    'saves a backup if the run number is zero
    #if Run_Number == 0;
        system_before_save_OUT  {
            copy INP_File##.inp INP_File##.backup
        }
    #endif   
   
    'I want the save each input file with the run number and some other identifier
        '  as the run number is not always unique
    system_before_save_OUT  {
        copy INP_File##.inp INP_File##_##Run_Number##_##ident##.backup
    }
 
   
    'this is to copy the output of the nth file and use it as the input for the (n+1)th file
    out_file = Concat(String(INP_File), ".INP");

    'copies the backup back over the original input file at the end of the run.
        '   This is the bit I'd like to run on stop
    #if Run_Number == number_of_runs-1;
        system_after_save_OUT  {
            copy INP_File##.backup INP_File##.inp
        }
    #endif   
   
   
    'I want to be able to output every parameter on the convergence of
    '  each item in the list
     #m_ifarg output "" #m_else
         out_prm_vals_on_convergence output
     #m_endif
}

but it gets expanded as (using John's tutorial data as an example, and for the first #list entry)
'input file things

#list File_Name Temperature SEQNO {
576460-mac-001_reb_0003.xye    30        576460
576463-mac-001_reb_0003.xye    90        576463
576466-mac-001_reb_0003.xye    150    576466
576469-mac-001_reb_0003.xye    210    576469
576472-mac-001_reb_0003.xye    270    576472
576475-mac-001_reb_0003.xye    330    576475
576478-mac-001_reb_0003.xye    400    576478
576480-mac-001_reb_0003.xye    500    576480
576482-mac-001_reb_0003.xye    600    576482
576484-mac-001_reb_0003.xye    700    576484
576486-mac-001_reb_0003.xye    800    576486
576488-mac-001_reb_0003.xye    900    576488
}
macro file { File_Name(Run_Number) }
Sequential_Refinement(12, file, output.txt)

'input file things
-->

num_runs 12 
system_before_save_OUT { copy INP_File.inp INP_File.backup } 
system_before_save_OUT { copy INP_File.inp INP_File_Run_Number_576460-mac-001_reb_0003.xye.backup }
out_file = Concat(String(al2o3_si_vt_01), ".INP"); 
out_prm_vals_on_convergence output.txt

The INP_File and Run_Number get copied straight across; there is no substitution.

If I set the Sequential_Refinement macro in such a way that it takes zero parameters, then it works, but then I lose all the flexibility.


Matthew
--
Matthew
AlanCoelho #2
Member since Aug 2011 · 238 posts
Group memberships: Members
Show profile · Link to this post
Hi Matthew

Don't know what purpose number_of_runs has; try the following:


macro Sequential_Refinement(numruns, ident, output)
{
    num_runs numruns

    'saves a backup if the run number is zero
    #if Run_Number == 0;
        system_before_save_OUT  {
            copy INP_File##.inp INP_File##.backup
        }
    #endif  
  
    'I want the save each input file with the run number and some other identifier
        '  as the run number is not always unique
    system_before_save_OUT  {
        copy INP_File##.inp INP_File##_##Run_Number##_##ident##.backup
    }
 
  
    'this is to copy the output of the nth file and use it as the input for the (n+1)th file
    out_file = Concat(String(INP_File), ".INP");

    'copies the backup back over the original input file at the end of the run.
        '   This is the bit I'd like to run on stop
    #if Run_Number == numruns-1;
        system_after_save_OUT  {
            copy INP_File##.backup INP_File##.inp
        }
    #endif  
  
  
    'I want to be able to output every parameter on the convergence of
    '  each item in the list
     #m_ifarg output "" #m_else
         out_prm_vals_on_convergence output
     #m_endif
}

cheers
alan
rowlesmr #3
Member since Oct 2011 · 159 posts
Group memberships: Members
Show profile · Link to this post
Hi Alan

number_of_runs was there as left over from something else I was trying.

The main issue was that INP_File and Run_Number weren't being replaced by the input filename or the run number.

I managed to solve it with this:
macro Sequential_Refinement(numruns, ident) { Sequential_Refinement(numruns, ident, , INP_File, Run_Number) }
macro Sequential_Refinement(numruns, ident, output) { Sequential_Refinement(numruns, ident, output, INP_File, Run_Number) }
macro Sequential_Refinement(numruns, ident, output, INPFILE, RUNNUMBER) 'This one would almost never be called directly
{
    num_runs numruns

    'saves a backup of the original input
    #if Run_Number == 0;
        system_before_save_OUT { copy INPFILE##.inp INPFILE##.backup }
    #endif  
  
    'Save each input file with the run number and some other identifier
    system_before_save_OUT { copy INPFILE##.inp INPFILE##_##RUNNUMBER##_##ident##.backup }
 
    'copy the output of the nth file and use it as the input for the (n+1)th file
    out_file = Concat(String(INPFILE), ".INP");

    'restores the original input file. This is what I would like to run automatically on stop or refinement error.
    #if Run_Number == numruns-1;
        system_after_save_OUT { copy INPFILE##.backup INPFILE##.inp }
    #endif  
  
    'output every refined parameter
    #m_ifarg output "" #m_else
        out_prm_vals_on_convergence output
    #m_endif
}



The macro is written with my own placeholders: INPFILE and RUNNUMBER
Sequential_Refinement(numruns, ident, output, INPFILE, RUNNUMBER)

This macro call would almost never be used.

I then have another macro call this macro
macro Sequential_Refinement(numruns, ident, output) { Sequential_Refinement(numruns, ident, output, INP_File, Run_Number) }

Here, I put in the Topas keywords (?) INP_File and Run_Number, and everything gets replaced as I want.


The output call at the end doesn't actually work, as it gets overwritten every time, and you end up with only the results from the last file.
--
Matthew
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Not logged in. · Lost password · Register
This board is powered by the Unclassified NewsBoard software, 20120620-dev, © 2003-2011 by Yves Goergen
Current time: 2018-08-17, 15:31:10 (UTC +00:00)