!CLTの曲げ(CCX)
! 弾塑性で繰り返し載荷
implicit none
!#--入力
real    :: b1=600.d-3      ! m   :幅(x)
real    :: h=180.d-3       ! m   :全層の高さ(y)
real    :: ell=3600.d-3    ! m   :長さ(z)
real    :: kotei=300.d-3   ! m   :両端から境界条件までの距離
real    :: b2=10.d-3       ! m   :固定しているH鋼のフランジ幅
integer :: nsou=7          !     :層数
integer :: nx=5            !     :幅方向分割数
integer :: ny=2            !     :1層ごとの高さ方向分割数
integer :: nz=100          !     :長さ方向分割数
integer :: ndankai=4       !     :荷重段階
real    :: saikax=500.d-3  ! m   :載荷板の幅(x)
real    :: saikaz=10.d-3   ! m   :載荷板の幅(z)
real    :: itix=300.d-3    ! m   :幅方向(x)の載荷板中心位置
real    :: itiz=1800.d-3   ! m   :長さ方向(z)の載荷板中心位置
real    :: exx=6.0d3/25    ! MPa :x軸(幅)方向のヤング率
real    :: eyy=6.0d3/25    ! MPa :y軸(高さ)方向のヤング率
real    :: ezz=6.0d3       ! MPa :z軸(長さ)方向のヤング率
real    :: poizx=0.4d0     !     :ポアソン比
!---
real poixy,poixz,poiyx,poiyz,poizy,gxy,gxz,gyz
real :: x(1000000),y(1000000),z(1000000) !節点座標
integer :: mesh(1000000,8)               !要素と要素を構成する節点
real :: e66(6,6),b(3,3),dx,dy,dz,ts
real,allocatable :: p(:)
integer,allocatable :: nhanpuku(:)
integer i,j,k,l,nset,nyou,nsaika
!#--各荷重段階での荷重と繰り返し回数
allocate(p(ndankai),nhanpuku(ndankai))
p(1)=20.d-3   ! MN :荷重
p(2)=30.d-3   ! MN :荷重
p(3)=40.d-3   ! MN :荷重
p(4)=50.d-3   ! MN :荷重
nhanpuku(1)=3 ! 回
nhanpuku(2)=4 ! 回
nhanpuku(3)=1 ! 回
nhanpuku(4)=1 ! 回
!---ポアソン比
poizy=poizx
poixy=poizx*exx/ezz
poixz=poixy
poiyx=poixy
poiyz=poixy
!---せん断弾性係数
gxy=ezz/15
gxz=gxy
gyz=gxy
!---要素長さ
dx=b1/nx
dy=h/(ny*nsou)
dz=ell/nz
!---節点座標の計算
nset=0
do k=0,nz
   do j=0,ny*nsou
      do i=0,nx
         nset=1+nset
         x(nset)=i*dx
         y(nset)=j*dy
         z(nset)=k*dz
      enddo
   enddo
enddo
!---要素を構成する節点の計算
nyou=0
do k=0,nz-1
   do j=0,ny*nsou-1
      do i=1,nx
         nyou=1+nyou
         mesh(nyou,1)=i+j*(nx+1)+k*((nx+1)*(ny*nsou+1))
         mesh(nyou,2)=mesh(nyou,1)+(nx+1)
         mesh(nyou,3)=mesh(nyou,2)+(nx+1)*(ny*nsou+1)
         mesh(nyou,4)=mesh(nyou,1)+(nx+1)*(ny*nsou+1)
         mesh(nyou,5)=mesh(nyou,1)+1
         mesh(nyou,6)=mesh(nyou,5)+nx+1
         mesh(nyou,7)=mesh(nyou,6)+(nx+1)*(ny*nsou+1)
         mesh(nyou,8)=mesh(nyou,5)+(nx+1)*(ny*nsou+1)
      enddo
   enddo
enddo
!---節点座標の出力
print'("*NODE, NSET=Nall")'
do i=1,nset
   print'(i6,a,f9.6,a,f9.6,a,f9.6)',&
       &i,',',x(i),',',y(i),',',z(i)
end do
!---要素の出力
do k=0,nsou-1
   print'(A,i1)',"*ELEMENT, TYPE=C3D8, ELSET=E",k+1
   do j=0,nz-1
      do i=1,nx*ny
         l=i+j*(nx*ny*nsou)+k*(nx*ny)
         print'(i6,a,i6,a,i6,a,i6,a,i6,a,i6,a,i6,a,i6,a,i6)',&
             &l,',',&
             &mesh(l,1),',',&
             &mesh(l,2),',',&
             &mesh(l,3),',',&
             &mesh(l,4),',',&
             &mesh(l,5),',',&
             &mesh(l,6),',',&
             &mesh(l,7),',',&
             &mesh(l,8)
      enddo
   enddo
