ElmerCSC / elmerfem

Official git repository of Elmer FEM software
http://www.elmerfem.org
Other
1.19k stars 320 forks source link

[MagnetoDynamics] Segmentation fault - invalid memory reference #140

Closed thilomaurer closed 6 years ago

thilomaurer commented 6 years ago

Receiving Segfault

...
LoadInputFile: Loading input file: case.sif
Loading user function library: [MagnetoDynamics]...[MagnetoDynamicsCalcFields_Init0]

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7fc00a82cf3a in ???
#1  0x7fc00a82c163 in ???
#2  0x7fc008b256df in ???
#3  0x7fc00b09d3cd in __lists_MOD_listfind
    at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/Lists.F90:1726
#4  0x7fc00b096494 in __lists_MOD_listgetstring
    at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/Lists.F90:2919
#5  0x7fc001a38492 in magnetodynamicscalcfields_init0_
    at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/modules/MagnetoDynamics/CalcFields.F90:140
#6  0x7fc00b0afd82 in __loadmod_MOD_execsolver
    at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/LoadMod.F90:449
#7  0x7fc00b1642a1 in __modeldescription_MOD_loadmodel
    at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/ModelDescription.F90:2129
#8  0x7fc00b5ca909 in elmersolver_
    at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/ElmerSolver.F90:311
#9  0x400ea7 in solver
    at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/Solver.F90:69
#10  0x401152 in main
    at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/Solver.F90:34

GDBing:

LoadInputFile: Loading input file: case.sif
Loading user function library: [MagnetoDynamics]...[MagnetoDynamicsCalcFields_Init0]

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff75923cd in lists::listfind (list=0x2e1, name=..., found=.FALSE., _name=4) at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/Lists.F90:1726
1726           Ptr => List % Head
Missing separate debuginfos, use: dnf debuginfo-install blas-3.8.0-7.fc27.x86_64 lapack-3.8.0-7.fc27.x86_64 libgcc-7.3.1-5.fc27.x86_64 libgfortran-7.3.1-5.fc27.x86_64 libquadmath-7.3.1-5.fc27.x86_64 libstdc++-7.3.1-5.fc27.x86_64
(gdb) frame 3
#3  0x00007ffff75a4d83 in loadmod::execsolver (fptr=140737185497210, model=..., solver=..., dt=0, transient=.FALSE.) at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/LoadMod.F90:449
449             CALL pptr(model, solver, dt, transient)
(gdb) frame 2
#2  0x00007fffedf2d493 in magnetodynamicscalcfields_init0 (model=..., solver=..., dt=0, transient=.FALSE.) at /home/tmaurer/src/elmerfem-build/elmerfem/fem/src/modules/MagnetoDynamics/CalcFields.F90:140
140   pname = ListGetString( Model % Solvers(soln) % Values, 'Mesh', Found )
(gdb) p Model % Solvers(soln)
no such vector element

In fem/src/modules/MagnetoDynamics/CalcFields.F90:97

  DO i=1,Model % NumberOfSolvers    ! NumberOfSolvers=2
   [...]
  END DO
 soln = i            ! soln=3
[...]
  ALLOCATE(Solvers(n+1))                   ! allocates Solvers(1:3)
  Solvers(1:n) = Model % Solvers          ! Model%Solvers still array (1:2)
  Solvers(n+1) % Values => ListAllocate()
  DGSolverParams => Solvers(n+1) % Values
[...]
  Solvers(n+1) % DG = .TRUE.
  Solvers(n+1) % PROCEDURE = 0
  Solvers(n+1) % ActiveElements => NULL()

[...]
  ! next line accesses Model % Solvers(3) => segfault
  pname = ListGetString( Model % Solvers(soln) % Values, 'Mesh', Found )  
  IF(Found) THEN
    CALL ListAddString( DGSolverParams, 'Mesh', pname )
  END IF

Please fix

thilomaurer commented 6 years ago

case.sif:

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
  Timestepping Method = BDF
  BDF Order = 1
  Solver Input File = case.sif
  Post File = case.vtu
End

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

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

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

Solver 1
  Equation = MgDynPost
  Calculate Current Density = True
  Procedure = "MagnetoDynamics" "MagnetoDynamicsCalcFields"
  Discontinuous Bodies = True
  Calculate Electric Field = True
  Calculate Magnetic Field Strength = True
  Calculate Joule Heating = True
  Exec Solver = Before Saving
  Stabilize = True
  Bubbles = False
  Lumped Mass Matrix = False
  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

Solver 2
  Equation = MgDyn
  Procedure = "MagnetoDynamics" "WhitneyAVSolver"
  Exec Solver = Always
  Stabilize = True
  Bubbles = False
  Lumped Mass Matrix = False
  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 = BiCGStabl
  Linear System Max Iterations = 500
  Linear System Convergence Tolerance = 1.0e-10
  BiCGstabl polynomial degree = 4
  Linear System Preconditioning = none
  Linear System ILUT Tolerance = 1.0e-3
  Linear System Abort Not Converged = True
  Linear System Residual Output = 10
  Linear System Precondition Recompute = 1
