simple adaptive meshing and MATC parameters, 2D steady state

Elmer cases by the users for the users
Post Reply
NJank
Posts: 99
Joined: 05 Dec 2009, 00:05
Location: Baltimore, MD, USA

simple adaptive meshing and MATC parameters, 2D steady state

Post by NJank »

This example uses heating of a rectangular block of metal with a coarse mesh. The heatsource is constricted, so mesh refinement is needed around it. This is done using Elmersolver's automatic RGB triangle splitting technique.

In addition, the example uses MATC parameters in the grid file to allow you to adjust the mesh density and heat source geometry. Any MATC variables or calculations are enclosed in $. Comments in the files are noted with exclamation points (!).

As a steady state simulation, Elmer Post can be used to view the final solution. Note that you cannot currently use ElmerPost to view adaptive meshes for transient simulations, as it does not save changing mesh condition for each timestep in EP format. The SaveLine function also has issues with the mesh changing between iterations. For a transient simulation, you can use the SaveScalars function with a list of points to get temperatures at certain locations for each timestep. You can also use ResultOutputSolver to save the results in a format that stores each mesh iteration, such as VTU format. Other postprocessors, such as ParaView and VisIt can view these results. The VTU output commands are included in this example as Solver 2.

-----------------
PROCEDURE (running elmersolver from the command line, assuming elmer files are in the system Path):
-----------------

- Create a new folder and save the adapt.grd and adapt.sif to it.

- Create the base mesh:
elmergrid 1 2 adapt

- Run the solver:
elmersolver adapt.sif

Viewing Results with Elmerpost:
you can use Elmerpost to view the results in several ways
1) view the adapt.ep file in the adapt subfolder. this is based on the initial mesh, and will have a coarser output. I believe the solution shown is the projection of the final solution on the initial mesh **confirmation requested**
2) view the adapt.ep files in the various "RefinedMesh#" folders. The program only makes 10 folders, and then reuses them. The one with highest mesh density, and usually the largest filesize will be the last one containing the final refined result. Note the much higher mesh refinement around the heat source. The maximum temperature is also slightly higher, as this better captured the peak temperature.
EPcoarse.jpg
EPcoarse.jpg (63.55 KiB) Viewed 13059 times
EPrefined.jpg
EPrefined.jpg (82.98 KiB) Viewed 13059 times
Viewing Result in VisIt:
1) in the vtuoutput folder will be a single vtu file. Open visit and select this file as the Source to open. Under Plots, select Add, Mesh, mesh. Then Draw. Select Add, Pseudocolor, Temperature. Then Draw.
2) You can change the VTU output to show each 'timestep' (or steady state iteration) by changing "after all" to "after timestep" in the Solver 2 section of the .sif file. This will create a group of numbered vtu files in the vtuoutput folder. Select this group as the source in Visit, and you can click 'play' to see the gradual mesh refinement. This is the same procedure you would use to visualize an actual transient model.
visitoutput.jpg
visitoutput.jpg (95.6 KiB) Viewed 13059 times
Modifying parameters:
You can adjust the parameter values in the .grd file to see the effect on refinement. You can also change the adaptive mesh convergence criteria in the .sif file Simulation section. These will all affect the amount of mesh refinement required to achieve a satisfactory solution.

adapt.grd file text:

Code: Select all

***** ElmerGrid input file for structured grid generation *****
Version = 210903
!Elmergrid requires you to explicitly turn on MATC
MATC = True

!variables list
$totalwidth = 3e-3$
$heated = 1e-3$
$meshdensity = 100$

$unheated = (totalwidth - heated)/2$

Coordinate System = Cartesian 2D
Subcell Divisions in 2D = 3 3 

Subcell Sizes 1 = $unheated heated unheated$
Subcell Sizes 2 = 1e-3 1e-3 1e-3

Material Structure in 2D
  2 1 2
  2 2 2
  2 2 2
End

Materials Interval = 1 2

!set hot boundary to the top of Material 1, and cold to the bottom of 2.
Boundary Definitions
!Special boundary 'out' notation:
!-1 down, -2 right, -3 top and -4 left -11 smaller, -9 bigger, and -10 anything
! type     out      int      double   of the boundaries
  1        -1       2       1
  2        -3       1        1
End

