CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > Siemens > STAR-CCM+

Import table and assign boundary conditions

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 10, 2016, 11:08
Default Import table and assign boundary conditions
  #1
Member
 
Join Date: Nov 2015
Posts: 57
Rep Power: 11
taillanm is on a distinguished road
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
taillanm is offline   Reply With Quote

Old   November 10, 2016, 12:49
Default
  #2
New Member
 
Kevin
Join Date: Oct 2012
Posts: 29
Rep Power: 14
kirrer is on a distinguished road
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!
kirrer is offline   Reply With Quote

Old   November 14, 2016, 07:16
Default
  #3
Member
 
Join Date: Nov 2015
Posts: 57
Rep Power: 11
taillanm is on a distinguished road
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
taillanm is offline   Reply With Quote

Old   November 14, 2016, 14:35
Default
  #4
New Member
 
Kevin
Join Date: Oct 2012
Posts: 29
Rep Power: 14
kirrer is on a distinguished road
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.
kirrer is offline   Reply With Quote

Reply

Tags
csv, table data


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Apply spatial variant pressure distribution on wall boundary jpesich STAR-CCM+ 1 November 3, 2015 22:24
How can i assign a set of data (table or matrix) as an input for source term? reza.s CFX 5 March 2, 2015 21:31
Setting Initial Conditions Velocity Profile lint STAR-CCM+ 7 March 28, 2014 03:46
Using table(x,y,z) to assign different temperatures to a surface. fshak92 STAR-CCM+ 6 February 22, 2012 07:28


All times are GMT -4. The time now is 05:37.