3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

plantFEMで作ったメッシュオブジェクトをmatplotlibで描画する。

Last updated at Posted at 2020-10-18

plantFEMで以下のようなスクリプトを実行すると、円筒型のメッシュオブジェクトが作られます。

! server.f90
program main
    use plantFEM
    implicit none

    type(FEMDomain_) :: domain

    call domain%create(meshtype="Cylinder",x_num=10,y_num=10,z_num=10,x_len=10.0d0,y_len=3.0d0,z_len=2.0d0)
    call domain%json(name="domain.json",endl=.true.)


end program main

実行コマンドはこちらです。


./plantfem run

このメッシュオブジェクトはjson形式で保存されています。
これを、matplotlibで描画してみます。

以下が描画用スクリプトです。

import json
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

json_file = open('domain.json', 'r')
json_object = json.load(json_file)

# メッシュオブジェクト中の節点座標配列を取り出す

nodcoord = np.array(json_object["mesh"]["nodcoord"])

# 以下、matplotlibで描画
# x軸とy軸にラベル付け
fig = plt.figure()
ax = Axes3D(fig)

ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")

# 節点を描画

x = nodcoord[:,0]
y = nodcoord[:,1]
z = nodcoord[:,2]
ax.plot(x,y,z,marker="o",linestyle='None')

# 図を表示

plt.show()

なお、ここではjsonファイル名をdomain.jsonとしています。

スクリプトを実行すると、3次元の円筒メッシュの節点が描画されています。

Figure_1.png
Figure_2.png

今後は、

json_object["mesh"]["elemnod"]

にはコネクティビティ情報が格納されていますので、今後はそちらを使ってメッシュの描画を行いたいと思います。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?