How to Obtain the Imaginary Part in Helmholtz Equation Simulations with Elmer

Numerical methods and mathematical models of Elmer
IsotoCedex
Posts: 11
Joined: 18 Mar 2024, 09:51
Antispam: Yes

How to Obtain the Imaginary Part in Helmholtz Equation Simulations with Elmer

Post by IsotoCedex »

Hello everyone,

I am working on an acoustic simulation using the Helmholtz equation in Elmer and need help ensuring I am correctly extracting and visualizing both the real and imaginary parts of the wave pressure (Pressure Wave) in my results.

I have set up my simulation to use two degrees of freedom per node, expecting this to allow me to access both the real and imaginary components of my pressure field. Here is the relevant section of my SIF file for the solver:

Code: Select all

Solver 1
  Equation = Helmholtz Equation
  Procedure = "HelmholtzSolve" "HelmholtzSolver"
  Variable = -dofs 2 Pressure Wave
  ...
End
And I have set the boundary conditions to work with specific values for the real and imaginary parts of the wave:

Code: Select all

Boundary Condition 1
  ...
  Pressure Wave 1 = 2
  Pressure Wave 2 = 0
End
However, when reviewing the results in ParaView and in ElmerVTK, only one "Pressure Wave" variable seems to be available, and I am unsure how to explicitly separate or visualize the real and imaginary components.

My questions are:

  • Is there something additional I need to configure in Elmer to ensure both the real and imaginary parts of the wave pressure are correctly calculated and exported?
  • How can I check in the output files from Elmer (e.g., .vtu) that both components are present and accurately calculated?
  • Are there specific steps or recommendations for visualizing these complex components in ParaView or similar visualization software?

I would appreciate any guidance, SIF file configuration examples, or tips on best practices for working with complex fields in Elmer, especially for acoustic applications using the Helmholtz equation.

Thank you in advance for your help!
kevinarden
Posts: 2319
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: How to Obtain the Imaginary Part in Helmholtz Equation Simulations with Elmer

Post by kevinarden »

I think by default it outputs a vector called pressure wave, default paraview shows the magnitude of a vector, but you can select the x, or y part of the vector which I believe corresponds tp pressure wave 1 and pressure wave 2. However if you want to out put the separately with names

Solver 2
Equation = "result output"
Procedure = "ResultOutputSolve" "ResultOutputSolver"
Output File Name = "demo"
Vtu Format = Logical True
Save Geometry IDs = True
Show Variables = True
Scalar Field 1 = Pressure Wave 1
Scalar Field 2 = Pressure Wave 2
End
IsotoCedex
Posts: 11
Joined: 18 Mar 2024, 09:51
Antispam: Yes

Re: How to Obtain the Imaginary Part in Helmholtz Equation Simulations with Elmer

Post by IsotoCedex »

Thanks @kevinarden,

I do not believe that the X and Y components refer to the variables PW1 and PW2. According to ElmerTutorials.pdf, section 17 (17. Helmholtz – 2D – Acoustic Waves – Air in a Cavity), they refer to pressure wave in the x-direction and y-direction.

Reviewing this forum topic Acoustics – Basic Postprocessing With ElmerSolver & Paraview, I have tried to do it as follows with two consecutive simulations, modifying the solver.

For PW1 the solver would be:

Code: Select all

Solver 1
  Equation = Helmholtz Equation
  Variable = -dofs 2 Pressure Wave 1
  Exported Variable 1 = -dofs 2 Pressure Wave 1
  Procedure = "HelmholtzSolve" "HelmholtzSolver"
  Exec Solver = Always
  Stabilize = True
  Optimize Bandwidth = True
  Steady State Convergence Tolerance = 1.0e-5
  Nonlinear System Convergence Tolerance = 1.0e-7
  Nonlinear System Max Iterations = 20
  Nonlinear System Newton After Iterations = 3
  Nonlinear System Newton After Tolerance = 1.0e-3
  Nonlinear System Relaxation Factor = 1
  Linear System Solver = Iterative
  Linear System Iterative Method = BiCGStab
  Linear System Max Iterations = 500
  Linear System Convergence Tolerance = 1.0e-10
  BiCGstabl polynomial degree = 2
  Linear System Preconditioning = ILU0
  Linear System ILUT Tolerance = 1.0e-3
  Linear System Abort Not Converged = False
  Linear System Residual Output = 10
  Linear System Precondition Recompute = 1
End

For PW2 the solver would be:

Code: Select all

