Body force (heat) using an MATC equation based on coordinates

Numerical methods and mathematical models of Elmer
Post Reply
ricardodeazambuja
Posts: 5
Joined: 24 Aug 2022, 15:08
Antispam: Yes

Body force (heat) using an MATC equation based on coordinates

Post by ricardodeazambuja »

Hi,

I started using Elmer (GUI, command line and pyelmer) less than a month ago and this is my first post here, so I apologize if I failed to find the answer somewhere else (I searched a lot without success).

I am trying something quite simple. It's a block of an ideal material, with an empty hole somewhere inside, all faces have a boundary condition with temperature zero (including the internal hole) and I would like to add a body force (heat) that follows an equation. One use case is to apply the body force at only one point. Here is the code (the full file is attached):

Code: Select all

Body Force 1
  Heat Source = Variable Coordinate; Real MATC "if (sqrt((tx(0)-(80))^2+(tx(1)-(80))^2+(tx(2)-(80))^2)<13) (1); else (0);"
End
My block is 100x100x100, the point is 80 80 80 and if I make the distance above smaller than 13 I get trivial solution zero because the if statement is never true, but any value that actually gets one point where the if statement is true makes the simulation diverge. It makes me feel it's not applying the body force only at that point and, therefore, I misunderstood how this problem should be solved. I tried the same situation, but using a small sphere in the mesh (same position 80 80 80) as the heat source, and it worked, so I suppose the values chosen aren't the problem.

I also tried a boundary with a target coordinate:

Code: Select all

Boundary Condition 3
  Target Coordinates(1,3) = Real 80 80 80
  Temperature = 5000000
End
But it seems to apply the condition to the whole body instead of only one point.

Any suggestion / help towards how to apply a body force on a point / using an MATC expression, etc will be very much appreciated :)
Attachments
box_with_hole.stl
(655.95 KiB) Downloaded 32 times
box_with_hole.msh
(450.12 KiB) Downloaded 36 times
case.sif
(1.87 KiB) Downloaded 32 times
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Body force (heat) using an MATC equation based on coordinates

Post by raback »

Hi

How about

Code: Select all

Boundary Condition 3
  Target Coordinates(1,3) = Real 80 80 80
  Temperature Load = Real 1.0
End
-Peter
ricardodeazambuja
Posts: 5
Joined: 24 Aug 2022, 15:08
Antispam: Yes

Re: Body force (heat) using an MATC equation based on coordinates

Post by ricardodeazambuja »

Thank you for the fast reply!

I deleted the body force and modified the boundary according to your suggestion, but ELMER SOLVER (v 9.0) outputs:

Code: Select all

ERROR:: IterSolve: Numerical Error: System diverged over maximum tolerance.
Without the word "Load" it runs and gives me the same temperature (actually 1.0 up to 1.0000000002219092) everywhere.

BTW, what was the problem with my body force using an expression? I started with this toy example, but I would like to have loads and parameters (e.g. Heat Conductivity) that would vary according to their position.

Thanks again for your help!
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Body force (heat) using an MATC equation based on coordinates

Post by raback »

Hi

Didn't check your mesh but I wonder if you really have BCs 1111 and 3333? ElmerGrid tells you which BCs it created. Without any Dirichlet conditions the value will float. My wild guess is that you fail in convergence because of this.

The "Temperature = 1" BC is not a heat source where as the "Temperature Load = Real 1" is a heat source of one W.

It is usually a bad idea to try to set a point load using some "MATC" and "if"'. Even when succesfull it will compute a lot of expensive conditions (MATC is slo..ow) and end up creating only 1 value somewhere. And you don't know how big your load is without integrating over it. And integrating over a point load is not very clean business.

A prettier use of "MATC" would be just a distributed smooth source extending over so many elements that the gaussian quadratures will do a good job integrating over it.

-Peter
ricardodeazambuja
Posts: 5
Joined: 24 Aug 2022, 15:08
Antispam: Yes

Re: Body force (heat) using an MATC equation based on coordinates

Post by ricardodeazambuja »