Surface Elements = $meshdensity$
Triangles = logical True  !needed for RGB adaptive meshing
Numbering Horizontal
Element Degree = 1s
adapt.sif file text:

Code: Select all

Header
  CHECK KEYWORDS Warn
  Mesh DB "." "adapt"
End

Simulation
  Max Output Level = 5
  Coordinate System = "Cartesian 2D"
  Coordinate Mapping(3) = 1 2 3
  Simulation Type = "Steady State"
  Steady State Max Iterations = 5
  Post File = adapt.ep
End

Body 1
  Target Bodies(2) = 1 2
  Equation = 1
  Material = 1
End

Equation 1
  Heat Equation = True
  Active Solvers(1) = 1
End

Solver 1
  Exec Solver = "Always"
  Equation = "Heat Equation"
  Procedure = "HeatSolve" "HeatSolver"
  Variable = "Temperature"
  Variable Dofs = 1
  Optimize Bandwidth = True
  Linear System Solver = "Direct"
  Linear System Direct Method = "umfpack"
  Steady State Convergence Tolerance = 1.0e-5
  Stabilize = True
  Nonlinear System Convergence Tolerance = 1.0e-4
  Nonlinear System Max Iterations = 3
  Nonlinear System Newton After Iterations = 2
  Nonlinear System Newton After Tolerance = 1.0e-3
  Nonlinear System Relaxation Factor = 1.0

  Adaptive Mesh Refinement = true
  Adaptive Remesh = false
  Adaptive Save Mesh = true
  Adaptive Error Limit = 1e-4
End

Solver 2
 Exec Solver = String "after all"
 Equation = String "ResultOutput"
 Procedure = File "ResultOutputSolve" "ResultOutputSolver"
 Output File Name = String "adapt."
 Vtu Format = Logical True
 Ascii Output = Logical True
 Scalar Field 1 = String "Temperature"
 Mesh Name = String "RefinedMesh"
 Output Directory = String vtuoutput
End

Material 1
   Density = 1
   Heat Conductivity = 1
End

Boundary Condition 1
  Target Boundaries(1) = 1
  Name = HOT
  Heat Flux BC = True
  Heat Flux = 100
End

Boundary Condition 2
  Target Boundaries(1) = 2
  Name = COLD
  Temperature = 0
End
NJank
Posts: 99
Joined: 05 Dec 2009, 00:05
Location: Baltimore, MD, USA

Re: simple adaptive meshing and MATC parameters, 2D steady state

Post by NJank »

Updating this for recent versions of Elmer. Noticed recently that some portions no longer work as initially described.

adapt.grd file: MATC is no longer seems to be compiled into elmergrid by default, so that has been removed. There are also a number of spurious warnings, but the mesh does build okay.

additionally, some SIF file commands needed to be modified, mainly some that specified filenames as type string need to be type file. Also, the syntax for the vtu solver seems incorrect and no longer generates a vtu. so solver 2 has been removed for now.

The following files can be used with the procedures described above:

adapt.grd:

Code: Select all

***** ElmerGrid input file for structured grid generation *****
Version = 210903

Coordinate System = Cartesian 2D
Subcell Divisions in 2D = 3 3 

Subcell Sizes 1 = 1e-3 1e-3 1e-3
Subcell Sizes 2 = 1e-3 1e-3 1e-3

Material Structure in 2D
  2 1 2
  2 2 2
  2 2 2
End

Materials Interval = 1 2

Boundary Definitions
! type     out      int      double   of the boundaries
  1        -1       2       1
  2        -3       1       1
End

Surface Elements = 100
Triangles = logical True  !needed for RGB adaptive meshing
Numbering = Horizontal
Element Degree = 1
adapt.sif:

Code: Select all

Header
  CHECK KEYWORDS Warn
  Mesh DB "." "adapt"
End

Simulation
  Max Output Level = 5
  Coordinate System = "Cartesian 2D"
  Coordinate Mapping(3) = 1 2 3
  Simulation Type = "Steady State"
  Steady State Max Iterations = 5
  Post File = file "adapt.ep"
End

Body 1
  Target Bodies(2) = 1 2
  Equation = 1
  Material = 1
End

Equation 1
  Heat Equation = True
  Active Solvers(1) = 1
End

