Heat source for microwave heating

Numerical methods and mathematical models of Elmer
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: Heat source for microwave heating

Post by kevinarden »

I have lead you astray, the user function gets called for every element and the body force is set by element. I used the pointers for the variables to the current element not the whole model. So the function is not doing what I thought it was doing.
elelel
Posts: 32
Joined: 23 May 2022, 17:37
Antispam: Yes

Re: Heat source for microwave heating

Post by elelel »

Dear Kevin,
Many thanks for your kind and warm help.
So the range of CurrentModel% MaxElementNodes is limited by body force?
Following your tips I tried the "n" in the udf.I used the pointer to Temperature.The results have new changes.

Code: Select all

TempVar => VariableGet(Model % Mesh % Variables,'Temperature')  
  x0 = 0.04
  y0 = 0.0225
  z0 = 0.102
  mindist = HUGE( mindist )       
		   DO l=1,n                   
             jx = Model % Mesh % Nodes % x(l)
             jy = Model % Mesh % Nodes % y(l)
             jz = Model % Mesh % Nodes % z(l)            
             dist = (x0-jx)**2 + (y0-jy)**2 + (z0-jz)**2
             IF( dist < mindist ) THEN
               mindist = dist
               HeatControlNode = l
             END IF
           END DO
  Temp = TempVar% Values(TempVar % Perm(HeatControlNode))
n find nodes 1549,2138,1258,2546,145,2231,2057et al,which is the same with Model% NumberOfNodes.And it can control the overall temperature, though still not very good. the result at 10 sec.
10sec.png
10sec.png (25.88 KiB) Viewed 619 times
Use n for the point, and n for the heat source.

Code: Select all

Poy = Poyvar % Values(Poyvar % Perm(n))
hvar = abs(Poy)/1050
The number of nodes(both use n) remains consistent. Maybe that's why heat sources and HeatControlNode can be linked together?
____________________________________________________________________________________________________________________________
It is worth mentioning that when I use GetScalarLocalSolution to get the temperature,

Code: Select all

ALLOCATE(localTemp(n))
CALL GetScalarLocalSolution(localTemp, 'Temperature')
DO l=1,n
the error occurs.

Code: Select all

Coupled system did not converge
When using a pointer to the temperature, no error occurs.
____________________________________________________________________________________________________________________________
n is so amazing, I can't understand...
I use REAL(KIND=dp) :: Poy receive Poyvar % Values(Poyvar % Perm(n))

Code: Select all

Poy = Poyvar % Values(Poyvar % Perm(n))
Each node has a Poyvar% Values and Poy is just a real type.Shouldn't Poyvar% Values (Poyvar% Perm (n)) be an array?
And I use n in the loop statement.

Code: Select all

DO l=1,n 
The n seems to have become Model% NumberOfNodes.But can not use Model% NumberOfNodes in the loop statement,it can not control the overall temperature. :shock:
I'll try on and tell you again when I have the perfect results.
Best wishes!
Dustin
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: Heat source for microwave heating

Post by kevinarden »

Not sure what n is so I printed it out before the do loop started. The function was called many times and n started out as a low number and it did not find the closest node

n 249
mindist 8.8588960791851460E-005
heatsource 331280.27811461076
HeatControlNode Temperature 293.00000000000000
HeatControlNode 144
HeatControlNode Coordinate 3.0678500000000001E-002 2.1238900000000002E-002 0.10167100000000000

But as the calls to the function continued n grew until it became the number of nodes and it found the correct node

n 20472
mindist 5.2366999405423164E-018
heatsource 137990.08572750143
HeatControlNode Temperature 443.32497410048251
HeatControlNode 14137
HeatControlNode Coordinate 4.0000000000000001E-002 2.2499999999999999E-002 0.10199999999999999
elelel
Posts: 32
Joined: 23 May 2022, 17:37
Antispam: Yes

Re: Heat source for microwave heating

Post by elelel »

Hi Kevin,
Thanks for spending so much time helping me.
I used a finer grid (the maximum potato grid was 0.0006m,the previous one was 0.0008m), and then I got something I didn't want to happen.
According to our results, I think n may not be suitable for loop.Probably too much node, magnified this error.
MaxH0.0006m_10sec.png
MaxH0.0006m_10sec.png (25.14 KiB) Viewed 604 times
I will try the others again.
Best wishes!
Dustin
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Heat source for microwave heating

Post by raback »

Hi,

You should define the control node only once, not for each element. Inside the code this routine is called for each element and their each node. It becomes laborious to every time find the control node. I made the minimal changes here (without even trying to compile).

Nevertheless, I have doubts whether this kind of explicit heat control will suffice. It may easily become unstable as it is not a continuous function of the control temperature. The heat control that is built in uses the an algorithm that by construction scales the heat source optimally. The price is solving one additional heat equation with the controlled source as the r.h.s.

Code: Select all

FUNCTION heatsource(Model, n, dummyArgument) RESULT(ht)
  USE DefUtils
  USE VectorHelmholtzUtils
  IMPLICIT None
  TYPE(Model_t) :: Model
  INTEGER :: n
  REAL(KIND=dp) :: dummyArgument, dt

  TYPE(Variable_t), POINTER :: TmpVar, PoyVar
  REAL(KIND=dp) :: hvar,ht,Poy,tlimit,hcon,mindist,x0,y0,z0,dist,jx,jy,jz,Temp
  INTEGER :: HeatControlNode = 0,l
  REAL(KIND=dp), ALLOCATABLE :: localTemp(:)
  LOGICAL :: Visited = .FALSE.

  SAVE TmpVar, PoyVar, HeatControlNode 

  IF(HeatControlNode == 0) THEN