Thanks again, your comment about the indices was spot on! I checked the elmergrid.log and it was complaining about the indices 1111, 3333 and 4444 as being too high, therefore it was simply ignoring them. Then I changed those indices to smaller values, loaded the mesh using ElmerGUI to test (before that I was using only pyelmer and gmsh occasionally for visualisation), and I realised the physical groups for my boundaries were not there under Geometry/Boundary. Even worse, when I loaded the mesh converted by ElmerGrid, nothing was showing (and it would segfault if I clicked to check the boundaries). I checked my script and I found the problem was related to this:

Code: Select all

gmsh.option.setNumber("Mesh.SubdivisionAlgorithm", 1)
gmsh.model.mesh.refine()
According to the manual, 0=none, 1=all quadrangles, 2=all hexahedra.
I can use the values 0 or 2, but when I use 1 ElmerGrid has a problem, although it process the mesh and generates the outputs I would expect. Inspecting the output files I can see ElmerGrid didn't show boundaries inside entities.sif, mesh.boundary is empty, and mesh.names only has the volume (without the boundaries). It's funny because when I visualise the mesh using Gmsh it shows the mesh and lists the physical groups. I am attaching both meshes, using SubdivisionAlgorithm 0 (ok) and 1 (ElmerGrid fails).

BTW, after fixing this problem with the mesh the simulation gives me results that are not all zeros (and yes, I will keep in mind your comment about the problems with the integration over one single point), thanks a lot!
Attachments
problematic_mesh_4_elmergrid.msh
(422.59 KiB) Downloaded 31 times
same_mesh_different_SubdivisionAlgorithm.msh
(383.49 KiB) Downloaded 32 times
Rich_B
Posts: 421
Joined: 24 Aug 2009, 20:18

Re: Body force (heat) using an MATC equation based on coordinates

Post by Rich_B »

Hello,

If you start in ElmerGUI by loading the stl file, 'box_with_hole.stl', it loads up with a coarse mesh. Then enter a new mesh size with 'Mesh,Configure', and set the max h to a number such as 10. Then 'Mesh, Remesh', and it should show a nicer mesh. I did the above and then ran the attached sif file, the simulation completed and looks reasonable.

Rich.
Attachments
case.sif
(1.64 KiB) Downloaded 36 times
Rich_B
Posts: 421
Joined: 24 Aug 2009, 20:18

Re: Body force (heat) using an MATC equation based on coordinates

Post by Rich_B »

Hello,

This is interesting, the problematic mesh doesn't load into ElmerGUI the same, if converted by elmergrid and then loaded in ElmerGUI, versus being loaded directly in ElmerGUI.

1) convert then load:

run 'elmergrid 14 2 problematic_mesh_4_elmergrid -autoclean', this will create the mesh files in a sub-folder. Open ElmerGUI, then 'File -> Load Mesh' and select the sub-folder with the converted mesh. It will show up as Body 1, no boundaries, and a blank screen. Select 'View -> Volume Mesh', and the volume elements will show up.

2) load directly:

'File -> Open' to select the msh file, and Body 1 and Boundary 1 will appear, and the surface elements will be displayed.

Note that the first sequence creates a volume mesh with no boundaries. Heat Solver should treat this as a fully insulated boundary, so there is a heat source without a heat sink, and the temperature climbs to infinity.

The second sequence generates a body and a boundary, so one can add a heat source to the body and a heat sink on a boundary, and Heat Solver will find a solution. Using the second sequence, the attached sif file gives a solution, and shows that your MATC expression is working.

The interesting question is why don't both sequence of operations give the same result in ElmerGUI?

Rich.
Attachments
case.sif
(1.81 KiB) Downloaded 37 times
ricardodeazambuja
Posts: 5
Joined: 24 Aug 2022, 15:08
Antispam: Yes

Re: Body force (heat) using an MATC equation based on coordinates

Post by ricardodeazambuja »

I created a github repo with a colab notebook if someone wants to check the full python script:
https://github.com/ricardodeazambuja/el ... playground
ricardodeazambuja
Posts: 5
Joined: 24 Aug 2022, 15:08
Antispam: Yes

Re: Body force (heat) using an MATC equation based on coordinates

Post by ricardodeazambuja »

The problem in the notebook I posted the link here in this thread, depending on the mesh, can give a result where small negative values of temperature are shown. Would anyone have a hint to solve this problem?
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: Body force (heat) using an MATC equation based on coordinates

Post by kevinarden »

Check the solver log to make sure the solver converged, you have it limited to 500 iterations, but it may not have converged.
Post Reply