CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   STAR-CCM+ (https://www.cfd-online.com/Forums/star-ccm/)
-   -   Import table and assign boundary conditions (https://www.cfd-online.com/Forums/star-ccm/179902-import-table-assign-boundary-conditions.html)

taillanm November 10, 2016 10:08

Import table and assign boundary conditions
 
Hello all,

I would like to write a macro that loops over each line of an imported table (table has time / temperature / mach / pressure columns and 10 rows) to set up like this my boundary conditions.

Each line of those parameters would correspond to one run and then after i made it run for a certain amount of iterations it would go to the second line and read the data to put them as boundary conditions.

Anyone tried to do this once?

Max

kirrer November 10, 2016 11:49

I've done this using the POI Java libraries to read in spreadsheet data. It's a bit daunting at first (learning a new API and all) but it provides great power. I'd recommend heading to their website to see how the POI library works and go through some examples. Then, you can start making a macro (hopefully you are in an IDE at this point) which does the same and begin debugging in CCM+.

Personally, I've set up 5-10 different cases where I'm using an Excel sheet to drive multiple (unlimited) simulation parameters or I'm using an Excel sheet to drive post processing of a single simulation, but done in a regular/standardized way.

https://poi.apache.org/

If you don't want to go that route, you could use the Java scanner + string split command to loop through a CSV file. That would be easier to set up for a single case, but less powerful for reusing in different cases and also limited in what you can read/write in the table file.

Finally, after re-reading I realized you are asking about using an imported table. I've not accessed imported table lines individually - this may be possible. But you could always "export" an imported table to a CSV, and then loop through it as described above.

Whatever path you choose, let us know so others can learn from your approach! Good luck!

taillanm November 14, 2016 06:16

Hi,

Indeed i used another method that works:

I first import my table and declare variables to get the number of columns and number of rows:
int NumCol = Table.getNumColumns(); // I named my imported table "Table"
int NumRows = Table.getNumRows();

I declare then my variables like: (here only Mach for this example)
double[] Mach;
Mach = new double[NumCol];

Then i loop through my number of columns:
for (i=0; i<NumCol; i++) {
Object Mach_temp = Table.getTableData(i,1); // I assume the Mach column is in the 2nd column of my table
Mach[i] new Double(Mach_temp.toString());

// Now I need to assign this to the field function i created for the mach number

UserFieldFunction fct_Mach = ((UserFieldFunction) sim.getFieldFunctionManager().getFunction("MachFli ght"); //Name of my field fct to be assigned to the inlet boundary here
fct_Mach.setDefinition(Double.toString(Mach[i]));

-> run and save

}

Of course this has to be done for the other parameters: temperature, pressure and time of your table.

Maximilian

kirrer November 14, 2016 13:35

This is a clever way to get access to the data within the table. However, if you want to make a generalized macro, using the POI libraries or even parsing your own CSV file makes it much more powerful. For example, the first row of data could contain only the name of a field function, and each subsequent row could contain the value of that field function for that specific analysis. You can then loop through the Excel file using the POI functions, assign all the values to all the field functions, and run the simulation. You could even write the results back to the same Excel file.

If you want to add more field functions or use the approach for a different problem altogether, just change the Excel file - no need to change the Java macro. Of course, this recommendation requires a bit more setup time in the macro but becomes much more applicable to other simulations.


All times are GMT -4. The time now is 17:06.