Example #1
0
# Set constitutive properties
rho = 2500.0  # density, kg/m^3
E = 70e9  # elastic modulus, Pa
nu = 0.3  # poisson's ratio
kcorr = 5.0 / 6.0  # shear correction factor
ys = 350e6  # yield stress, Pa
min_thickness = 0.001
max_thickness = 0.020
thickness = 0.005

# Loop over components, creating stiffness and element object for each
num_components = struct_mesh.getNumComponents()
for i in range(num_components):
    descriptor = struct_mesh.getElementDescript(i)
    stiff = constitutive.isoFSDT(rho, E, nu, kcorr, ys, thickness, i,
                                 min_thickness, max_thickness)
    element = None
    if descriptor in ["CQUAD", "CQUADR", "CQUAD4"]:
        element = elements.MITCShell(2, stiff, component_num=i)
    struct_mesh.setElement(i, element)

# Create tacs assembler object
tacs = struct_mesh.createTACS(6)
res = tacs.createVec()
ans = tacs.createVec()
mat = tacs.createFEMat()

# Create distributed node vector from TACS Assembler object and extract the
# nodes
struct_X_vec = tacs.createNodeVec()
tacs.getNodes(struct_X_vec)
Example #2
0
# There are 6 degrees of freedom per node
vars_per_node = 6

# Create the TACS assembler object
tacs = TACS.Assembler.create(comm, vars_per_node,
                             num_nodes, num_elements)

elems = []
elem_conn = []

# Add all the elements
for j in range(ny):
    for i in range(nx):
        # Create the shell element class
        dv_num = i + nx*j
        stiff = constitutive.isoFSDT(rho, E, nu, kcorr, ys, t,
                                     dv_num, min_t, max_t)

        # stiff.setRefAxis([0.0, 1.0, 0.0])
        shell_element = elements.MITCShell(2, stiff)
        elems.append(shell_element)

        # Set the element connectivity
        elem_conn.append([i + (nx+1)*j, 
                          i+1 + (nx+1)*j,
                          i + (nx+1)*(j+1), 
                          i+1 + (nx+1)*(j+1)])
        
# Create the connectivity array
conn = np.array(elem_conn, dtype=np.intc).flatten()
ptr = np.arange(0, len(conn)+1, 4, dtype=np.intc)
Example #3
0
    def __init__(self, comm, bdf_name):
        self.comm = comm
        struct_mesh = TACS.MeshLoader(self.comm)
        struct_mesh.scanBDFFile(bdf_name)

        # Set constitutive properties
        rho = 2500.0  # density, kg/m^3
        E = 70e9  # elastic modulus, Pa
        nu = 0.3  # poisson's ratio
        kcorr = 5.0 / 6.0  # shear correction factor
        ys = 350e6  # yield stress, Pa
        min_thickness = 0.002
        max_thickness = 0.20
        thickness = 0.02

        # Loop over components, creating stiffness and element object for each
        num_components = struct_mesh.getNumComponents()
        for i in range(num_components):
            descriptor = struct_mesh.getElementDescript(i)

            # Set the design variable index
            design_variable_index = i
            stiff = constitutive.isoFSDT(rho, E, nu, kcorr, ys, thickness,
                                         design_variable_index, min_thickness,
                                         max_thickness)
            element = None

            # Create the element object
            if descriptor in ["CQUAD", "CQUADR", "CQUAD4"]:
                element = elements.MITCShell(2, stiff, component_num=i)
            struct_mesh.setElement(i, element)

        # Create tacs assembler object from mesh loader
        self.assembler = struct_mesh.createTACS(6)

        # Create the KS Function
        ksWeight = 50.0
        self.funcs = [
            functions.StructuralMass(self.assembler),
            functions.KSFailure(self.assembler, ksWeight)
        ]

        # Create the forces
        self.forces = self.assembler.createVec()
        force_array = self.forces.getArray()
        force_array[2::6] += 100.0  # uniform load in z direction
        self.assembler.applyBCs(self.forces)

        # Set up the solver
        self.ans = self.assembler.createVec()
        self.res = self.assembler.createVec()
        self.adjoint = self.assembler.createVec()
        self.dfdu = self.assembler.createVec()
        self.mat = self.assembler.createFEMat()
        self.pc = TACS.Pc(self.mat)
        subspace = 100
        restarts = 2
        self.gmres = TACS.KSM(self.mat, self.pc, subspace, restarts)

        # Scale the mass objective so that it is O(10)
        self.mass_scale = 1e-3

        # Scale the thickness variables so that they are measured in
        # mm rather than meters
        self.thickness_scale = 1000.0

        # The number of thickness variables in the problem
        self.nvars = num_components

        # The number of constraints (1 global stress constraint that
        # will use the KS function)
        self.ncon = 1

        # Initialize the base class - this will run the same problem
        # on all processors
        super(uCRM_VonMisesMassMin, self).__init__(MPI.COMM_SELF, self.nvars,
                                                   self.ncon)

        # Set the inequality options for this problem in ParOpt:
        # The dense constraints are inequalities c(x) >= 0 and
        # use both the upper/lower bounds
        self.setInequalityOptions(dense_ineq=True,
                                  use_lower=True,
                                  use_upper=True)

        # For visualization
        flag = (TACS.ToFH5.NODES | TACS.ToFH5.DISPLACEMENTS
                | TACS.ToFH5.STRAINS | TACS.ToFH5.EXTRAS)
        self.f5 = TACS.ToFH5(self.assembler, TACS.PY_SHELL, flag)
        self.iter_count = 0

        return
