volume of element

User: "Prabin Pradhananga_22497"
Altair Community Member
Updated by unknown

I have been able to get the volume of single element (both in serial and parallel mode with 8 cores.) I used the code as mentioned in the above link. The following code works very well both in series and parallel. I found that wDetJ is 1/8 th of volume of single element. To find the volume of an element, I needed to multiply by 8 (most probably there are 8 gauss points).

Real* wghtDetJac ; Real wDetJ ; Integer elem ; ... wghtDetJac = udfGetElmWDetJ( udfHd ) ; for ( elem = 0 ; elem < nItems ; elem++ ) {   wDetJ = wghtDetJac[elem] ;  ... }

I have a simple geometry as below. It is 1m x 1m x 1m with (10 x 10 x 1) elements:- 

image

Now, the issue I am having is that I have marker (0-fluid; 1-solid) for each element in the domain above. I want to run a code to calculate the volume of only fluid (i.e marker with 0). I wrote a code that does this. It works very well in series (only 1 core). But, I found when I try to run the same code in parallel (multi cores with 8 cores), wDetJ is correct. But, the total volume (vol) corresponding to 0 marker is not correct in parallel mode--it is correct only in series mode. Would you please help me figure out how to evaluate the volume for the 0 marker only in parallel mode? I figured out that UDF is called several times even in each timestep due to parallelization. The code I ran is:

Integer timeStep ;
Integer firstCall ;
static Integer mytimestep ;
firstCall = udfFirstCall( udfHd ) ;
Real dens ;

/* volume of an element */
Real* wghtDetJac ;
Real wDetJ ;
wghtDetJac = udfGetElmWDetJ( udfHd ) ;

static Real vol ;
if (firstCall ==1)
{
vol = 0.0 ;
 
for ( elem =0 ; elem < nItems ; elem++ ) {
 
outVec[elem] =0 ;

if (dens ==0) // fluid region
{
wDetJ = wghtDetJac[elem] ;
udfPrintMessPrim( udfHd, "wDetJ=%0.12f\t nItems=%d\n", wDetJ, nItems) ;
vol += wDetJ*8;
}

FILE* fpv = fopen("volume.txt", "w");
fprintf(fpv, "%0.12f\n%0.12f\n%d\n%d\n", vol, wDetJ*8, nItems);
fclose(fpv);
}
}

Find more posts tagged with