Solver 1
  Exec Solver = "Always"
  Equation = "Heat Equation"
  Procedure = "HeatSolve" "HeatSolver"
  Variable = "Temperature"
  Variable Dofs = 1
  Optimize Bandwidth = True
  Linear System Solver = "Direct"
  Linear System Direct Method = "umfpack"
  Steady State Convergence Tolerance = 1.0e-5
  Stabilize = True
  Nonlinear System Convergence Tolerance = 1.0e-4
  Nonlinear System Max Iterations = 3
  Nonlinear System Newton After Iterations = 2
  Nonlinear System Newton After Tolerance = 1.0e-3
  Nonlinear System Relaxation Factor = 1.0

  Adaptive Mesh Refinement = true
  Adaptive Remesh = false
  Adaptive Save Mesh = true
  Adaptive Error Limit = 1e-4
End

Material 1
   Density = 1
   Heat Conductivity = 1
End

Boundary Condition 1
  Target Boundaries(1) = 1
  Name = HOT
  Heat Flux BC = True
  Heat Flux = 100
End

Boundary Condition 2
  Target Boundaries(1) = 2
  Name = COLD
  Temperature = 0
End
raback
Site Admin
Posts: 4801
Joined: 22 Aug 2009, 11:57
Antispam: Yes
Location: Espoo, Finland
Contact:

Re: simple adaptive meshing and MATC parameters, 2D steady state

Post by raback »

Hi

The VTU output problem is now fixed.

There was a problem in that when we changed to case sensitive keyword (File vs. String) the matching of "Mesh Name" broke down. It would have workd with lowercase values only...

Now fixed in devel.

To my understanding there is only the problem of MATC & ElmerGrid remaininig. Thanx for reporting!

-Peter
NJank
Posts: 99
Joined: 05 Dec 2009, 00:05
Location: Baltimore, MD, USA

Re: simple adaptive meshing and MATC parameters, 2D steady state

Post by NJank »

just to verify, changing:

Mesh Name = file "RefinedMesh"

to
Mesh Name = file "refinedmesh"

allows the original ResultOutputSolve Solver to run correctily. On Windows, file commands are generally case insensitive. I don't know if this would still work on other operating systems. But at least for Windows users this will allow the solver to still be used until another binary is generated.
NJank
Posts: 99
Joined: 05 Dec 2009, 00:05
Location: Baltimore, MD, USA

Re: simple adaptive meshing and MATC parameters, 2D steady state

Post by NJank »

Updating the example to capture steady state and transient cases with VTU output for Paraview

The attached files are updates of the original files. They showcase solving the transient heat equation with adaptive mesh refinement. The block is initially at 100°C. It has a bottom boundary fixed at 0°C and a portion of the upper boundary with a fixed input heat flux. The transient simulation will cool down to the steady state gradient between the hot and cold boundaries. As it cools, a sharp gradient will form around the edges of the heat source and the mesh will need to be refined in that region.

Using the command line to run the files, assuming Elmer is in the system path and environment variables are properly set:

The geometry and mesh can be created by running:
elmergrid 1 2 adapt.grd

Note in the file below that a simple 3x3 geometry is defined. Body 1 is defined separately to make it easier to specify a portion of the top boundary as a heating region. A deliberately coarse mesh is defined so that refinement will be required.

Code: Select all

***** ElmerGrid input file for structured grid generation *****
Version = 210903

Coordinate System = Cartesian 2D
Subcell Divisions in 2D = 3 3 

Subcell Sizes 1 = 1e-3 1e-3 1e-3
Subcell Sizes 2 = 1e-3 1e-3 1e-3

Material Structure in 2D
  2 1 2
  2 2 2
  2 2 2
End

Materials Interval = 1 2

Boundary Definitions
! type     out      int      double   of the boundaries
  1        -1       2       1
  2        -3       1       1
End

Surface Elements = 10
Triangles = logical True  !needed for RGB adaptive meshing
Numbering = Horizontal
Element Degree = 1
Next, simulate the transient model by running:
elmersolver adapt.sif

The "Adaptive Mesh Refinement = true" line in Solver 1 will tell Elmer to subdivide the triangular mesh where needed to meet the specified error limit. Each refined mesh will be saved in a RefinedMesh# folder. After 9 folders, it will begin again at 1 and overwrite the earlier files.

Code: Select all

Header
  CHECK KEYWORDS Warn
  Mesh DB "." "adapt"