enddo
!---境界条件の節点群
print'("*NSET,NSET=kotei1")'
do i=1,nset
   if (y(i)>h-dy/3.and.y(i)<h+dy/3.and.&
       &z(i)>kotei-b2/2-dz/3.and.z(i)<kotei+b2/2+dz/3) then
      print'(i6,a)',i
   endif
end do
print'("*NSET,NSET=kotei2")'
do i=1,nset
   if (y(i)>h-dy/3.and.y(i)<h+dy/3.and.&
       &z(i)>ell-kotei-b2/2-dz/3.and.z(i)<ell-kotei+b2/2+dz/3) then
      print'(i6,a)',i
   endif
end do
!---載荷条件の節点群
print'("*NSET,NSET=saika")'
nsaika=0
do i=1,nset
   if (y(i)>-dy/3.and.y(i)<dy/3.and.&
       &z(i)>=itiz-saikaz/2-dz/3.and.z(i)<=itiz+saikaz/2+dz/3.and.&
       &x(i)>=itix-saikax/2-dx/3.and.x(i)<=itix+saikax/2+dx/3) then
      nsaika=nsaika+1
      print'(i6,a)',i
   endif
end do
!#--支間中央の節点群
print'("*NSET,NSET=tyuuou")'
do i=1,nset
   !---高さが3/7*hの場合
   if (y(i)>h*3.d0/7-dy/2.and.y(i)<h*3.d0/7+dy/2.and.&
       &z(i)>=ell/2-saikaz/2-dz/2.and.z(i)<=ell/2+saikaz/2+dz/2.and.&
       &x(i)>=-dx/3.and.x(i)<=dx/3) then
      print'(i6,a)',i
   else if (y(i)>h*3.d0/7-dy/2.and.y(i)<h*3.d0/7+dy/2.and.&
       &z(i)>=ell/2-saikaz/2-dz/2.and.z(i)<=ell/2+saikaz/2+dz/2.and.&
       &x(i)>=b1-dx/3.and.x(i)<=b1+dx/3) then
      print'(i6,a)',i
   endif
   !---高さが中央の場合
!   if (y(i)>h/2-dy/2.and.y(i)<h/2+dy/2.and.&
!       &z(i)>=ell/2-saikaz/2-dz/2.and.z(i)<=ell/2+saikaz/2+dz/2.and.&
!       &x(i)>=-dx/3.and.x(i)<=dx/3) then
!      print'(i6,a)',i
!   else if (y(i)>h/2-dy/2.and.y(i)<h/2+dy/2.and.&
!       &z(i)>=ell/2-saikaz/2-dz/2.and.z(i)<=ell/2+saikaz/2+dz/2.and.&
!       &x(i)>=b1-dx/3.and.x(i)<=b1+dx/3) then
!      print'(i6,a)',i
!   endif
end do
!---境界条件
print'("*BOUNDARY")'
print'("kotei1,1,3")'
print'("kotei2,1,2")'
!---材料設定
print'("*MATERIAL,NAME=EL1")'
!print'("*ELASTIC")'!等方性
!print'(f12.4,a,f12.4)',ezz,',',poizx
print'("*ELASTIC,TYPE=ORTHO")'
call ortho(e66,exx,eyy,ezz,poixy,poixz,poiyz,gyz,&
& gxz,gxy,poiyx,poizx,poizy)
print'(f12.4,a,f12.4,a,f12.4,a,&
     &f12.4,a,f12.4,a,f12.4,a,f12.4,&
     & a ,f12.4,a)',&
     &e66(1,1),',',e66(1,2),',',e66(2,2),',',e66(1,3),','& 
     &,e66(2,3),',',e66(3,3),',',e66(6,6),',',e66(5,5),','
print'(f12.4)',e66(4,4)
print'("*PLASTIC")'!弾塑性
print'("20,0")'
print'("22,0.05")'
print'("24,0.20")'
print'("26,0.70")'
!#--局所座標系の設定
print'("*ORIENTATION,NAME=OR1,SYSTEM=RECTANGULAR")'
print'("1.,0.,0.,0.,1.,0.")'!全体座標系と一致
print'("*ORIENTATION,NAME=OR2,SYSTEM=RECTANGULAR")'
print'("0.,0.,-1.,0.,1.,0.")'!y軸回りに90度回転
print'("*SOLID SECTION,ELSET=E1,MATERIAL=EL1,ORIENTATION=OR1")'
print'("*SOLID SECTION,ELSET=E2,MATERIAL=EL1,ORIENTATION=OR2")'
print'("*SOLID SECTION,ELSET=E3,MATERIAL=EL1,ORIENTATION=OR1")'
print'("*SOLID SECTION,ELSET=E4,MATERIAL=EL1,ORIENTATION=OR2")'
print'("*SOLID SECTION,ELSET=E5,MATERIAL=EL1,ORIENTATION=OR1")'
print'("*SOLID SECTION,ELSET=E6,MATERIAL=EL1,ORIENTATION=OR2")'
print'("*SOLID SECTION,ELSET=E7,MATERIAL=EL1,ORIENTATION=OR1")'
!#--出力ステップ
print'("*TIME POINTS,NAME=T1")'
do i=0,10
   ts=real(i)/10
   print'(f12.4,a)',ts,','
