def addStrainsFromDeformationGradients( mesh, defo_grad_array_name="DeformationGradient", strain_array_name="Strain", mesh_w_local_basis=None, verbose=0): mypy.my_print(verbose, "*** addStrainsFromDeformationGradients ***") assert (mesh.GetCellData().HasArray(defo_grad_array_name)) farray_f = mesh.GetCellData().GetArray(defo_grad_array_name) n_cells = mesh.GetNumberOfCells() if (mesh_w_local_basis is not None): farray_strain = myvtk.createFloatArray(name=strain_array_name + "_CAR", n_components=6, n_tuples=n_cells) else: farray_strain = myvtk.createFloatArray(name=strain_array_name, n_components=6, n_tuples=n_cells) mesh.GetCellData().AddArray(farray_strain) I = numpy.eye(3) E_vec = numpy.empty(6) #e_vec = numpy.empty(6) for k_cell in range(n_cells): F = numpy.reshape(farray_f.GetTuple(k_cell), (3, 3), order="C") C = numpy.dot(numpy.transpose(F), F) E = (C - I) / 2 mypy.mat_sym33_to_vec_col6(E, E_vec) farray_strain.SetTuple(k_cell, E_vec) #if (add_almansi_strain): #Finv = numpy.linalg.inv(F) #c = numpy.dot(numpy.transpose(Finv), Finv) #e = (I - c)/2 #mypy.mat_sym33_to_vec_col6(e, e_vec) #farray_almansi.SetTuple(k_cell, e_vec) if (mesh_w_local_basis is not None): if (mesh_w_local_basis.GetCellData().HasArray("eR"))\ and (mesh_w_local_basis.GetCellData().HasArray("eC"))\ and (mesh_w_local_basis.GetCellData().HasArray("eL")): farray_strain_cyl = myvtk.rotateMatrixArray( old_array=mesh.GetCellData().GetArray(strain_array_name + "_CAR"), out_vecs=[ mesh_w_local_basis.GetCellData().GetArray("eR"), mesh_w_local_basis.GetCellData().GetArray("eC"), mesh_w_local_basis.GetCellData().GetArray("eL") ], verbose=0) farray_strain_cyl.SetName(strain_array_name + "_CYL") mesh.GetCellData().AddArray(farray_strain_cyl) if (mesh_w_local_basis.GetCellData().HasArray("eRR"))\ and (mesh_w_local_basis.GetCellData().HasArray("eCC"))\ and (mesh_w_local_basis.GetCellData().HasArray("eLL")): farray_strain_pps = myvtk.rotateMatrixArray( old_array=mesh.GetCellData().GetArray(strain_array_name + "_CAR"), out_vecs=[ mesh_w_local_basis.GetCellData().GetArray("eRR"), mesh_w_local_basis.GetCellData().GetArray("eCC"), mesh_w_local_basis.GetCellData().GetArray("eLL") ], verbose=0) farray_strain_pps.SetName(strain_array_name + "_PPS") mesh.GetCellData().AddArray(farray_strain_pps)
def rotateMatrixArray(old_array, old_array_storage="vec", in_vecs=None, R=None, out_vecs=None, verbose=0): mypy.my_print(verbose, "*** rotateMatrixArray ***") mypy.my_print( min(verbose, 1), "*** Warning: in rotateMatrixArray, the definition of the global rotation is probably the inverse of the definition in previous rotateTensors function. ***" ) n_components = old_array.GetNumberOfComponents() if (old_array_storage == "vec"): assert (n_components == 6 ), "Wrong number of components (n_components=" + str( n_components) + "). Aborting." elif (old_array_storage == "Cmat"): assert (n_components == 9 ), "Wrong number of components (n_components=" + str( n_components) + "). Aborting." elif (old_array_storage == "Fmat"): assert (n_components == 9 ), "Wrong number of components (n_components=" + str( n_components) + "). Aborting." else: assert (0), "Wrong storage (old_array_storage=" + str( old_array_storage) + "). Aborting." n_tuples = old_array.GetNumberOfTuples() new_array = myvtk.createFloatArray(old_array.GetName(), n_components, n_tuples) new_vector = numpy.empty(n_components) if (old_array_storage == "vec"): old_vector = numpy.empty(6) elif (old_array_storage == "Cmat"): old_vector = numpy.empty(9) elif (old_array_storage == "Fmat"): old_vector = numpy.empty(9) old_matrix = numpy.empty((3, 3)) new_matrix = numpy.empty((3, 3)) for k_tuple in xrange(n_tuples): old_array.GetTuple(k_tuple, old_vector) if (old_array_storage == "vec"): mypy.vec_col6_to_mat_sym33(old_vector, old_matrix) elif (old_array_storage == "Cmat"): mypy.cvec9_to_mat33(old_vector, old_matrix) elif (old_array_storage == "Fmat"): mypy.fvec9_to_mat33(old_vector, old_matrix) if (in_vecs is None): in_R = numpy.eye(3) else: in_R = numpy.transpose( numpy.array([ in_vecs[0].GetTuple(k_tuple), in_vecs[1].GetTuple(k_tuple), in_vecs[2].GetTuple(k_tuple) ])) if (out_vecs is None): out_R = numpy.eye(3) else: out_R = numpy.transpose( numpy.array([ out_vecs[0].GetTuple(k_tuple), out_vecs[1].GetTuple(k_tuple), out_vecs[2].GetTuple(k_tuple) ])) if (R is None): R = numpy.eye(3) full_R = numpy.dot(numpy.dot(numpy.transpose(in_R), R), out_R) new_matrix[:] = numpy.dot( numpy.dot(numpy.transpose(full_R), old_matrix), full_R) if (old_array_storage == "vec"): mypy.mat_sym33_to_vec_col6(new_matrix, new_vector) elif (old_array_storage == "Cmat"): mypy.mat33_to_cvec9(new_matrix, new_vector) elif (old_array_storage == "Fmat"): mypy.mat33_to_fvec9(new_matrix, new_vector) new_array.SetTuple(k_tuple, new_vector) return new_array
def rotateMatrixArray( old_array, old_array_storage="vec", in_vecs=None, R=None, out_vecs=None, verbose=0): mypy.my_print(verbose, "*** rotateMatrixArray ***") mypy.my_print(min(verbose,1), "*** Warning: in rotateMatrixArray, the definition of the global rotation is probably the inverse of the definition in previous rotateTensors function. ***") n_components = old_array.GetNumberOfComponents() if (old_array_storage == "vec"): assert (n_components == 6), "Wrong numpber of components (n_components="+str(n_components)+"). Aborting." elif (old_array_storage == "Cmat"): assert (n_components == 9), "Wrong numpber of components (n_components="+str(n_components)+"). Aborting." elif (old_array_storage == "Fmat"): assert (n_components == 9), "Wrong numpber of components (n_components="+str(n_components)+"). Aborting." else: assert (0), "Wrong storage (old_array_storage="+str(old_array_storage)+"). Aborting." n_tuples = old_array.GetNumberOfTuples() new_array = myvtk.createFloatArray(old_array.GetName(), n_components, n_tuples) new_vector = numpy.empty(n_components) if (old_array_storage == "vec"): old_vector = numpy.empty(6) elif (old_array_storage == "Cmat"): old_vector = numpy.empty(9) elif (old_array_storage == "Fmat"): old_vector = numpy.empty(9) old_matrix = numpy.empty((3,3)) new_matrix = numpy.empty((3,3)) for k_tuple in xrange(n_tuples): old_array.GetTuple(k_tuple, old_vector) if (old_array_storage == "vec"): mypy.vec_col6_to_mat_sym33(old_vector, old_matrix) elif (old_array_storage == "Cmat"): mypy.cvec9_to_mat33(old_vector, old_matrix) elif (old_array_storage == "Fmat"): mypy.fvec9_to_mat33(old_vector, old_matrix) if (in_vecs is None): in_R = numpy.eye(3) else: in_R = numpy.transpose(numpy.array([in_vecs[0].GetTuple(k_tuple), in_vecs[1].GetTuple(k_tuple), in_vecs[2].GetTuple(k_tuple)])) if (out_vecs is None): out_R = numpy.eye(3) else: out_R = numpy.transpose(numpy.array([out_vecs[0].GetTuple(k_tuple), out_vecs[1].GetTuple(k_tuple), out_vecs[2].GetTuple(k_tuple)])) if (R is None): R = numpy.eye(3) full_R = numpy.dot(numpy.dot(numpy.transpose(in_R), R), out_R) new_matrix[:] = numpy.dot(numpy.dot(numpy.transpose(full_R), old_matrix), full_R) if (old_array_storage == "vec"): mypy.mat_sym33_to_vec_col6(new_matrix, new_vector) elif (old_array_storage == "Cmat"): mypy.mat33_to_cvec9(new_matrix, new_vector) elif (old_array_storage == "Fmat"): mypy.mat33_to_fvec9(new_matrix, new_vector) new_array.SetTuple(k_tuple, new_vector) return new_array
def addStrainsFromDeformationGradients( mesh, defo_grad_array_name="DeformationGradient", strain_array_name="Strain", mesh_w_local_basis=None, verbose=0): mypy.my_print(verbose, "*** addStrainsFromDeformationGradients ***") assert (mesh.GetCellData().HasArray(defo_grad_array_name)) farray_f = mesh.GetCellData().GetArray(defo_grad_array_name) n_cells = mesh.GetNumberOfCells() if (mesh_w_local_basis is not None): farray_strain = myvtk.createFloatArray( name=strain_array_name+"_CAR", n_components=6, n_tuples=n_cells) else: farray_strain = myvtk.createFloatArray( name=strain_array_name, n_components=6, n_tuples=n_cells) mesh.GetCellData().AddArray(farray_strain) I = numpy.eye(3) E_vec = numpy.empty(6) #e_vec = numpy.empty(6) for k_cell in range(n_cells): F = numpy.reshape(farray_f.GetTuple(k_cell), (3,3), order="C") C = numpy.dot(numpy.transpose(F), F) E = (C - I)/2 mypy.mat_sym33_to_vec_col6(E, E_vec) farray_strain.SetTuple(k_cell, E_vec) #if (add_almansi_strain): #Finv = numpy.linalg.inv(F) #c = numpy.dot(numpy.transpose(Finv), Finv) #e = (I - c)/2 #mypy.mat_sym33_to_vec_col6(e, e_vec) #farray_almansi.SetTuple(k_cell, e_vec) if (mesh_w_local_basis is not None): if (mesh_w_local_basis.GetCellData().HasArray("eR"))\ and (mesh_w_local_basis.GetCellData().HasArray("eC"))\ and (mesh_w_local_basis.GetCellData().HasArray("eL")): farray_strain_cyl = myvtk.rotateMatrixArray( old_array=mesh.GetCellData().GetArray(strain_array_name+"_CAR"), out_vecs=[mesh_w_local_basis.GetCellData().GetArray("eR"), mesh_w_local_basis.GetCellData().GetArray("eC"), mesh_w_local_basis.GetCellData().GetArray("eL")], verbose=0) farray_strain_cyl.SetName(strain_array_name+"_CYL") mesh.GetCellData().AddArray(farray_strain_cyl) if (mesh_w_local_basis.GetCellData().HasArray("eRR"))\ and (mesh_w_local_basis.GetCellData().HasArray("eCC"))\ and (mesh_w_local_basis.GetCellData().HasArray("eLL")): farray_strain_pps = myvtk.rotateMatrixArray( old_array=mesh.GetCellData().GetArray(strain_array_name+"_CAR"), out_vecs=[mesh_w_local_basis.GetCellData().GetArray("eRR"), mesh_w_local_basis.GetCellData().GetArray("eCC"), mesh_w_local_basis.GetCellData().GetArray("eLL")], verbose=0) farray_strain_pps.SetName(strain_array_name+"_PPS") mesh.GetCellData().AddArray(farray_strain_pps)