## Code: Circular hole under uniaxial stress

### September 4, 2007

The wonderful guys at WordPress have given a wraparound so that posting source code is easier; it can’t get any better than this. Look out these pages for more phase field codes! For now, as a test, here is the code which will calculate the elastic stress fields around a circular hole in a square plate which is under an uniaxial stress.


/************
This program calculates the elastic stress fields of a circular hole
in a square plate under an uniaxial stress. The stress is applied
along the x-axis. For the expressions used in calculating the stress
fields, see p. 109 of Elasticity by Barber -- Equations 8.74, 8.75, and 8.76.
************/

#include
#include
#include

int main(void){

FILE *fp1, *fp2, *fp3;

double S; /* Applied uniaxial stress */
double a; /* Radius of the circular hole */
double r; /* Distance along the x- or y-axis */

int i;
double s11, s12, s22; /* The 11, 12 and 22 stress fields respectively */

S = 1.0;
a = 2.5;

fp1 = fopen("sigma11_x","w");
fp2 = fopen("sigma22_x","w");
fp3 = fopen("sigma12_x","w");

for(i=0;i<3000; ++i){
r = 0.01*i;
if (r < a){
s11 = s12 = s22 = 0.0;
}
else{
s11 = 0.5*S*(1. - a*a/(r*r)) + 0.5*S*(3.*a*a*a*a/(r*r*r*r) - 4.*a*a/(r*r) + 1.);
s22 = 0.5*S*(1. + a*a/(r*r)) - 0.5*S*(3.*a*a*a*a/(r*r*r*r) + 1.);
s12 = 0.0;
}
fprintf(fp1,"%le %le\n",r,s11);
fprintf(fp2,"%le %le\n",r,s22);
fprintf(fp3,"%le %le\n",r,s12);

}

fclose(fp1);
fclose(fp2);
fclose(fp3);

fp1 = fopen("sigma11_y","w");
fp2 = fopen("sigma22_y","w");
fp3 = fopen("sigma12_y","w");

for(i=0;i<3000; ++i){
r = 0.01*i;
if (r < a){
s11 = s12 = s22 = 0.0;
}
else{
s22 = 0.5*S*(1. - a*a/(r*r)) - 0.5*S*(3.*a*a*a*a/(r*r*r*r) - 4.*a*a/(r*r) + 1.);
s11 = 0.5*S*(1. + a*a/(r*r)) + 0.5*S*(3.*a*a*a*a/(r*r*r*r) + 1.);
s12 = 0.0;
}
fprintf(fp1,"%le %le\n",r,s11);
fprintf(fp2,"%le %le\n",r,s22);
fprintf(fp3,"%le %le\n",r,s12);

}

fclose(fp1);
fclose(fp2);
fclose(fp3);

return 0;
}


At the first go, looks like everything works fine except for (a) the #include things–for which, the stuff in triangular brackets, it seems to consider as html commands, and (b) the greater then signs, which it seem to have some problems showing as greater then signs. Code within the sourcecode wraparound are supposed to be formatted automatically. The language option I chose is cpp, which I assume is C++. Could that be the problem?

Test: <>

 #include

Hmm…I guess the wraparound requires a bit of fixing!!!

Test 2:

$features = file_get_contents( 'http://wordpress.com/features/' ); preg_match_all( '|<h3>(.*?)</h3>|is',$features, $why_wp_rocks ); foreach ($why_wp_rocks[1] as $slick_feature )$hotness[] = $slick_feature; var_dump($hotness );