|
[Sponsors] |
creating a field that is accessible by all processors |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 27, 2020, 03:08 |
creating a field that is accessible by all processors
|
#1 |
New Member
siavash
Join Date: Jul 2019
Location: Indiana, US
Posts: 11
Rep Power: 7 |
I am using a curve estimation method for interFoam, which relies on adjacent cell values.
for instance, to calculate the curvature on cell [i, j], I need the values from cells: [i-3,j+3],[i-2,j+3],[i-1,j+3],[i,j+3],.... This is easily done when running on one processor, however, the code does not run in parallel, because each processor has access only to a certain part of the domain. and not all the cells are necessarily aligned on the patch fields. I was thinking of creating a field or array where all of the elements within it are accessible from all processors in openfoam. Is this possible? I am sure there must be a smarter way around this issue? I would appreciate any insight or guidance on this. Thank you |
|
July 27, 2020, 03:14 |
|
#2 |
Senior Member
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 367
Rep Power: 8 |
did you change/modify/add code ?
if yes how did you do it? |
|
July 27, 2020, 03:28 |
|
#3 |
New Member
siavash
Join Date: Jul 2019
Location: Indiana, US
Posts: 11
Rep Power: 7 |
Yes, I have added the following code, which, again, works fine running only on 1 processor.
so in the code below, the "ID_" should be a global ID, where all elements of "alpha1_smooth3" could be accessed by all the processors. forAll(mesh.C(),ID_) { int ID = ID_+1; //cell indices i and j int c_i = ID % Nx; if(c_i == 0){ c_i = Nx;} int c_j = ceil(ID_/Nx)+1; if(c_i > 4 && c_i < (Nx-4) && c_j>4 && c_j < (Ny-4)) { //top row int ID_NW = ((c_j+1)-1)*Nx + (c_i-1) - 1; int ID_N = ((c_j+1)-1)*Nx + c_i - 1; int ID_NE = ((c_j+1)-1)*Nx + (c_i+1) - 1; //midrow int ID_W = (c_j-1)*Nx + (c_i-1) - 1; int ID_E = (c_j-1)*Nx + (c_i+1) - 1; //bottom row int ID_SW = ((c_j-1)-1)*Nx + (c_i-1) - 1; int ID_S = ((c_j-1)-1)*Nx + c_i - 1; int ID_SE = ((c_j-1)-1)*Nx + (c_i+1) - 1; if(abs(gradAlpha_[ID_].component(vector::Y))>abs(gradAlpha_[ID_].component(vector::X))){ //fourth top row int ID_NW3 = ((c_j+4)-1)*Nx + (c_i-1) - 1; int ID_N3 = ((c_j+4)-1)*Nx + c_i - 1; int ID_NE3 = ((c_j+4)-1)*Nx + (c_i+1) - 1; //third top row int ID_NW2 = ((c_j+3)-1)*Nx + (c_i-1) - 1; int ID_N2 = ((c_j+3)-1)*Nx + c_i - 1; int ID_NE2 = ((c_j+3)-1)*Nx + (c_i+1) - 1; //second top row int ID_NW1 = ((c_j+2)-1)*Nx + (c_i-1) - 1; int ID_N1 = ((c_j+2)-1)*Nx + c_i - 1; int ID_NE1 = ((c_j+2)-1)*Nx + (c_i+1) - 1; //second bottom row int ID_SW1 = ((c_j-2)-1)*Nx + (c_i-1) - 1; int ID_S1 = ((c_j-2)-1)*Nx + c_i - 1; int ID_SE1 = ((c_j-2)-1)*Nx + (c_i+1) - 1; //third bottom row int ID_SW2 = ((c_j-3)-1)*Nx + (c_i-1) - 1; int ID_S2 = ((c_j-3)-1)*Nx + c_i - 1; int ID_SE2 = ((c_j-3)-1)*Nx + (c_i+1) - 1; //fourth bottom row int ID_SW3 = ((c_j-4)-1)*Nx + (c_i-1) - 1; int ID_S3 = ((c_j-4)-1)*Nx + c_i - 1; int ID_SE3 = ((c_j-4)-1)*Nx + (c_i+1) - 1; double H_ib((alpha1_smooth3[ID_NW3]+alpha1_smooth3[ID_NW2]+alpha1_smooth3[ID_NW1]+alpha1_smooth3[ID_NW]+alpha1_smooth3[ID_W]+alpha1_smooth3[ID_SW]+alpha1_smooth3[ID_SW1]+alpha1_smooth3[ID_SW2]+alpha1_smooth3[ID_SW3])*deltaX_); double H_i((alpha1_smooth3[ID_N3]+alpha1_smooth3[ID_N2]+alpha1_smooth3[ID_N1]+alpha1_smooth3[ID_N]+alpha1_smooth3[ID_]+alpha1_smooth3[ID_S]+alpha1_smooth3[ID_S1]+alpha1_smooth3[ID_S2]+alpha1_smooth3[ID_S3])*deltaX_); double H_if((alpha1_smooth3[ID_NE3]+alpha1_smooth3[ID_NE2]+alpha1_smooth3[ID_NE1]+alpha1_smooth3[ID_NE]+alpha1_smooth3[ID_E]+alpha1_smooth3[ID_SE]+alpha1_smooth3[ID_SE1]+alpha1_smooth3[ID_SE2]+alpha1_smooth3[ID_SE3])*deltaX_); double h_d((H_if - H_ib)/(2.0*deltaX_)); double h_dd((H_if - 2.0*H_i + H_ib)/(deltaX_*deltaX_)); Kurv[ID_] = h_dd/Foam:ow((1.0 + Foam:ow(h_d,2.0)),3.0/2.0); }else{ //top row, starting from left int ID_NW3 = ((c_j+1)-1)*Nx + (c_i-4) - 1; int ID_NW2 = ((c_j+1)-1)*Nx + (c_i-3) - 1; int ID_NW1 = ((c_j+1)-1)*Nx + (c_i-2) - 1; int ID_NE1 = ((c_j+1)-1)*Nx + (c_i+2) - 1; int ID_NE2 = ((c_j+1)-1)*Nx + (c_i+3) - 1; int ID_NE3 = ((c_j+1)-1)*Nx + (c_i+4) - 1; //middle middle row int ID_W3 = (c_j-1)*Nx + (c_i-4) - 1; int ID_W2 = (c_j-1)*Nx + (c_i-3) - 1; int ID_W1 = (c_j-1)*Nx + (c_i-2) - 1; int ID_E1 = (c_j-1)*Nx + (c_i+2) - 1; int ID_E2 = (c_j-1)*Nx + (c_i+3) - 1; int ID_E3 = (c_j-1)*Nx + (c_i+4) - 1; //bottom row int ID_SW3 = ((c_j-1)-1)*Nx + (c_i-4) - 1; int ID_SW2 = ((c_j-1)-1)*Nx + (c_i-3) - 1; int ID_SW1 = ((c_j-1)-1)*Nx + (c_i-2) - 1; int ID_SE1 = ((c_j-1)-1)*Nx + (c_i+2) - 1; int ID_SE2 = ((c_j-1)-1)*Nx + (c_i+3) - 1; int ID_SE3 = ((c_j-1)-1)*Nx + (c_i+4) - 1; double H_jn((alpha1_smooth3[ID_NW3] + alpha1_smooth3[ID_NW2] + alpha1_smooth3[ID_NW1] + alpha1_smooth3[ID_NW] + alpha1_smooth3[ID_N] + alpha1_smooth3[ID_NE] + alpha1_smooth3[ID_NE1] + alpha1_smooth3[ID_NE2] + alpha1_smooth3[ID_NE3])*deltaX_); double H_j((alpha1_smooth3[ID_W3] + alpha1_smooth3[ID_W2] + alpha1_smooth3[ID_W1] + alpha1_smooth3[ID_W] + alpha1_smooth3[ID_] + alpha1_smooth3[ID_E] + alpha1_smooth3[ID_E1] + alpha1_smooth3[ID_E2] + alpha1_smooth3[ID_E3])*deltaX_); double H_js((alpha1_smooth3[ID_SW3] + alpha1_smooth3[ID_SW2] + alpha1_smooth3[ID_SW1] + alpha1_smooth3[ID_SW] + alpha1_smooth3[ID_S] + alpha1_smooth3[ID_SE] + alpha1_smooth3[ID_SE1] + alpha1_smooth3[ID_SE2]+ alpha1_smooth3[ID_SE3])*deltaX_); double h_d((H_jn - H_js)/(2.0*deltaX_)); double h_dd((H_jn - 2.0*H_j + H_js)/(deltaX_*deltaX_)); Kurv[ID_] = h_dd/Foam:ow((1.0 + Foam:ow(h_d,2.0)),3.0/2.0); } } |
|
Tags |
openfoam, parallelization, programming |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Foam::error::PrintStack | almir | OpenFOAM Running, Solving & CFD | 92 | May 21, 2024 08:56 |
creating an internal field? | maybee | OpenFOAM Programming & Development | 2 | February 4, 2021 18:15 |
[Other] dynamicTopoFVMesh and pointDisplacement | RandomUser | OpenFOAM Meshing & Mesh Conversion | 6 | April 26, 2018 08:30 |
TimeVaryingMappedFixedValue for Direct Numerical Simulation inlet | johndeas | OpenFOAM | 5 | May 21, 2014 08:11 |
Creating far field | musman | ANSYS Meshing & Geometry | 1 | May 14, 2009 15:29 |