Solver 1
  Equation = Helmholtz Equation
  Variable = -dofs 2 Pressure Wave 2
  Exported Variable 1 = -dofs 2 Pressure Wave 2
  Procedure = "HelmholtzSolve" "HelmholtzSolver"
  Exec Solver = Always
  Stabilize = True
  Optimize Bandwidth = True
  Steady State Convergence Tolerance = 1.0e-5
  Nonlinear System Convergence Tolerance = 1.0e-7
  Nonlinear System Max Iterations = 20
  Nonlinear System Newton After Iterations = 3
  Nonlinear System Newton After Tolerance = 1.0e-3
  Nonlinear System Relaxation Factor = 1
  Linear System Solver = Iterative
  Linear System Iterative Method = BiCGStab
  Linear System Max Iterations = 500
  Linear System Convergence Tolerance = 1.0e-10
  BiCGstabl polynomial degree = 2
  Linear System Preconditioning = ILU0
  Linear System ILUT Tolerance = 1.0e-3
  Linear System Abort Not Converged = False
  Linear System Residual Output = 10
  Linear System Precondition Recompute = 1
End
The result is that in PW1 I get the same as in Pressure Wave, and PW2 is "0" in the entire domain.

With these results (PW2=0) I cannot apply formula 12.3 of the ElmerModelsManual.pdf:

Code: Select all

p(t) = Re(P e^(iωt)) = Re(P) cos(ωt) - Im(P) sin(ωt)
Where:
- Re(P) is Pressure Wave 1
- Im(P) is Pressure Wave 2
The objective is to obtain p(t) at various moments of the simulation.

Any suggestions?

Thank you in advance for your help!

IsotoCedex
IsotoCedex
Posts: 11
Joined: 18 Mar 2024, 09:51
Antispam: Yes

Re: How to Obtain the Imaginary Part in Helmholtz Equation Simulations with Elmer

Post by IsotoCedex »

Thanks again @kevinarden,

I've already tried it, but the same thing happens to me with the results of "Pressure Wave 2" and "Pressure Wave 2 flux". In both cases, the result is "0" in the entire domain.

I'm applying it to example 17 from Elmer's tutorial https://www.nic.funet.fi/pub/sci/physic ... orials.pdf.

My modified SIF for Tutorial 17, according to https://www.elmerfem.org/forum/viewtopi ... ure+wave+2 is:

Code: Select all

Header
  CHECK KEYWORDS Warn
  Mesh DB "." "."
  Include Path ""
  Results Directory ""
End

Simulation
  Max Output Level = 5
  Coordinate System = Cartesian
  Coordinate Mapping(3) = 1 2 3
  Simulation Type = Steady state
  Steady State Max Iterations = 1
  Output Intervals(1) = 1
  Solver Input File = case.sif
  Post File = case_1.vtu
End

Constants
  Gravity(4) = 0 -1 0 9.82
  Stefan Boltzmann = 5.67e-08
  Permittivity of Vacuum = 8.8542e-12
  Permeability of Vacuum = 1.25663706e-6
  Boltzmann Constant = 1.3807e-23
  Unit Charge = 1.602e-19
End

Body 1
  Target Bodies(1) = 1
  Name = "Body 1"
  Equation = 1
  Material = 1
End

Solver 1
  Equation = Helmholtz Equation
  Procedure = "HelmholtzSolve" "HelmholtzSolver"
  Variable = -dofs 2 Pressure Wave
  Stabilize = True
  Bubbles = False
  Lumped Mass Matrix = False
  Optimize Bandwidth = True
  Steady State Convergence Tolerance = 1.0e-5
  Nonlinear System Convergence Tolerance = 1.0e-8
  Nonlinear System Max Iterations = 20
  Nonlinear System Newton After Iterations = 3
  Nonlinear System Newton After Tolerance = 1.0e-3
  Nonlinear System Relaxation Factor = 1
  Linear System Solver = Direct
  Linear System Direct Method = Banded
End

Solver 2
  Equation = "flux compute 1"
  Procedure = "FluxSolver" "FluxSolver"
  Calculate Flux = Logical True
  Target Variable = String "Pressure Wave 2"
  Flux Coefficient = String "Heat Conductivity"
  Linear System Solver = Direct
  Linear System Direct Method = Banded
End

Solver 3
  Equation = "flux compute 2"
  Procedure = "FluxSolver" "FluxSolver"
  Calculate Flux = Logical True
  Target Variable = String "Pressure Wave 1"
  Flux Coefficient = String "Heat Conductivity"
  Linear System Solver = Direct
  Linear System Direct Method = Banded
End

Solver 4
  Equation = Result Output
  Procedure = "ResultOutputSolve" "ResultOutputSolver"
  Save Geometry Ids = False
  Output File Name = tube
  Output Format = Vtu
  Scalar Field 1 = Pressure wave 1
  Scalar Field 2 = Pressure wave 2
  Vector Field 1 = Pressure wave 2 flux
  Vector Field 2 = Pressure wave 1 flux
