Using flow results from OpenFOAM for Heat Transfer

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Using flow results from OpenFOAM for Heat Transfer

mgriffith
I'm working on a 3D heat transfer problem with forced air convection. I have turbulent flow so I need to use OpenFOAM to solve for the velocities. My goal is to find the steady state solution of the air flow velocity and then use those fixed velocities later in my heat transfer simulation. So it is a two step approach. I know that OpenFOAM can only handle a single subdomain which is fine, but later my heat transfer simulation will have multiple subdomains. So my idea was to start with the full geometry and mesh everything and then just delete the part of the grid I didn't need for the OpenFOAM simulation. Lets call the the grid with all of the features the "FullGrid" and the grid with just the air the "AirGrid" in FullGrid the air was subdomain 2, in AirGrid the subdomain is 1, because there is only one and I had to change it to make featool happy. I ran the OpenFOAM sim and I have results, so far so good.

I saved my results as an .fea file. I loaded the fea file and the old FullGrid and ran
fea.grid = FullGrid;
to get my original grid back. However now the solution I have doesn't match up with the grid I have.

So my question is how do I map my solution to the FullGrid. It seems like just an indexing problem, but I don't know the structure of the sol.u variable so I don't know how to fix it.  

As always thank you for your help,

Matt
Reply | Threaded
Open this post in threaded view
|

Re: Using flow results from OpenFOAM for Heat Transfer

Precise Simulation
Administrator
The degree of freedom mapping is generated when "parseprob" is called by the "mapdofbdr" function, and will generate arrays of dof maps for each dependent variable in the "fea.eqn.dofm" field.

https://www.featool.com/doc/feastruct.html#eqn_struct

Each dof map is an array of "n_local_dofs x n_grid_cells" and gives the global dof numbering on each cell (depending on the shape function for the dependent variable, but in the simple case of 1st order nodal basis functions is the same as the fea.grid.c grid cell mapping). The (row) order of the solution vector in "fea.sol.u" follows the dofm maps for each dependent variable in sequence.

So you would have to use this map and compute a reindexing from your partial mesh to your full mesh.
Reply | Threaded
Open this post in threaded view
|

Re: Using flow results from OpenFOAM for Heat Transfer

mgriffith
Ok Thank you for the explanation. It took me a while to understand what was going on. My goal is to take the partial solution that I have and pad it with zeros to make it match the full grid. For example here are some of my dimensions:

Air Only problem
size(fea.grid.c) = 4x905988
size(fea.eqn.dofm{1})  = 4x905988
ndof = 177419
size(fea.sol.u) = 709676x1

I have 4 dependent variables u,v,w,p . When I plot fea.sol.u I can see that the variables are plotted in that order so far everything makes sense. Just to be clear there are 177419 values in a row for u then v,w,and p.

Now when I go back to my full problem here are the sizes:
size(fea.grid.c) = 4x1609726
size(fea.eqn.dofm{1})  = 4x1609726
ndof = 287258


So I know I need to add zeros to fea.sol.u until it is 1149032, or put another way I need to add zeros to each section of fea.sol.u to increase it from 177419 to 287258.

This is where I got stuck until I realized how to figure out where the zeros should go.
The subdomain that I have the solution for is 2 in the full problem so when I run:
size(unique(fea.eqn.dofm{1}(:,fea.grid.s == 2))) = 177419 aha that number is familiar.

So here is a quick script to map a solution from a partial grid back to the full grid assuming the simple case of a 1st order nodal basis function. I didn't spend any time making this work for general cases or provide any error checking. I'm only including this to let Precise Simulation know I figured it out and also to provide guidance in the unlikely event that someone else has the same question.
There are a bunch of hard coded constants and I stored my solution struct in a variable call Solution, but you should get the gist.

clc
fea.sol.u = zeros(1149032,1);
Index = unique(fea.eqn.dofm{1}(:,fea.grid.s == 2));
OldLength = 177419;
NewLength = 1149032/4;
for i =0:3
    fea.sol.u(Index+i*NewLength) = Solution.u((i*OldLength+1):(i*OldLength+OldLength));
end





Reply | Threaded
Open this post in threaded view
|

Re: Using flow results from OpenFOAM for Heat Transfer

Precise Simulation
Administrator
Thank you for providing your solution. As a minor note, depending on your use case you might consider padding with "nan" instead of zeros "0" as solution values with nan will not be plotted (while zeros will be plotted/visualized as zero level of course).