antonberce - chalmershani/kurser/os_cfd_2010/antonberce/antonbercepresentation.pdfantonberce •set...

24
Anton Berce, Chalmers / Solid and Fluid Dynamics 1 Anton Berce OpenFOAM Tutorial Adaptive mesh refinement - The development of a new application Anton Berce, October 16, 2010

Upload: others

Post on 17-Jan-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 1

Anton Berce

OpenFOAM Tutorial

Adaptive mesh refinement

- The development of a new application

Anton Berce, October 16, 2010

Page 2: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 2

Agenda

Anton Berce

• Project Definition

• Tutorial icoErrorEstimate

• Tutorial refineMesh

• Developing

• Discussion

”Develop a solver that automatically etimates an

error and refines the mesh in the areas where the

magnitude of the error is largest”

Page 3: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 3

Agenda

Anton Berce

• Project Definition

• Tutorial icoErrorEstimate

• Tutorial refineMesh

• Developing

• Discussion

The utility icoErrorEstimate will be used on

the cavity-case. Quite brief and easy tutorial.

Page 4: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 4

Agenda

Anton Berce

• Project Definition

• Tutorial icoErrorEstimate

• Tutorial refineMesh

• Developing

• Discussion

First we will use the utility refineMesh to refine

the wole mesh. Then we will refine a region using

the same utility with a dictionary.

Page 5: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 5

Agenda

Anton Berce

• Project Definition

• Tutorial icoErrorEstimate

• Tutorial refineMesh

• Developing

• Discussion

We will now use our recently gained knowledge to

develop the application icoFoamErrorRefine and

apply it to the cavity case.

Page 6: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 6

Agenda

Anton Berce

• Project Definition

• Tutorial icoErrorEstimate

• Tutorial refineMesh

• Developing

• Discussion

Further Development

Questions

Opinions

Page 7: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 7

Project Definition

Anton Berce

• Background

• Goals

Report by Jasak, H. and Gosman, A. D. (2000)

’AUTOMATIC RESOLUTION CONTROL FOR THE

FINITEVOLUME METHOD, PART 2: ADAPTIVE

MESH REFINEMENT AND COARSENING’

Figure 1: Adaptive refining/coarsening by Hvorje Jasak

Page 8: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 8

Project Definition

Anton Berce

• Background

• GoalsThe application should, simplified, do the following:

Time++

Solve

Error

Refine

Where Large?

Update Mesh

Map Results

Figure 2: Flow Chart of IcoFoamErrorRefine

Page 9: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 9

Tutorial icoErrorEstimate

Anton Berce

• Copy cavity-case

• Run the icoErrorEstimate

• Study results in paraFoam

runcp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .

Code 1: Copy cavity-case

cd cavityblockMesh |tee logMeshicoFoam |tee logSolveicoErrorEstimate |tee logErrorEstimate

Code 2: Run the icoErrorEstimate

Figure 3: Result of cavityError

Page 10: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 10

Tutorial refineMesh

Anton Berce

• Set up directories

• Run original icoFoam

• Refine whole mesh

• Refine cellSet

runcp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .mv cavity cavityOrigcp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .mv cavity cavityRefineWholecp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .mv cavity cavityRefineSet

Code 3: Set up directories

cd cavityOrigblockMesh |tee logMeshicoFoam |tee logSolve

Code 4: Run original icoFoam

Page 11: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 11

Tutorial refineMesh

Anton Berce

• Set up directories

• Run original icoFoam

• Refine whole mesh

• Refine cellSet

runcd cavityRefineWholerefineMesh -overwriterm -r 0/polyMeshvim system/controlDict:%s/endTime 0.5;/endTime 0.7;/:%s/deltaT 0.005;/deltaT 0.0025;/:wqmapFields ../cavityOrig -sourceTime latestTime -consistenticoFoam |tee logSolve

Code 5: Refine Whole Mesh

Page 12: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 12

Tutorial refineMesh

Anton Berce

• Set up directories

• Run original icoFoam

• Refine whole mesh

• Refine cellSet

runcd cavityRefineSetcp $FOAM_UTILITIES/mesh/manipulation/\refineMesh/refineMeshDict system/mkdir constant/polyMesh/sets/

Code 6: Set up refinement

Remove normal from the directions inside the

refineMeshDict.Also, copy the attached file c0 and into

constant/polyMesh/sets/. It contains the cell-

numbers of the cells which are about to be refined (40

cells closest to the moving wall)

refineMesh -dict -overwriterm -r 0/polyMeshvim system/controlDict:%s/endTime 0.5;/endTime 0.7;/:%s/deltaT 0.005;/deltaT 0.0025;/:wqmapFields ../cavityOrig -sourceTime latestTime -consistenticoFoam |tee logSolve

Code 7: Refine cellSet

Page 13: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 13

Developing

Anton Berce

• Set up

• ErrorEstimation

• Find largest errors

• Refine cells

• Map results

• Compile

We will base the new application in icoFoam, let’s start

with copying that into our user appbin.

runcd ../applications/mkdir -p solvers/incompressible/icoFoamErrorRefinecd solvers/incompressible/icoFoamErrorRefinecp -r $FOAM_SOLVERS/incompressible/icoFoam/* .rm *.deprm -r Make/linux*mv icoFoam.C icoFoamErrorRefine.Csed -i s/"icoFoam"/"icoFoamErrorRefine"/g \Make/filessed -i s/"FOAM_APPBIN"/"FOAM_USER_APPBIN"/g \Make/files

Code 8: Copy icoFoam

Page 14: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 14

Developing

Anton Berce

• Set up

• ErrorEstimation

• Find largest errors

• Refine cells

• Map results

• Compile

Add this to createFields.H:

//*********NEW****************volVectorField err(IOobject("err",runTime.timeName(),mesh,IOobject::MUST_READ,IOobject::AUTO_WRITE),mesh);// ****************************/

