#!/usr/bin/python
# -*- coding: utf-8 -*-
#-*-coding: UTF-8 -*-
from math import *
from abaqus import *
from abaqusConstants import *
from caeModules import *
from driverUtils import executeOnCaeStartup
import numpy as np
executeOnCaeStartup()
#自动找到当前model名称
viewportName = session.currentViewportName
modelNameDE=session.viewports[viewportName].displayedObject.modelName
#此脚本修改节点后不能恢复,推荐复制出新的part进行修改
#输入函数
#前半为提示,后半为默认参数
field = ( ('model名称:',modelNameDE),
('part名称:','Part-5'),('part的set名:','Set-1'),
('磨耗深度:','10')
)
#getInputs函数接受的参数与上面一一对应
modelname,\
Part,PartSet,A=getInputs(field,dialogTitle='创建多边形')
A=float(A)
p = mdb.models[modelname].parts[Part]
n = p.sets[PartSet].nodes
#直角坐标转极坐标
def Rectangular_to_Polar(x,y): # 直角坐标转极坐标,计算时thata为角度值,输出的thata为弧度值
r = np.sqrt(np.square(x) + np.square(y))
if x==0.0 and y>0:
theta = 90
elif x==0.0 and y<0:
theta = 270
elif x>0:
if y>0:#一象限
theta = np.degrees(np.arctan(y / x))
else:#四象限
theta = 360 + np.degrees(np.arctan(y / x))
elif x<0:#二三象限
theta = 180.0 + np.degrees(np.arctan(y / x))
theta = theta * (np.pi / 180)
#round函数为保留小数位数
return round(r, 5), round(theta, 5)
#极坐标转直角坐标
def Polar_to_Rectangular(r, theta):
x = r * np.cos(theta)
y = r * np.sin(theta)
return round(x, 2), round(y, 2)
#玫瑰线
def Rosette(r,theta):
#A为磨耗波深度
r = r - 0.5*A*(1-np.cos(24*theta))
return r
for i in n:
r, theta = Rectangular_to_Polar(i.coordinates[0],i.coordinates[1])
#上面coordinates[0]为x轴,coordinates[1]为y轴,coordinates[2]为z轴
R = Rosette(r,theta)
x,y = Polar_to_Rectangular(R, theta)
#print(R,theta,x,y)
#此处coordinate1为x轴,coordinate2为y轴,coordinate3为z轴
p.editNode(nodes=i,coordinate1=x,coordinate2=y)
abaqus圆形变多边形脚本