End

Equation 1
  Name = "Equation 1"
  Active Solvers(2) = 1 2
End

Material 1
  Name = "Copper (generic)"
  Electric Conductivity = 59.59e6
  Heat expansion Coefficient = 16.5e-6
  Relative Permeability = 0.999994
  Relative Permeability = 0.999994
  Heat Conductivity = 401.0
  Sound speed = 3810.0
  Heat Capacity = 385.0
  Mesh Poisson ratio = 0.34
  Density = 8960.0
  Electric Conductivity = 59.59e6
  Poisson ratio = 0.34
  Youngs modulus = 115.0e9
End

Material 2
  Name = "Air (room temperature)"
  Viscosity = 1.983e-5
  Heat expansion Coefficient = 3.43e-3
  Relative Permittivity = 1.00059
  Relative Permeability = 1.00000037
  Relative Permeability = 1.00000037
  Heat Conductivity = 0.0257
  Relative Permittivity = 1.00059
  Sound speed = 343.0
  Heat Capacity = 1005.0
  Density = 1.205
End
juharu commented 6 years ago

Hi Thilo

It seems, that the "CalcFIelds" initailization subroutine requires that the "WhitneyAvSolver" initialization subroutine has already been executed. The initializations as well as the actual solvers are executed in the order of the "Solver" -section numbering in the .sif file.

So changing the "Solver" numbering in the .sif file should be enough to prevent the core dump ?

BR, Juha

From: "Thilo Maurer" notifications@github.com To: "ElmerCSC" elmerfem@noreply.github.com Cc: "Subscribed" subscribed@noreply.github.com Sent: Wednesday, 23 May, 2018 23:50:01 Subject: Re: [ElmerCSC/elmerfem] [MagnetoDynamics] Segmentation fault - invalid memory reference (#140)

case.sif:

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
  Timestepping Method = BDF
  BDF Order = 1
  Solver Input File = case.sif
  Post File = case.vtu
End

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

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

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

Solver 1
  Equation = MgDynPost
  Calculate Current Density = True
  Procedure = "MagnetoDynamics" "MagnetoDynamicsCalcFields"
  Discontinuous Bodies = True
  Calculate Electric Field = True
  Calculate Magnetic Field Strength = True
  Calculate Joule Heating = True
  Exec Solver = Before Saving
  Stabilize = True
  Bubbles = False
  Lumped Mass Matrix = False
  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

Solver 2
  Equation = MgDyn
  Procedure = "MagnetoDynamics" "WhitneyAVSolver"
  Exec Solver = Always
  Stabilize = True
  Bubbles = False
  Lumped Mass Matrix = False
  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 = BiCGStabl
  Linear System Max Iterations = 500
  Linear System Convergence Tolerance = 1.0e-10
  BiCGstabl polynomial degree = 4
  Linear System Preconditioning = none
  Linear System ILUT Tolerance = 1.0e-3
  Linear System Abort Not Converged = True
  Linear System Residual Output = 10
  Linear System Precondition Recompute = 1
End

Equation 1
  Name = "Equation 1"
  Active Solvers(2) = 1 2
End

Material 1
  Name = "Copper (generic)"
  Electric Conductivity = 59.59e6
  Heat expansion Coefficient = 16.5e-6
  Relative Permeability = 0.999994
  Relative Permeability = 0.999994
  Heat Conductivity = 401.0
  Sound speed = 3810.0
  Heat Capacity = 385.0
  Mesh Poisson ratio = 0.34
  Density = 8960.0
  Electric Conductivity = 59.59e6
  Poisson ratio = 0.34
  Youngs modulus = 115.0e9
End

Material 2
  Name = "Air (room temperature)"
  Viscosity = 1.983e-5
  Heat expansion Coefficient = 3.43e-3
  Relative Permittivity = 1.00059
  Relative Permeability = 1.00000037
  Relative Permeability = 1.00000037
  Heat Conductivity = 0.0257
  Relative Permittivity = 1.00059
  Sound speed = 343.0
  Heat Capacity = 1005.0
  Density = 1.205
End 

— You are receiving this because you are subscribed to this thread. Reply to this email directly, [ https://github.com/ElmerCSC/elmerfem/issues/140#issuecomment-391491569 | view it on GitHub ] , or [ https://github.com/notifications/unsubscribe-auth/AKbmSoNcWy3QXA4n2zBuYJ8m-4-ma7EEks5t1ct5gaJpZM4ULKQu | mute the thread ] .

raback commented 6 years ago

I made the CalcFields a little smarter and hence it can now be initialized also before the primary solver.