import math
#from python_matrix_operations import *
import ctypes
import os
import sys
import numpy as np
import elasticity_toolbox as elast

# Polymeric matrix material without prestrin
# design parameter: fibre diameterthickness in mmm of fibre d
param_r = 0.1
param_h = 0.6
param_vol = 0.1
# eingestrain in percent
param_eigenstrain = 0.3
# height mm
h = param_h
# volume fraction
vol = param_vol
# period 
# epsilon_ = np.pi*param_r**2/(h*vol)
# Wir nutzen w\"ufel:
epsilon_ = (2*param_r)**2/(h*vol)
# gamma
gamma = h/epsilon_
# width of fibres in after rescaling to unit cell
fibre_height=2*param_r/h
fibre_width=2*param_r*h/gamma # ~0.07


# --- define geometry
def indicatorFunction(x):
    if (np.abs(x[2]+.25)<=fibre_height/2) and (np.abs(x[1])<=fibre_width/2):
        return 1  # fibre
    else :
        return 2   # matrix

# --- Number of material phases
Phases=2

# --- PHASE 1 fibre
phase1_type="isotropic"
# E in MPa and nu
E = 6
nu = 0.47
# [mu, lambda]
materialParameters_phase1 = [E/(2*(1+nu)), (E*nu)/((1+nu)*(1-2*nu))]
def prestrain_phase1(x):
    fitting_factor=1
    factor = fitting_factor*(param_eigenstrain - 0.0009)/h
    factor_quer= -factor/2 # to keep volume konstant
    return [[factor,0,0],[0,factor_quer,0],[0,0,factor_quer]]

# --- PHASE 2
# --- PHASE 1 fibre
phase2_type="isotropic"
# E in MPa and nu
E = 0.7
nu = 0.47
# [mu, lambda]
materialParameters_phase2 = [E/(2*(1+nu)), (E*nu)/((1+nu)*(1-2*nu))]
def prestrain_phase2(x):
    return [[0,0,0],[0,0,0],[0,0,0]]