Example #4
0
    def __init__(self,comm,tacs_comm,model,n_tacs_procs):
        super(CRMtacs,self).__init__(comm,tacs_comm,model)

        self.tacs_proc = False
        if comm.Get_rank() < n_tacs_procs:
            self.tacs_proc = True
            struct_mesh = TACS.MeshLoader(tacs_comm)
            struct_mesh.scanBDFFile("CRM_box_2nd.bdf")

            # Set constitutive properties
            rho = 2500.0  # density, kg/m^3
            E = 70.0e9 # elastic modulus, Pa
            nu = 0.3 # poisson's ratio
            kcorr = 5.0 / 6.0 # shear correction factor
            ys = 350e6  # yield stress, Pa
            min_thickness = 0.001
            max_thickness = 0.100

            thickness = 0.015
            spar_thick = 0.015

            # Loop over components in mesh, creating stiffness and element
            # object for each
            map = np.zeros(240,dtype=int)
            num_components = struct_mesh.getNumComponents()
            for i in range(num_components):
                descript = struct_mesh.getElementDescript(i)
                comp = struct_mesh.getComponentDescript(i)
                if 'SPAR' in comp:
                    t = spar_thick
                else:
                    t = thickness
                stiff = constitutive.isoFSDT(rho, E, nu, kcorr, ys, t, i,
                                             min_thickness, max_thickness)
                element = None
                if descript in ["CQUAD", "CQUADR", "CQUAD4"]:
                    element = elements.MITCShell(2,stiff,component_num=i)
                struct_mesh.setElement(i, element)

                # Create map
                if 'LE_SPAR' in comp:
                    segnum = int(comp[-2:])
                    map[i] = segnum
                if 'TE_SPAR' in comp:
                    segnum = int(comp[-2:])
                    map[i] = segnum + 48
                if 'IMPDISP' in comp:
                    map[i] = i
                elif 'RIB' in comp:
                    segnum = int(comp[-9:-7]) - 1
                    if segnum > 3:
                        segnum -= 1
                    map[i] = segnum + 188
                if 'U_SKIN' in comp:
                    segnum = int(comp[-9:-7]) - 1
                    map[i] = segnum + 92
                if 'L_SKIN' in comp:
                    segnum = int(comp[-9:-7]) - 1
                    map[i] = segnum + 140

            self.dof = 6

            # Create tacs assembler object
            tacs = struct_mesh.createTACS(self.dof)
            res = tacs.createVec()
            ans = tacs.createVec()
            mat = tacs.createFEMat()

            # Create distributed node vector from TACS Assembler object and
            # extract the node locations
            nbodies = 1
            struct_X = []
            struct_nnodes = []
            for body in range(nbodies):
                self.struct_X_vec = tacs.createNodeVec()
                tacs.getNodes(self.struct_X_vec)
                struct_X.append(self.struct_X_vec.getArray())
                struct_nnodes.append(len(struct_X) / 3)

            tacs.setNodes(self.struct_X_vec)

            # Create the preconditioner for the corresponding matrix
            pc = TACS.Pc(mat)

            alpha = 1.0
            beta = 0.0
            gamma = 0.0
            tacs.assembleJacobian(alpha,beta,gamma,res,mat)
            pc.factor()

            # Create GMRES object for structural adjoint solves
            nrestart = 0 # number of restarts before giving up
            m = 30 # size of Krylov subspace (max # of iterations)
            gmres = TACS.KSM(mat, pc, m, nrestart)


            # Initialize member variables pertaining to TACS
            self.tacs = tacs
            self.res = res
            self.ans = ans
            self.mat = mat
            self.pc = pc
            self.struct_X = struct_X
            self.struct_nnodes = struct_nnodes
            self.gmres = gmres
            self.svsens = tacs.createVec()
            self.struct_rhs_vec = tacs.createVec()
            self.psi_S_vec = tacs.createVec()
            psi_S = self.psi_S_vec.getArray()
            self.psi_S = np.zeros((psi_S.size,self.nfunc),dtype=TACS.dtype)
            self.ans_array = []
            for scenario in range(len(model.scenarios)):
                self.ans_array.append(self.ans.getArray().copy())
        self.initialize(model.scenarios[0],model.bodies)