#Calculations for Concrete02 parameters

#import all necessary package
from PyMpc import *
import math

#clear the terminal
App.clearTerminal()

# get the pre-processor document
doc = App.caeDocument()

#unit reference system N - m - s
N = 1.0
m = 1.0
s = 1.0

#derived quantities and conversions
Pa = 1*N/(m**2)
MPa = 1*Pa*1e+6

#Imput parameters and Calculations
fpc = -35.0*MPa
epsc0 = -0.002
fpcu = 0.2*fpc
epsU = -0.01
unload = 0.1
ft = -0.14*fpc
Ets = ft/abs(epsc0)

def makeConcrete02 (id,fpc,epsc0,fpcu,epsU,unload,ft,Ets):
	p = doc.getPhysicalProperty(id)
	p.XObject.getAttribute('fpc').quantityScalar.value = fpc
	p.XObject.getAttribute('epsc0').quantityScalar.value = epsc0
	p.XObject.getAttribute('fpcu').quantityScalar.value = fpcu
	p.XObject.getAttribute('epsU').quantityScalar.value = epsU
	p.XObject.getAttribute('lambda').quantityScalar.value = unload
	p.XObject.getAttribute('ft').quantityScalar.value = ft
	p.XObject.getAttribute('Ets').quantityScalar.value = Ets
	p.commitXObjectChanges()

#makeConcrete02(1,fpc,epsc0,fpcu,epsU,unload,ft,Ets)

#Generic data input
E = 2.e+11 #N/m^2
n = 0.30
G = E/(2.0*(1.0+n))
print(G)

#This function takes the properties of the "Fiber section" x-objects and multiplies it for the G of the generic material previously defined.
def makeGJ(id):
	p = doc.getPhysicalProperty(id)
	s = p.XObject.getAttribute('Fiber section').customObject
	J = s.toElasticSection().properties.J
	p.XObject.getAttribute('GJ').quantityScalar.value = G*J
	p.commitXObjectChanges()

makeGJ(3)
makeGJ(4)