Code 9: Copy icoFoam

New header file that creates the additional mesh

newMesh.

cp $FOAM_SRC/OpenFOAM/include/createMesh.H .mv createMesh.H createNewMesh.Hsed -i s/"mesh"/"newMesh"/g createNewMesh.H

Code 10: createNewMesh

Page 15: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 15

Developing

Anton Berce

• Set up

• ErrorEstimation

• Find largest errors

• Refine cells

• Map results

• Compile

Now open icoFoamErrorRefine.C and copy this into

the header:

// Error Estimation#include "errorEstimate.H"#include "resError.H"// Mesh refinement#include "multiDirRefinement.H" // For the actual refinement#include <vector> // For creating standard vectors// Map Mesh//#include "fvMesh.H"//#include "IOobjectList.H"//#include "meshToMesh.H"//#include "MapVolFields.H"//#include "MapConsistentVolFields.H"//#include "UnMapped.H"//#include "processorFvPatch.H"//#include "mapLagrangian.H"// Extra objects for setting up refinementstatic const scalar errTol = 1E-5;static bool refine10 = true;

Code 11: Additional headers in icoErrorRefine.C

Also, add "#include createNewMesh.H" //Create objectjust after #include createMesh.H in the top of the

main.

Page 16: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 16

Developing

Anton Berce

• Set up

• ErrorEstimation

• Find largest errors

• Refine cells

• Map results

• Compile

Time to add the error estimation code. This is based

on icoErrorEstimate.C. Add the following right after

the Info statements after runTime.wrie().

//******** Error Estimation *********if(runTime.write()){errorEstimate<vector> ee(resError::div(phi, U)- resError::laplacian(nu, U)==-fvc::grad(p));volVectorField err = ee.error();err.write();mag(err)().write();

Code 12: Error estimation syntax

Page 17: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 17

Developing

Anton Berce

• Set up

• ErrorEstimation

• Find largest errors

• Refine cells

• Map results

• Compile

The syntax of this is too long to fit in a slide. So copy the

code inside the attached file findLargestErrors into

the line right after the previously added code.

Page 18: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 18

Developing

Anton Berce

• Set up

• ErrorEstimation

• Find largest errors

• Refine cells

• Map results

• Compile

//******** Cell Refinement **********// Since this is a pretty long function i would in// this section like to call upon a function file// that refines the mesh.// That file should be similar to refineMesh.C// Define refinement dictionarydictionary refineDict; //Declaredictionary coeffsDict;coeffsDict.add("tan1", vector(1, 0, 0));coeffsDict.add("tan2", vector(0, 1, 0));wordList directions(2);directions[0] = "tan1";directions[1] = "tan2";refineDict.add("directions", directions); // Add directionsrefineDict.add("useHexTopology", "false");// Use standard cut

Code 13: First part of refine mesh syntax

Page 19: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 19

Developing

Anton Berce

• Set up

• ErrorEstimation

• Find largest errors

• Refine cells

• Map results

• Compile

refineDict.add("coordinateSystem", "global");refineDict.add("globalCoeffs", coeffsDict);refineDict.add("geometricCut", "false");refineDict.add("writeMesh", "false");// Multi-directional refinement (does multiple iterations)Info << "Entering Refinement" << endl;multiDirRefinement multiRef(newMesh, refCells, refineDict);Info << "Done with Refinement" << endl;Info << "Writing new mesh with " << refCells.size()<< " refinements" << endl;mesh.write();newMesh.write();}

Code 14: Second part of refine mesh syntax

Page 20: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 20

Developing

Anton Berce

• Set up

• ErrorEstimation

• Find largest errors

• Refine cells

• Map results

• Compile

The mapping has not been competed yet. To see the

toughts and tries that has been made please see my re-

port.

Page 21: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 21

Developing

Anton Berce

• Set up

• ErrorEstimation

• Find largest errors

• Refine cells

• Map results

• Compile

It is now time to compile and run the application. Before

compiling we have to include some more libraries in the

Make/options-file according to the code box below.

EXE_INC = \-I$(LIB_SRC)/finiteVolume/lnInclude \-I$(LIB_SRC)/errorEstimation/lnInclude \-I$(LIB_SRC)/dynamicMesh/lnInclude \-I$(LIB_SRC)/meshTools/lnInclude \-I$(LIB_SRC)/lagrangian/basic/lnInclude \-I$(LIB_SRC)/sampling/lnInclude

EXE_LIBS = \-lmeshTools \-lfiniteVolume \-ltopoChangerFvMesh \-lsampling

Code 15: Make/options

Compile with wmake.

Page 22: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 22

Using icoErrorRefine

Anton Berce

• Set up

• Run

• Study results

To illustrate how far the development has come up to

now we will now solve the cavity case with the newly

developed solver.

runcp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .mv cavity cavityErrorRefinecd cavityErrorRefinecp 0/U 0/errsed -i s/"U"/"err"/g 0/errsed -i s/"(1 0 0)"/"(0 0 0)"/g 0/errblockMesh |tee logBlockMeshicoFoamErrorRefine |tee logIcoFoamErrorRefine

Code 16: Run

Now view the results in paraFoam.

Page 23: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 23

Discussion

Anton Berce

• Further Developments

• Questions

Fix the mapping

Add a coarsening

Page 24: AntonBerce - Chalmershani/kurser/OS_CFD_2010/antonBerce/antonBercePresentation.pdfAntonBerce •Set up •ErrorEstimation •Find largest errors •Refine cells •Map results

Anton Berce, Chalmers / Solid and Fluid Dynamics 24

Discussion

Anton Berce

• Further Developments

• Questions

Thank You!