Static.py 文件源码

python
阅读 50 收藏 0 点赞 0 评论 0

项目:StructEngPy 作者: zhuoju36 项目源码 文件源码
def solve_linear_tf(model):
    """
    Linearly solve the structure.
    """
    Logger.info('Solving linear model with %d DOFs using TensorFlow...'%model.DOF)

    K_bar,F_bar,index=model.K_,model.F_,model.index
    K_bar=K_bar.astype(np.float32)
    F_bar=F_bar.astype(np.float32)
    Dvec=model.D
    #Begin a new graph
    if 'sess' in locals() and sess is not None:
        print('Close interactive session')
        sess.close()

#    with tf.device('/cpu:0'):  
    K_init = tf.placeholder(tf.float32, shape=(model.DOF, model.DOF))
    K_ = tf.Variable(K_init)
#        K_ = tf.constant(K_bar,name="stiffness")    
    F_ =  tf.Variable(np.array([F_bar.astype(np.float32)]),name="force")

#    with tf.device('/cpu:0'):
    D_=tf.matrix_solve(K_,tf.transpose(F_),name='displacement')
    sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
    print(type(K_bar),K_bar.dtype,K_bar.shape)
    sess.run(tf.global_variables_initializer(),feed_dict={K_init:K_bar})
    # run the op.
    delta=sess.run(D_)

    n_nodes=model.node_count
    #fill original displacement vector
    prev = 0
    for idx in index:
        gap=idx-prev
        if gap>0:
            delta=np.insert(delta,prev,[0]*gap)
        prev = idx + 1               
        if idx==index[-1] and idx!=n_nodes-1:
            delta = np.insert(delta,prev, [0]*(n_nodes*6-prev))
    delta += Dvec
    model.is_solved=True
    return delta
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号