enddo
!---繰り返し載荷
do i=1,ndankai
   do j=1,nhanpuku(i)
   !#--載荷
      !---載荷条件
      print'("*STEP,INC=200000000")'
      print'("*STATIC,SOLVER=SPOOLES")'
      print'("*CLOAD")'
      print'(A,a,i6,a,1pe13.5)','saika',',',2,',',p(i)/nsaika
      !#--datファイルの設定
      print'("*NODE PRINT,NSET=tyuuou,TIMEPOINTS=T1")'
      print'("U")'
      !print'("*EL PRINT,ELSET=,TIMEPOINTS=T1")'
      !print'("S")'
      print'("*NODE FILE,TIMEPOINTS=T1")'
      print'("U")'
      print'("*EL FILE,TIMEPOINTS=T1")'
      print'("S")'
      print'("*END STEP")'
   !#--除荷
      !---載荷条件
      print'("*STEP,INC=200000000")'
      print'("*STATIC,SOLVER=SPOOLES")'
      print'("*CLOAD,OP=NEW")'
      print'(A,a,i6,a,1pe13.5)','saika',',',2,',',0.d0
      !#--datファイルの設定
      print'("*NODE PRINT,NSET=tyuuou,TIMEPOINTS=T1")'
      print'("U")'
      !print'("*EL PRINT,ELSET=,TIMEPOINTS=T1")'
      !print'("S")'
      print'("*NODE FILE,TIMEPOINTS=T1")'
      print'("U")'
      print'("*EL FILE,TIMEPOINTS=T1")'
      print'("S")'
      print'("*END STEP")'
   enddo
enddo

end

!-------- 直交異方性の定数を出すプログラム --------
subroutine ortho(e66,exx,eyy,ezz,poixy,poixz,poiyz,gyz,&
&gxz,gxy,poiyx,poizx,poizy)
implicit none
real :: e66(6,6),b(3,3)
real exx,eyy,ezz,poixy,poixz,poiyz,gyz,gxz,gxy,poiyx,poizx,poizy
real det
integer i,j
!implicit real*8(a-h,o-z)
! e66(6,6),b(3,3)
!応力－ひずみ行列：e66
!do i=1,6
!do j=1,6
!e66(i,j)=0.d0
!end do
!end do
e66=0.d0
e66(1,1)=1.d0/exx
e66(1,2)=-poixy/exx
e66(1,3)=-poixz/exx
e66(2,1)=-poiyx/eyy
e66(2,2)=1.d0/eyy
e66(2,3)=-poiyz/eyy
e66(3,1)=-poizx/ezz
e66(3,2)=-poizy/ezz
e66(3,3)=1.d0/ezz

!****** 逆行列を取って、応力－ひずみ行列に変換する******
det=e66(1,1)*e66(2,2)*e66(3,3)+e66(2,1)*e66(3,2)*e66(1,3)&
&+e66(3,1)*e66(1,2)*e66(2,3)-e66(2,1)*e66(1,2)*e66(3,3)&
&-e66(3,1)*e66(2,2)*e66(1,3)-e66(1,1)*e66(3,2)*e66(2,3)
b(1,1)=(-1.d0)**(1+1)*(e66(2,2)*e66(3,3)-e66(3,2)*e66(2,3))
b(1,2)=(-1.d0)**(1+2)*(e66(2,1)*e66(3,3)-e66(3,1)*e66(2,3))
b(1,3)=(-1.d0)**(1+3)*(e66(2,1)*e66(3,2)-e66(3,1)*e66(2,2))
b(2,1)=(-1.d0)**(2+1)*(e66(1,2)*e66(3,3)-e66(3,2)*e66(1,3))
b(2,2)=(-1.d0)**(2+2)*(e66(1,1)*e66(3,3)-e66(3,1)*e66(1,3))
b(2,3)=(-1.d0)**(2+3)*(e66(1,1)*e66(3,2)-e66(3,1)*e66(1,2))
b(3,1)=(-1.d0)**(3+1)*(e66(1,2)*e66(2,3)-e66(2,2)*e66(1,3))
b(3,2)=(-1.d0)**(3+2)*(e66(1,1)*e66(2,3)-e66(2,1)*e66(1,3))
b(3,3)=(-1.d0)**(3+3)*(e66(1,1)*e66(2,2)-e66(2,1)*e66(1,2))
do i=1,3
do j=1,3
e66(i,j)=b(j,i)/det
end do
end do
!****** せん断補正係数を入力 ******
!print*,'xy面のせん断弾性係数を入れて下さい'
!read*, gxy
e66(4,4)=gyz
!print*,'xz面のせん断弾性係数を入れて下さい'
!read*, gxz
e66(5,5)=gxz
!print*,'yz面のせん断弾性係数を入れて下さい'
!read*, gyz
e66(6,6)=gxy
return
end
