HiveBrain v1.2.0
Get Started
← Back to all entries
patternphpMinor

Nodes and Boundary Conditions in Finite Element Method

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
nodesfinitemethodboundaryelementconditionsand

Problem

The problem:

  • A Node is located in a specific coordinate (x, y, z).



  • A Node can be one of these types: None, Hinge, Roll, Fixed. (it is called Boundary Condition)


Different boundary condition type determine a Node's Degree of Freedom.

I have one Abstract NodeBase class and multiple classes of nodes inheriting them. Please check if this is a good approach.

I also have some Abstract Data Types, such as Coordinate, ForceSet, DisplacementSet. They are classes containing only public variables. (want to use them as structs, like in C++)

NodeBase.php:

```
abstract class NodeBase {

/** @var Coordinate */
protected $coordinate;

/** @var ForceSet */
protected $forces;

/** @var DisplacementSet */
protected $displacements;

/** @var int index / ordering of this node in a project */
protected $idNumber;

/** @var int static variable, giving each node a unique Id Number */
private static $idCounter = 0;

/** @var double $localAngle local rotation of the node */
protected $localAngle;

public function __construct(array $params = null)
{
// For Generating ID Numbers (starting from 1)
self::$idCounter++;

// Initialization
$this->coordinate = new Coordinate();
$this->forces = new ForceSet();
$this->displacements = new DisplacementSet();
$this->idNumber = self::$idCounter;

// Assign values with parameter (if exists)
if (isset($params))
{
if (isset($params['x']))
{
$this->coordinate->x = $params['x'];
}
if (isset($params['y']))
{
$this->coordinate->y = $params['y'];
}
if (isset($params['angle']))
{
$this->localAngle = $params['angle'];
}
}
}

public function setCoordXY($x, $y)
{
$this->coordinate->x = $x;
$this->coordinate->

Solution

It all looks good to me, though you can simplify your NodeBase getForce() and getDisplacement() methods if you use variable properties, like so:

public function getForce($forceName)
{
    if(isset($this->forces->$forceName))
    {
        return $this->forces->$forceName;
    }
}

public function getDisplacement($dispName)
{
    if(isset($this->displacements->$dispName))
    {
        return $this->displacements->$dispName;
    }
}


Which will save you a lot of rewriting if you decide to change the names of any of the properties down the line

Code Snippets

public function getForce($forceName)
{
    if(isset($this->forces->$forceName))
    {
        return $this->forces->$forceName;
    }
}

public function getDisplacement($dispName)
{
    if(isset($this->displacements->$dispName))
    {
        return $this->displacements->$dispName;
    }
}

Context

StackExchange Code Review Q#56352, answer score: 3

Revisions (0)

No revisions yet.