【发布时间】:2016-02-06 05:58:48
【问题描述】:
我想创建一个有限元面向对象的程序。我有一个类 Node。由于有限元网格中的节点(由 Mesh 类表示)是不同的,因此我创建了 Node 类作为值类。当我从类 Node 实例化对象数组时,我将该对象数组分配给 Mesh 的节点属性。我也有一个 Element 类,代表一个有限元。我还从这个类创建了一个对象数组并将其分配给 Mesh 的元素属性。到现在都清楚了。
由于有限元节点也属于元素,我想将一些节点分配给适当的元素。但是复制节点会导致数据冗余,因此我想将指针分配给 Node 对象,以便 Element 的 localNodes 属性包含一个数组指向特定节点的指针。我应该如何修改下面的类来实现它?
节点类:
classdef Node
properties
coordinate;
end
methods
% Not interesting for this example
end
end
元素类:
classdef Element
properties
localNodes; % the object instantiated from the class Element
% will store an array of pointers to the
% appropriate elements of the object array stored
% in Mesh.nodes. How can I assign these pointers
% to Element.localNodes?
end
methods
% Not interesting for this example
end
end
Mesh类:
classdef Mesh
properties
nodes; % its object will contain an object array of Node
elements; % its object will contain an object array of Element
end
methods
% Not interesting for this example
end
end
【问题讨论】: