How to output user defined variable to the vtu file?

Post processing utility for Elmer

How to output user defined variable to the vtu file?

Postby Jenwel » 28 Aug 2017, 06:20

Hi, Dear Elmer developers

I am a motor designer, and I try to develop my own subroutine to calculate the core loss of the electrical steel.
Now, I do not know how to output the calculated field of core loss into the vtu file, so that it can be visulized in ParaView?

Actually, I have read the source code in the FourierLoss.F90. I only got the hints that the variable may be saved by the codes:
Code: Select all
   CompVarsE % Var => VariableGet( Solver % Mesh % Variables,&
          'Fourier Loss '//TRIM(I2S(icomp))//'e' )


Is that enough to save the data and can be called by the ResultOutputSolve?

Thank you in advance!
Jenwel
Jenwel
 
Posts: 19
Joined: 22 Jun 2017, 07:07

Re: How to output user defined variable to the vtu file?

Postby raback » 28 Aug 2017, 11:28

Hi

The VTU output saves all fields that are not explicitly determined not to be saved. The "Variable % Output" is T or F.

If you write your own solver you can declare a variable there in Solver section keyword
Code: Select all
Variable = myvar

This will be defined where the Solver is active. Any solver can have also other variables that have the same permutation as the primary field determined by
Code: Select all
Exported Variable i = othervar ! i=1,2,3,..


The VariableGet function is used in the code to fetch the pointer to the variable structure by its name.

-Peter
raback
Site Admin
 
Posts: 3139
Joined: 22 Aug 2009, 11:57
Location: Espoo, Finland

Re: How to output user defined variable to the vtu file?

Postby Jenwel » 30 Aug 2017, 06:10

Hi Peter
Thank you so much for your helpful response. It works to creat a new variable in sif file.
However, I find that the defined variable has different size with other mesh variables, i.e. the magnetic vector potential A or flux density.

For instance, in sif file I defined the variable Ph:
Code: Select all
Solver 6 
Equation = CoreLoss
 
Exec Solver = Always
 
Procedure = "CoreLoss" "CoreLossSolver"
 
!Target Variable = "A"

Target Variable = "Magnetic flux density"


Variable = Ph
Exported Variable 1 = Ph

!Linear System Solver = Direct
!Linear System Iterative Method = MUMPS
End


And in the subroutine:
Code: Select all
! Fetch the target field, e.g. magnetic vector potential
  !--------------------------------------------------------------------------
  VarName = GetString(SolverParams,'Target Variable',Found)
  TargetVar => VariableGet( Solver % Mesh % Variables, VarName )
  IF( .NOT. ASSOCIATED( TargetVar ) ) THEN
    CALL Fatal('CoreLossSolver','Target field not present: '//TRIM(VarName) )
  END IF
  NsizeTar = SIZE(TargetVar % Values)

  PhLossVar => VariableGet( Solver % Mesh % Variables,'Ph' )
  IF( .NOT. ASSOCIATED( PhLossVar ) ) THEN
    CALL Fatal('CoreLossSolver','Target field not present: '//TRIM('Ph') )
  END IF
  Nsize = SIZE( PhLossVar % Values )


The value of NsizeTar and Nsize are printed:
Code: Select all
MAIN:
MAIN: -------------------------------------
MAIN:  Time: 5/5   5.0000019999999997E-004
MAIN: Estimated time left:  7.8 seconds
MAIN: -------------------------------------
MAIN:
WARNING:: CheckTimer: Requesting time from non-existing timer: PeriodicProjector
      20 0.2307E-01
      40 0.3281E-02
      60 0.1919E-03
      80 0.1436E-04
     100 0.3003E-05
ComputeChange: NS (ITER=1) (NRM,RELC): (  823.47569      2.7070519     ) :: mgdyn2d
      20 0.8681E-05
      40 0.3745E-05
      60 0.2790E-05
      80 0.2265E-06
ComputeChange: NS (ITER=2) (NRM,RELC): (  699.98129     0.12090379E-01 ) :: mgdyn2d
ComputeChange: NS (ITER=3) (NRM,RELC): (  714.46728     0.13968426E-03 ) :: mgdyn2d
ComputeChange: NS (ITER=4) (NRM,RELC): (  714.46509     0.78288201E-07 ) :: mgdyn2d
ComputeChange: NS (ITER=1) (NRM,RELC): ( 0.16865682      1.9999988     ) :: calcfields
ComputeChange: NS (ITER=2) (NRM,RELC): ( 0.18859387     0.11161379     ) :: calcfields
ComputeChange: NS (ITER=6) (NRM,RELC): ( 0.11993191E-02  2.0000000     ) :: calcfields
ComputeChange: NS (ITER=9) (NRM,RELC): (  545766.69      2.0000000     ) :: calcfields
Peddy(1) =   2.2883254874863018E-002
BField(1) =  -2.1476206474732302E-004
PrevBField(1) =  -2.0149707920361193E-004
Nsize =        6383
NsizeTar =       38112
PhLossVar % Values(1) =   6.0903816507435881E-003
Peddy(1) =   7.3991054147325272E-004
BField(1) =  -2.1476206474732302E-004
PrevBField(1) =  -2.1476206474732302E-004
PhLossVar % Values(1) =   1.1797555160803963E-003
ElmerSolver: *** Elmer Solver: ALL DONE ***
ElmerSolver: The end
SOLVER TOTAL TIME(CPU,REAL):        39.00       39.00
ELMER SOLVER FINISHED AT: 2017/08/30 10:57:40


It makes me confused why the size of the new defined variable "Ph" is only 6383?
Can I also define the size of the user defined variables?

Thank you again!
Jenwel
Jenwel
 
Posts: 19
Joined: 22 Jun 2017, 07:07

Re: How to output user defined variable to the vtu file?

Postby raback » 30 Aug 2017, 11:20

Hi Jenwel,

The AV solver is a complex creature where scalar potential (if present) is associated to nodal degrees of freedom (in H1) and vector potential to the edge degrees of freedom (in Hcurl). It seems that the exported variable omits the latter. Anyways, the edge dofs are not directly easily applicable since you cannot do anything with those before postprocessing.

-Peter
raback
Site Admin
 
Posts: 3139
Joined: 22 Aug 2009, 11:57
Location: Espoo, Finland

Re: How to output user defined variable to the vtu file?

Postby Jenwel » 31 Aug 2017, 06:03

Hi Peter,
Thank you again for your replay.
For the 2D magnetic field, actually I only need the norm value (scalar value) of magnetic flux density of each nodal.
Now, I tried to find corresponding variable Bx and By in MagnetoDynamics2D.F90 or CalcFields.F90, but I am not quite sure about that I have found them.

Can you give me any hints? Maybe I can directly calculate the core loss after the flux density field has been solved.

Now the solvers I used in sif file includes:
Code: Select all
Solver 2
Exec Solver = Always
Equation = MgDyn2D
Variable = A
Procedure = "MagnetoDynamics2D" "MagnetoDynamics2D"

Stabilize = False
 
Partition Local Constraints = Logical True
 
Nonlinear System Compute Change in Scaled System = Logical True
 
Nonlinear System Convergence Measure = Residual

Nonlinear System Convergence Tolerance = 1e-6
 
Nonlinear System Max Iterations = 20
 
Nonlinear System Min Iterations = 1
 
Nonlinear System Relaxation Factor = 1.0
 
Nonlinear System Newton After Iterations = 7

 
Export Lagrange Multiplier = Logical True

 
Linear System Abort Not Converged = False
 
Linear System Solver = Iterative
 
Linear System Iterative Method = GCR
 
Linear System GCR Restart = 500
 
Bicgstabl Polynomial Degree = 4

 
Linear System Preconditioning = ILU4
 
Linear System Max Iterations = 1500
 
Linear System Residual Output = Integer 20
 
Linear System Convergence Tolerance = 1e-7 ! 2.0e-6

 
Mortar BCs Additive = Logical True

End

Solver 3
Exec Solver = Always
Equation = CalcFields
Potential Variable = "A"
Procedure = "MagnetoDynamics" "MagnetoDynamicsCalcFields"
 
Calculate Nodal Forces = Logical True
 
Calculate Magnetic Torque = Logical True

 
Calculate Magnetic Force = Logical True

 
Calculate Current Density = Logical True
 
Calculate Magnetic Vector Potential = Logical True

Frequency = Real $ f

Linear System Solver = Direct
Linear System Iterative Method = MUMPS
End



I am not sure the solver "Bsolver" in MagnetoDynamics2D.F90 is called by the solver "MagnetoDynamicsCalcFields" or other solver?
If not, why the magnetic flux density still can be calculated and saved in the vtu file?

Best Regards
Jenwel
Jenwel
 
Posts: 19
Joined: 22 Jun 2017, 07:07

Re: How to output user defined variable to the vtu file?

Postby raback » 31 Aug 2017, 10:54

Hi Jenwel,

I think the Bsolver may be obsolite and the CalcFields solver computes everything needed also in 2D. The B field should be "Magnetic Flux Density 1" for x-component etc. Of course this is available only after CalcFields has been executed.

What kind of losses are you interested about. There is some work towards Steinmetz type loss models already in the code. Look at module FourierLoss.

-Peter
raback
Site Admin
 
Posts: 3139
Joined: 22 Aug 2009, 11:57
Location: Espoo, Finland

Re: How to output user defined variable to the vtu file?

Postby Jenwel » 31 Aug 2017, 14:34

Hi Peter
Thank you so much for the advices!
I have tried the FourierSolver, but it calculates the loss at least after one or several rotational periods.
Actually, I want to optimize the motor with less calculation cost.
Hence, I tried the time-step method to calculate the hysteresis loss and eddy-current loss in each time-step, based on the reference
"V. Raulin, A. Radun and I. Husain, “Modeling of losses in switched reluctance machines,” IEEE Trans. Ind. Appl., vol. 40, no. 6, pp. 1560-1569, Nov/Dec 2004."
The principle is not very difficult.
If the core loss can be calculated in each time-step, less time steps are requried.

Today, I found the "CalcFields solver" sloves B field and tried to add a subroutine to solve the core loss in CalcFields.F90. A new variable is defined in the Solver 2 of the sif:
Code: Select all
Solver 2
Exec Solver = Always
Equation = MgDyn2D
Variable = A
Exported Variable 1 = -global -dofs 1 P_hys
Procedure = "MagnetoDynamics2D" "MagnetoDynamics2D"
Stabilize = False
Partition Local Constraints = Logical True 
Nonlinear System Compute Change in Scaled System = Logical True 
Nonlinear System Convergence Measure = Residual
Nonlinear System Convergence Tolerance = 1e-6 
Nonlinear System Max Iterations = 20 
Nonlinear System Min Iterations = 1 
Nonlinear System Relaxation Factor = 1.0 
Nonlinear System Newton After Iterations = 7 
Export Lagrange Multiplier = Logical True 
Linear System Abort Not Converged = False 
Linear System Solver = Iterative 
Linear System Iterative Method = GCR
Linear System GCR Restart = 500 
Bicgstabl Polynomial Degree = 4 
Linear System Preconditioning = ILU4 
Linear System Max Iterations = 1500 
Linear System Residual Output = Integer 20 
Linear System Convergence Tolerance = 1e-7 
Mortar BCs Additive = Logical True
End

Solver 3
Exec Solver = Always
Equation = CalcFields
Potential Variable = "A"
Procedure = "MagnetoDynamics" "MagnetoDynamicsCalcFields"
Calculate Nodal Forces = Logical True
Calculate Magnetic Torque = Logical True
Calculate Magnetic Force = Logical True
Calculate Current Density = Logical True
Calculate Magnetic Vector Potential = Logical True
Frequency = Real $ f
Linear System Solver = Direct
Linear System Iterative Method = MUMPS
End

Solver 4
Exec Solver = After timestep
Equation = "ResultOutput"
Procedure = "ResultOutputSolve" "ResultOutputSolver"
Output File Name = case
Output Directory = results_5krpm
Save Geometry Ids = Logical True
Vtu Format = Logical True
End

Solver 5 
Exec Solver = After timestep
Equation = scalars
Procedure = "SaveData" "SaveScalars"
Filename = transient_results.dat
Output Directory = results_5krpm
Variable 1 = Time
End


The "Exported Variable 1 = -global -dofs 1 P_hys" is declared, but the variable is not outputed in the VTU file.
It seems that the defined variable in sif is not linked with the pointer in solver subroutine.
And the calculated results in the subroutine is not linked with the solver variable. So I guess this is the reason why it is not outputed in the VTU file.

Thank you again for your hints. Maybe I should try to call the B field in another defined solver, instead of revising the "CalcFields.F90".
If it works, I will upload the solver code here. In case anyone needs that.
Jenwel
 
Posts: 19
Joined: 22 Jun 2017, 07:07

Re: How to output user defined variable to the vtu file?

Postby raback » 01 Sep 2017, 02:11

Hi

Quick note:

"-global" declares a variable that is like a state variable (as opposed to field variables). So it is just one value over the whole domain (such as time) and is not treated in usual output formats.

-Peter
raback
Site Admin
 
Posts: 3139
Joined: 22 Aug 2009, 11:57
Location: Espoo, Finland

Re: How to output user defined variable to the vtu file?

Postby Jenwel » 01 Sep 2017, 07:07

Hi Peter,
Thank you for the notes!
The core loss can be calculated and saved in VTU now.

I found the Exported Variable should be defined in the Solver section "MagnetoDynamics2D", instead of the defined solver "CoreLossSolver". Otherwise, the size of the exported variable is not as same as other field variables, i.e. magnetic flux density.
the Exported Variable in sif is declared as:
Code: Select all
Equation 1 :: Active Solvers(2) = 2 3
Equation 2 :: Active Solvers(3) = 2 3 6
! Rotation of the rotor at the beginning of each time step
Solver 1
Exec Solver = Before timestep
Equation = MeshDeform
Procedure = "RigidMeshMapper" "RigidMeshMapper"
End

Solver 2
Exec Solver = Always
Equation = MgDyn2D
Variable = A
Procedure = "MagnetoDynamics2D" "MagnetoDynamics2D"

Exported Variable 1 = Ph
Exported Variable 2 = Peddy
Exported Variable 3 = Pcoreloss

Stabilize = False
Partition Local Constraints = Logical True
Nonlinear System Compute Change in Scaled System = Logical True
Nonlinear System Convergence Measure = Residual
Nonlinear System Convergence Tolerance = 1e-6
Nonlinear System Max Iterations = 20
Nonlinear System Min Iterations = 1
Nonlinear System Relaxation Factor = 1.0
Nonlinear System Newton After Iterations = 7
Export Lagrange Multiplier = Logical True
Linear System Abort Not Converged = False
Linear System Solver = Iterative
Linear System Iterative Method = GCR
Linear System GCR Restart = 500
Bicgstabl Polynomial Degree = 4
Linear System Preconditioning = ILU4
Linear System Max Iterations = 1500
Linear System Residual Output = Integer 20
Linear System Convergence Tolerance = 1e-7 ! 2.0e-6
Mortar BCs Additive = Logical True
End

Solver 3
Exec Solver = Always
Equation = CalcFields
Potential Variable = "A"
Procedure = "MagnetoDynamics" "MagnetoDynamicsCalcFields"
! Torque calculation
Calculate Nodal Forces = Logical True
Calculate Magnetic Torque = Logical True
Calculate Magnetic Force = Logical True
Calculate Current Density = Logical True
Calculate Magnetic Vector Potential = Logical True

Frequency = Real $ f

Linear System Solver = Direct
Linear System Iterative Method = MUMPS
End

Solver 4
Exec Solver = After timestep
Equation = "ResultOutput"
Procedure = "ResultOutputSolve" "ResultOutputSolver"
Output File Name = case
Output Directory = results_5krpm
Save Geometry Ids = Logical True
Vtu Format = Logical True
End

Solver 5 
Exec Solver = After timestep
Equation = scalars
Procedure = "SaveData" "SaveScalars"
Filename = transient_results.dat
Output Directory = results_5krpm
Variable 1 = Time
End

Solver 6 
Equation = CoreLoss
Exec Solver = Always
Procedure = "CoreLoss" "CoreLossSolver"
End


The calculated transient core loss of a Switched Reluctance Motor basically agree with that calculated by ANSYS Maxwell, as shown here:

MaxwellCoreLoss.jpg
Core loss calculated by ANSYS Maxwell
MaxwellCoreLoss.jpg (121.57 KiB) Viewed 444 times


ElmerCoreLoss.jpg
Core loss calculated by Elmer
(94.37 KiB) Not downloaded yet


The solver file is not completed. I will try to assemble the total Core Loss of all elements and output them to the dat file.
But the source code is still uploaded, if anyone needs that. It can be compiled by the Elmerf90.

The last but not the least, I would like to thank you again for so many valuable suggestions and hits!

Best Regards
Jenwel
Attachments
CoreLoss.F90
(5.55 KiB) Downloaded 9 times
Jenwel
 
Posts: 19
Joined: 22 Jun 2017, 07:07

Re: How to output user defined variable to the vtu file?

Postby raback » 01 Sep 2017, 15:24

Hi

Nice work!

You will have much nicer looking pictures when you use a DG type of elemental field for the losses and average them within bodies. Most of the fields in CalcFields routine have both options. The standard nodal field will enforce continuity which becomes unphysical at the material interfaces and hence a discontinuous field is usually preferred.

-Peter
raback
Site Admin
 
Posts: 3139
Joined: 22 Aug 2009, 11:57
Location: Espoo, Finland

Next

Return to ElmerPost

Who is online

Users browsing this forum: No registered users and 1 guest

cron