|
[Sponsors] |
September 28, 2017, 07:27 |
Manual decomposition using setFields
|
#1 |
New Member
Lennart Steffen
Join Date: Mar 2017
Location: Braunschweig, Germany
Posts: 17
Rep Power: 9 |
Hey there,
I found a couple of old threads about the manual option in decomposeParDict, and how to conveniently prepare the file for it with the setFields utility: DecomposePar utility Manually divide sub-domain for parallel computing It was possible to piece the answer together from these threads, but it took me a couple of hours, so I wanted to share my solution here. There might be more elegant ways and I'm open to suggestions, but it works and it's fast enough. First, I'll explain the problem, then I'll describe my solution. The problem: The manual option in the decomposeParDict file offers a lot of versatility, but is difficult to use, because you have to provide a file with a labelList the size of your mesh cell count. Each entry signifies the processor that cell is on. The exact file formatting is not completely trivial to find in the docs, but that's doable. However, actually creating that file manually doesn't really make sense, especially for larger meshes. While the setFields utility provides a very convenient way of writing that list, its input- and output formatting is slightly different to the one for the needed file. My solution: Make sure your mesh is created and your system/decomposeParDict looks something like this: Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 4.x | | \\ / A nd | Web: www.OpenFOAM.org | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; note "mesh decomposition control dictionary"; object decomposeParDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // numberOfSubdomains 2; method scotch; scotchCoeffs { } manualCoeffs { dataFile "cellDist"; } // ************************************************************************* // Code:
decomposePar -cellDist Now we need to write our desired decomposition into the system/setFieldsDict. Just as an example, it can be sth like this: Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: 1.7.1 | | \\ / A nd | Web: www.OpenFOAM.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class dictionary; location "system"; object setFieldsDict; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // defaultFieldValues ( volScalarFieldValue cellDist 0 ); regions ( boxToCell { box ( 0.5 0 0 ) ( 1 0.5 1 ) ; fieldValues ( volScalarFieldValue cellDist 1); } boxToCell { box ( 0 0.5 0 ) ( 0.5 1 1 ) ; fieldValues ( volScalarFieldValue cellDist 2); } boxToCell { box ( 0.5 0.5 0 ) ( 1 1 1 ) ; fieldValues ( volScalarFieldValue cellDist 3); } ); // ************************************************************************* // Now go back to your terminal and execute Code:
setFields ; touch prepDecomp.py Code:
#read file with open("0/cellDist", "r") as cdFile: lines = cdFile.readlines() #replace and delete unwanted lines lines[11] = lines[11].replace("volScalarField", "labelList") lines[12] = lines[12].replace("0", "constant") del lines[17:21] bfline = 0 for i, line in enumerate(lines): if (line.find("boundaryField") != -1): bfline = i break del lines[i:] #write file with open("constant/cellDist", "w") as cdFile: for line in lines: cdFile.write(line) Code:
python prepDecomp.py Next, we set the keyword method in system/decomposeParDict to manual, and we're good to go. Your workflow for designing your preferred decomposition may be this:
I needed this, because I used a codedFixedValue BC that accessed a patch on another processor core. This way, I could just place them on the same core, at least as a stopgap solution. Hope this might help someone. Lennart Edit: I didn't try this method with binary format, so if you run into problems, make sure the writeFormat keyword in system/controlDict is set to ascii for the whole process. That way you can at least see what's happening. |
|
February 7, 2018, 07:30 |
|
#2 |
New Member
Timm Feigel
Join Date: Sep 2017
Location: Braunschweig, Germany
Posts: 3
Rep Power: 9 |
Works perfectly, thank you!
|
|
March 20, 2018, 03:18 |
Works Perfectly.
|
#3 |
New Member
Join Date: Aug 2009
Posts: 4
Rep Power: 17 |
Thanks for sharing. Works perfectly.
|
|
August 25, 2018, 01:18 |
Perfect!
|
#4 |
New Member
Join Date: Mar 2016
Posts: 8
Rep Power: 10 |
Works great!
Thanks for the help! |
|
October 2, 2018, 10:04 |
|
#5 |
New Member
Mateusz
Join Date: Nov 2016
Posts: 1
Rep Power: 0 |
It works great. Many thanks !
|
|
August 24, 2020, 11:43 |
|
#6 |
Member
Patti Michelle Sheaffer
Join Date: Sep 2018
Posts: 55
Rep Power: 8 |
Thanks for taking the time to share a solution!!
|
|
August 12, 2021, 07:24 |
|
#7 |
New Member
Giovanni Luddeni
Join Date: Jan 2021
Posts: 14
Rep Power: 5 |
I didn't really follow the steps, i just used funkySetFields, but I couldn't find in any tutorial an example of the file to put in the constant folder, very helpful, thank you!
Just changing a few lines I got a nice script to decompose a multiregion case in a proper way |
|
May 10, 2023, 21:59 |
|
#8 | |
Senior Member
Desh
Join Date: Mar 2021
Location: Sydney
Posts: 118
Rep Power: 5 |
Quote:
Since you have figure out a proper way of manual decompose of a multiRegion, would you mind sharing the details, particular to the multiRegion ? Thank you Dasith |
||
July 3, 2023, 09:51 |
|
#9 |
Senior Member
Join Date: Oct 2017
Posts: 133
Rep Power: 9 |
I have adapted the line numbers to OpenFOAM v2212:
Code:
#read file with open("0/cellDist", "r") as cdFile: lines = cdFile.readlines() #replace and delete unwanted lines lines[12] = lines[12].replace("volScalarField", "labelList") lines[13] = lines[13].replace("0", "constant") del lines[18:21] bfline = 0 for i, line in enumerate(lines): if (line.find("boundaryField") != -1): bfline = i break del lines[i:] #write file with open("constant/cellDist", "w") as cdFile: for line in lines: cdFile.write(line) Code:
/*--------------------------------*- C++ -*----------------------------------*\ | ========= | | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / O peration | Version: v2212 | | \\ / A nd | Website: www.openfoam.com | | \\/ M anipulation | | \*---------------------------------------------------------------------------*/ FoamFile { version 2.0; format ascii; class volScalarField; object cellDist; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 0 0 0 0 0 0]; internalField uniform 0; boundaryField { ".*" { type fixedValue; value uniform 0; } } // ************************************************************************* // |
|
Tags |
codedfixedvalue, decomposepar, manual decomposition, python, setfields |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Looking for an example/help with manual decomposition | KTG | OpenFOAM Pre-Processing | 2 | March 28, 2017 00:06 |
[snappyHexMesh] How to define to right point for locationInMesh | Mirage12 | OpenFOAM Meshing & Mesh Conversion | 7 | March 13, 2016 15:07 |
Manual Decomposition Method | smraniaki | OpenFOAM Pre-Processing | 3 | November 24, 2013 17:53 |
Manual decomposition of domain | pss | OpenFOAM Pre-Processing | 0 | April 26, 2012 02:33 |
Description file for manual decomposition | A.Devesa | OpenFOAM Running, Solving & CFD | 2 | July 4, 2011 09:09 |