본문 바로가기

YADE

Body의 이해

YADE Body의 이해

 

YADE에서 모델을 구성하는 Particle, Facet등은 Shape인 상태에서는 구체화 되지 않는다.

모델 스페이스내에서 구체화 되기 위해서는 인스턴스가 Body로 선언되어야 한다.

 

예를 들어보자

In [34]: Sphere
Out[34]: yade.wrapper.Sphere

Sphere는 클래스이다.

In [35]: s=Sphere()
In [36]: s
Out[36]: <Sphere instance at 0x5647d8195fd0>

위의 작업을 통해 인스턴스로 구체화 된다.

In [37]: O.bodies
Out[37]: <yade.wrapper.BodyContainer at 0x7fe2e097adc0>

O.bodies는 Body를 담고있는 컨테이너이다. 여기에 Sphere를 담아야 하나, Sphere는 Body가 아니라 Shape을 정의 한다고 봐야된다.

 

그래서, 단순히 Sphere인스턴스를 바디 컨테이너에 넣으려고 하면 아래와 같은 에러를 보게 된다.

In [38]: O.bodies.append(s)
---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
/usr/bin/yade in <module> ----> 1 O.bodies.append(s)

ArgumentError: Python argument types in BodyContainer.append(BodyContainer, Sphere) did not match C++ signature:
    append(yade::pyBodyContainer {lvalue}, std::vector<boost::shared_ptr<yade::Body>, std:: allocator<boost::shared_ptr<yade::Body> > >)
    append(yade::pyBodyContainer {lvalue}, boost::shared_ptr<yade::Body>)

 

일단 Sphere 인스턴스인 s의 반지름을 정의하고,

In [39]: s.radius=2

 

Sphere Body를 하나 만들어 보자

In [18]: ss=utils.sphere()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/usr/bin/yade in <module> ----> 1 ss=utils.sphere()
TypeError: sphere() missing 2 required positional arguments: 'center' and 'radius'

 

Body는 utils를 이용해서 만들어진다. utils.sphere()를 사용하려면 적어도 2개의 arguments를 써야 된다고 한다.

그렇다면,

In [19]: ss=utils.sphere((0,0,0),radius=1)
In [20]: ss
Out[20]: <Body instance at 0x5647d7d2d180>

이렇게 하면 좌표 (0,0,0)에 반지름 1인 sphere Body가 하나 생겼다.

 

이걸 Sphere 인스턴스로 Shape를 변경하는 것이 가능하다

In [21]: s
Out[21]: <Sphere instance at 0x5647d8040550>

In [22]: ss.shape
Out[22]: <Sphere instance at 0x5647d7f01b90>

In [23]: ss.shape = s

이렇게,

 

'YADE' 카테고리의 다른 글

Body의 상태 확인방법  (0) 2023.01.07
O.engines 내용 확인방법  (1) 2023.01.06
YADE의 좌표표시  (0) 2022.12.22
Class, wrapper 확인  (1) 2022.12.16
Omega.run - 제어화면 표시 방법  (0) 2022.12.11