End

Equation 1
  Name = "Helmholtz"
  Angular Frequency = 628.3
  Active Solvers(4) = 1 2 3 4
End

Material 1
  Name = "Material 1"
  Sound damping = 0.0
  Density = 1.224
  Sound speed = 343
End

Boundary Condition 1
  Target Boundaries(1) = 1 
  Name = "Constraint1"
  Wave Flux 2 = 0
  Wave Flux 1 = 1
End

Boundary Condition 2
  Target Boundaries(1) = 2 
  Name = "Constraint2"
  Wave Flux 1 = 0
  Wave Flux 2 = 0
End

Boundary Condition 3
  Target Boundaries(1) = 3 
  Name = "Constraint3"
  Pressure Wave 1 = 2
  Pressure Wave 2 = 0
End
I'm probably not doing something right with the boundary conditions of the noise source (Constraint3).
kevinarden
Posts: 2319
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: How to Obtain the Imaginary Part in Helmholtz Equation Simulations with Elmer

Post by kevinarden »

I noticed Elmer reports
SolveLinearSystem: Solution trivially zero!
when the solution is zero

If I change either Wave flux 2 or Pressure Wave 2, or both, to a non-zero number then there is a solution for both pressure wave 1 and 2
Boundary Condition 1
Target Boundaries(1) = 1
Name = "Constraint1"
Wave Flux 2 = 1
Wave Flux 1 = 1
End

Boundary Condition 2
Target Boundaries(1) = 2
Name = "Constraint2"
Wave Flux 1 = 0
Wave Flux 2 = 0
End

Boundary Condition 3
Target Boundaries(1) = 3
Name = "Constraint3"
Pressure Wave 1 = 2
Pressure Wave 2 = 1
End
Rich_B
Posts: 423
Joined: 24 Aug 2009, 20:18

Re: How to Obtain the Imaginary Part in Helmholtz Equation Simulations with Elmer

Post by Rich_B »

Hello,

Regarding this statement in your previous post:
According to ElmerTutorials.pdf, section 17 (17. Helmholtz – 2D – Acoustic Waves – Air in a Cavity), they refer to pressure wave in the x-direction and y-direction.
As written, the tutorial could be misleading. The tutorial probably should say something more like 'x and y refer to the real and imaginary components of the pressure'.

Rich.
IsotoCedex
Posts: 11
Joined: 18 Mar 2024, 09:51
Antispam: Yes

Re: How to Obtain the Imaginary Part in Helmholtz Equation Simulations with Elmer

Post by IsotoCedex »

Thanks @Rich_B and @kevinarden,

I really appreciate your help.

Sorry for the delay in responding.

I've been looking at other forum topics, in particular https://www.elmerfem.org/forum/viewtopic.php?t=4976 and https://www.elmerfem.org/forum/viewtopic.php?t=4553, that deal with similar problems.

I have come to the conclusion that if the mesh is 2D, the result is the Pressure Wave variable, of vector type, in which it is possible that each component is the real part and the imaginary part respectively.

If the mesh is 3D, Elmer Helmholtz gives the two components separately (pressure wave 1 and pressure wave 2).

Questions:
  • Does it make sense to you?
  • What is the reason why in 2D the result is complex, and in 3D the variables are separated?
  • In which Elmer file can I see the Helmholtz Equation code?
I illustrate it with two images:
- Result of the calculation with 2D mesh:
Result2Dmesh.jpg
Result2Dmesh.jpg (32.81 KiB) Viewed 228 times

- Calculation result with 3D mesh:
Result3Dmesh.jpg
Result3Dmesh.jpg (30.02 KiB) Viewed 228 times
Thanks so much!
IsotoCEDEX
kevinarden
Posts: 2319
Joined: 25 Jan 2019, 01:28
Antispam: Yes

Re: How to Obtain the Imaginary Part in Helmholtz Equation Simulations with Elmer

Post by kevinarden »

https://github.com/ElmerCSC/elmerfem/tr ... rc/modules

scroll down to Helmholtz

For the difference in 2D and 3D I suspect that the two were developed at different times by different programmers and where just not made consistent.
IsotoCedex
Posts: 11
Joined: 18 Mar 2024, 09:51
Antispam: Yes

Re: How to Obtain the Imaginary Part in Helmholtz Equation Simulations with Elmer

Post by IsotoCedex »

Hello again.

I have reviewed this file https://github.com/ElmerCSC/elmerfem/bl ... zSolve.F90, but I cannot find the definition of the boundary conditions or the outputs in it.

Variables "pressure wave", "pressure wave 1"... are not mentioned
Post Reply