End

Simulation
  Max Output Level = 5
  Coordinate System = "Cartesian 2D"
  Coordinate Mapping(3) = 1 2 3
  Simulation Type = "Transient"
  Timestep Sizes(1) = .000005
  Timestep Intervals(1) = 20
  Timestepping Method = BDF
  BDF Order = 1
  Steady State Max Iterations = 10
End

Body 1
  Target Bodies(2) = 1 2
  Equation = 1
  Material = 1
  Initial Condition  = 1
End

Equation 1
  Heat Equation = True
  Active Solvers(1) = 1
End

Solver 1
  Exec Solver = "Always"
  Equation = "Heat Equation"
  Procedure = "HeatSolve" "HeatSolver"
  Variable = "Temperature"
  Variable Dofs = 1
  Optimize Bandwidth = True
  Linear System Solver = "Direct"
  Linear System Direct Method = "umfpack"
  Steady State Convergence Tolerance = 1.0e-5
  Stabilize = True
  Nonlinear System Convergence Tolerance = 1.0e-4
  Nonlinear System Max Iterations = 3
  Nonlinear System Newton After Iterations = 2
  Nonlinear System Newton After Tolerance = 1.0e-3
  Nonlinear System Relaxation Factor = 1.0

  Adaptive Mesh Refinement = true
  Adaptive Remesh = false
  Adaptive Save Mesh = true
  Adaptive Error Limit = 1e-4
End

Solver 2
 Exec Solver = String "after timestep"
 Equation = String "ResultOutput"
 Procedure = File "ResultOutputSolve" "ResultOutputSolver"
 Output File Name = file "vtufile"
 Vtu Format = Logical True
 Ascii Output = Logical True
 Scalar Field 1 = String "Temperature"
 Mesh Name = file "refinedmesh"
 Output Directory = file "vtuoutput"
End

Material 1
   Density = 1
   Heat Conductivity = 1
   Heat Capacity = 1
End

Boundary Condition 1
  Target Boundaries(1) = 1
  Name = COLD
  Temperature = 0
End

Boundary Condition 2
  Target Boundaries(1) = 2
  Name = HOT
  Heat Flux BC = True
  Heat Flux = 100
End

Initial Condition 1
  Temperature = 100
End

VTU files will be created in a 'vtuoutput' subfolder with the filename 'vtufile####.vtu'. Each will contain one file per timestep with the mesh information from that timestep. These can be viewed in ParaView:
  • Open ParaView, then File/Open.
  • Navigate the the 'vtuoutput' subfolder. from their sequential filenames, paraview groups the vtu files as a single entity. select that group and Ok.
  • The group will appear in the 'Pipeline Browser' on the left. Under Properties on the left should be an Apply button. it should be green indicated that there is something new to update on the display. click the Apply button. you should see a single color region representing the simulation domain.
  • Lower on the left you should see "Coloring" with "Solid Color" as the current option. Click "Solid Color" to drop down an option list with "temperature" as an option. Select temperature and you should see a color gradient on the image.
  • Above Coloring you should see "Representation" "Surface". Click on "Surface" and change it to "Surface with Edges" to superimpose the mesh on the image. Note that this is not the original course mesh, but the mesh at the end of the first timestep, after it was first refined.
  • At the top of the window, there are timestepping buttons. Click the green "Play" arrow to animate both the temperature (color) and the mesh refinement. Notice that the entire model turns blue. the final temperatures are much colder than the starting temperatures, so you cannot see the final temperature gradient.
  • Under the "Coloring" "temperature" list are options for the temperature scale. (button names will appear if you hover the mouse pointer above the button) Select the third button from the left "Rescale to data range". since you are showing the last timestep, this will rescale to the final temperature gradient.
  • Finally, select Play again to animate the colors / mesh, and show the mesh refinement appearing around the top heat source as the temperature gradient develops.
Note that changing the line in the Simulation block from "Simulation Type = "Transient" " to "Simulation Type = "Steady State" " will still produce an output with multiple vtu files, but this time they will just show the mesh refinements required to reach the steady solution.
Attachments
adapt.sif
Adaptive Mesh Elmersolver input file
(1.86 KiB) Downloaded 429 times
adapt.grd
Adaptive Mesh Elmergrid input file
(584 Bytes) Downloaded 443 times
Post Reply