!get HeatControlNode 
    TempVar => VariableGet(Model % Mesh % Variables,'Temperature')
    Poyvar => VariableGet( Model % Mesh % Variables,'Div Poynting Vector re')
    x0 = 0.04
    y0 = 0.0225
    z0 = 0.102
    mindist = HUGE( mindist )
    DO l=1,Model % Mesh % NumberOfNodes
             jx = Model % Mesh % Nodes % x(l)
             jy = Model % Mesh % Nodes % y(l)
             jz = Model % Mesh % Nodes % z(l)          
             dist = (x0-jx)**2 + (y0-jy)**2 + (z0-jz)**2
             IF( dist < mindist ) THEN
               mindist = dist
               HeatControlNode = l  
             END IF
       if (mindist<=0.00001)exit
    END DO
   END IF  

  Temp = TmpVar % Values(TmpVar % Perm(HeatControlNode))
  
!"Div Poynting Vector re" as the heat source variable
  Poy = Poyvar % Values(Poyvar % Perm(n))

  hvar = abs(Poy)/1050  
  hcon = -4761.9
  tlimit = 600.0
  ht=hcon+hvar
  if (Temp <= tlimit) ht=hcon+hvar
  if(Temp > tlimit)  ht = hcon
  
  PRINT *, "heatsource",ht
  PRINT *, "HeatControlNode Temperature",Temp
  PRINT *, "HeatControlNode",HeatControlNode
  PRINT *, "HeatControlNode Coordinate", Model % Nodes % x(HeatControlNode)&
  , Model % Nodes % y(HeatControlNode), Model % Nodes % z(HeatControlNode)
END FUNCTION heatsource
-Peter
elelel
Posts: 32
Joined: 23 May 2022, 17:37
Antispam: Yes

Re: Heat source for microwave heating

Post by elelel »

Hi Peter,
Thanks for your help.
Because I have two heat sources, one heat source is the reaction heat, assumed to stay open, one is the microwave heating, on / off according to the temperature of a point.This should not be possible by using SmartHeaterControl, right?
I tried your modified udf,still can't control the temperature well.
10sec.png
10sec.png (25.88 KiB) Viewed 595 times
It seems that only n in the loop statement can better control the temperature, although not so good.
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: Heat source for microwave heating

Post by kevinarden »

In Peter's the heatcontrolnode stayed constant but it is not the correct node (closest to the point specified)

HeatControlNode Temperature 293.00000000000000
HeatControlNode 6797
HeatControlNode Coordinate 3.8018700000000002E-002 2.3381599999999999E-002 0.10000000000000001
heatsource 227584.78535594913

This user function started because of the need to have a constant heat source and a variable one, but could only have one heat source.

Body Force 1
Heat Source = 100
Smart Heater Control = True
Smart Heater Temperature = 150.0
Smart Heater Control Point(3) = 0.5 0.5 0.0
End
kevinarden
Posts: 2237
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: Heat source for microwave heating

Post by kevinarden »

The reason it finds the 6797 node as the closest node is that it thinks there are 6797 nodes in the model, when there is actually 20472 nodes in the model.
raback
Site Admin
Posts: 4812
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: Heat source for microwave heating

Post by raback »

Hi

Maybe remove this condition:

Code: Select all

       if (mindist<=0.00001)exit
It may be sloppier than intended since tolerance is just \sqrt(0.00001) ~= 0.003

Is the real-world heat control really just a step function? For me this simple heat control would likely just result to on/off switching that would be timestep-depdendent.

-Peter
elelel
Posts: 32
Joined: 23 May 2022, 17:37
Antispam: Yes

Re: Heat source for microwave heating

Post by elelel »

Thank you Kevin,Peter
In that case( "it thinks there are 6797 nodes in the model"), I directly use DO l=1,9999999

Code: Select all

DO l=1,9999999
             jx = Model % Mesh % Nodes % x(l)
             jy = Model % Mesh % Nodes % y(l)
             jz = Model % Mesh % Nodes % z(l)          
             dist = sqrt((x0-jx)**2 + (y0-jy)**2 + (z0-jz)**2)
             IF( dist < mindist ) THEN
               mindist = dist
               HeatControlNode = l  
             END IF
       if (mindist<=0.01)exit  
    END DO
Manually adjusted for mindist <=0.01.If set to mindist <=0.00001, elmer may report an error because this point could not be found.
I tried this on the 0.001m grid.(The 0.0008m grid calculation is too slow.)
But it still can't control the temperature.(use Peter's udf)
001m,10sec.png
001m,10sec.png (17.85 KiB) Viewed 578 times
Does this mean that the problem is not the node?
I uploaded the 0.001m grid.
001.7z
(574.18 KiB) Downloaded 47 times
In the real world, the temperature control in a microwave heating reactor uses infrared radiation thermometer to measure the temperature of a point. When the temperature is too high, close the microwave source (magnetron), and when the temperature drops, open the magnetron.So this simulation, although not very accurate, unless the time step is particularly small.We did this on Comsol and my task now is to do this simulation with Elmer. :D
We're now simulating a magnified reactor, and I actually have several problems left unsolved with Elmer. :D
I have tried removing

Code: Select all

if (mindist<=0.00001)exit
nothing has changed.
Post Reply