Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sub-scaffolds #47

Merged
merged 14 commits into from
Apr 9, 2019
130 changes: 130 additions & 0 deletions scaffoldmaker/meshtypes/meshtype_1d_path1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
"""
Generates a 1-D path mesh.
"""

from __future__ import division
import math
from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base
from scaffoldmaker.utils import zinc_utils
from opencmiss.zinc.element import Element, Elementbasis
from opencmiss.zinc.field import Field
from opencmiss.zinc.node import Node

class MeshType_1d_path1(Scaffold_base):
'''
classdocs
'''
@staticmethod
def getName():
return '1D Path 1'

@staticmethod
def getDefaultOptions(parameterSetName='Default'):
return {
'Coordinate dimensions' : 3,
'Length' : 1.0,
'Number of elements' : 1
}

@staticmethod
def getOrderedOptionNames():
return [
'Coordinate dimensions',
'Length',
'Number of elements'
]

@staticmethod
def checkOptions(options):
if (options['Coordinate dimensions'] < 1) :
options['Coordinate dimensions'] = 1
elif (options['Coordinate dimensions'] > 3) :
options['Coordinate dimensions'] = 3
if (options['Number of elements'] < 1) :
options['Number of elements'] = 1

@staticmethod
def generateMesh(region, options):
"""
:param region: Zinc region to define model in. Must be empty.
:param options: Dict containing options. See getDefaultOptions().
:return: None
"""
coordinateDimensions = options['Coordinate dimensions']
length = options['Length']
elementsCount = options['Number of elements']

fm = region.getFieldmodule()
fm.beginChange()
coordinates = zinc_utils.getOrCreateCoordinateField(fm, componentsCount=coordinateDimensions)
cache = fm.createFieldcache()

#################
# Create nodes
#################

nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
nodetemplate = nodes.createNodetemplate()
nodetemplate.defineField(coordinates)
nodetemplate.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_VALUE, 1)
nodetemplate.setValueNumberOfVersions(coordinates, -1, Node.VALUE_LABEL_D_DS1, 1)

nodeIdentifier = 1
x = [ 0.0, 0.0, 0.0 ]
dx_ds1 = [ length/elementsCount, 0.0, 0.0 ]
for n in range(elementsCount + 1):
x[0] = length*n/elementsCount
node = nodes.createNode(nodeIdentifier, nodetemplate)
cache.setNode(node)
coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1, x)
coordinates.setNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1, dx_ds1)
nodeIdentifier = nodeIdentifier + 1

#################
# Create elements
#################

mesh = fm.findMeshByDimension(1)
cubicHermiteBasis = fm.createElementbasis(1, Elementbasis.FUNCTION_TYPE_CUBIC_HERMITE)
eft = mesh.createElementfieldtemplate(cubicHermiteBasis)
elementtemplate = mesh.createElementtemplate()
elementtemplate.setElementShapeType(Element.SHAPE_TYPE_LINE)
result = elementtemplate.defineField(coordinates, -1, eft)

elementIdentifier = 1
for e in range(elementsCount):
element = mesh.createElement(elementIdentifier, elementtemplate)
element.setNodesByIdentifier(eft, [ e + 1, e + 2 ])
elementIdentifier = elementIdentifier + 1

fm.endChange()


def extractPathParametersFromRegion(region):
'''
Returns parameters of all nodes in region in identifier order.
Assumes nodes in region have field coordinates (1 to 3 components).
Currently limited to nodes with exactly value and d_ds1, same as path 1 scaffold.
:return: cx, cd1 (all padded with zeroes to 3 components)
'''
fm = region.getFieldmodule()
coordinates = fm.findFieldByName('coordinates').castFiniteElement()
componentsCount = coordinates.getNumberOfComponents()
assert componentsCount in [ 1, 2, 3 ], 'extractPathParametersFromRegion. Invalid coordinates number of components'
cache = fm.createFieldcache()
cx = []
cd1 = []
nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
nodeIter = nodes.createNodeiterator()
node = nodeIter.next()
while node.isValid():
cache.setNode(node)
result, x = coordinates.getNodeParameters(cache, -1, Node.VALUE_LABEL_VALUE, 1, componentsCount)
result, d1 = coordinates.getNodeParameters(cache, -1, Node.VALUE_LABEL_D_DS1, 1, componentsCount)
for c in range(componentsCount, 3):
x.append(0.0)
d1.append(0.0)
cx.append(x)
cd1.append(d1)
node = nodeIter.next()
return cx, cd1
11 changes: 2 additions & 9 deletions scaffoldmaker/meshtypes/meshtype_2d_plate1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import division
import math
from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base
from scaffoldmaker.utils import zinc_utils
from opencmiss.zinc.element import Element, Elementbasis
from opencmiss.zinc.field import Field
from opencmiss.zinc.node import Node
Expand Down Expand Up @@ -60,15 +61,7 @@ def generateMesh(region, options):

fm = region.getFieldmodule()
fm.beginChange()
coordinates = fm.createFieldFiniteElement(coordinateDimensions)
coordinates.setName('coordinates')
coordinates.setManaged(True)
coordinates.setTypeCoordinate(True)
coordinates.setCoordinateSystemType(Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN)
coordinates.setComponentName(1, 'x')
coordinates.setComponentName(2, 'y')
if coordinateDimensions == 3:
coordinates.setComponentName(3, 'z')
coordinates = zinc_utils.getOrCreateCoordinateField(fm, componentsCount=coordinateDimensions)

nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
nodetemplate = nodes.createNodetemplate()
Expand Down
11 changes: 2 additions & 9 deletions scaffoldmaker/meshtypes/meshtype_2d_platehole1.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import math
from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base
from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative
from scaffoldmaker.utils import zinc_utils
from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate
from opencmiss.zinc.field import Field
from opencmiss.zinc.node import Node
Expand Down Expand Up @@ -77,15 +78,7 @@ def generateMesh(region, options):

fm = region.getFieldmodule()
fm.beginChange()
coordinates = fm.createFieldFiniteElement(coordinateDimensions)
coordinates.setName('coordinates')
coordinates.setManaged(True)
coordinates.setTypeCoordinate(True)
coordinates.setCoordinateSystemType(Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN)
coordinates.setComponentName(1, 'x')
coordinates.setComponentName(2, 'y')
if coordinateDimensions == 3:
coordinates.setComponentName(3, 'z')
coordinates = zinc_utils.getOrCreateCoordinateField(fm, componentsCount=coordinateDimensions)

nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
nodetemplate = nodes.createNodetemplate()
Expand Down
10 changes: 2 additions & 8 deletions scaffoldmaker/meshtypes/meshtype_2d_sphere1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import division
import math
from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base
from scaffoldmaker.utils import zinc_utils
from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate
from opencmiss.zinc.field import Field
from opencmiss.zinc.node import Node
Expand Down Expand Up @@ -53,14 +54,7 @@ def generateMesh(region, options):

fm = region.getFieldmodule()
fm.beginChange()
coordinates = fm.createFieldFiniteElement(3)
coordinates.setName('coordinates')
coordinates.setManaged(True)
coordinates.setTypeCoordinate(True)
coordinates.setCoordinateSystemType(Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN)
coordinates.setComponentName(1, 'x')
coordinates.setComponentName(2, 'y')
coordinates.setComponentName(3, 'z')
coordinates = zinc_utils.getOrCreateCoordinateField(fm)

nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
nodetemplateApex = nodes.createNodetemplate()
Expand Down
10 changes: 2 additions & 8 deletions scaffoldmaker/meshtypes/meshtype_2d_tube1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from __future__ import division
import math
from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base
from scaffoldmaker.utils import zinc_utils
from opencmiss.zinc.element import Element, Elementbasis
from opencmiss.zinc.field import Field
from opencmiss.zinc.node import Node
Expand Down Expand Up @@ -53,14 +54,7 @@ def generateMesh(region, options):

fm = region.getFieldmodule()
fm.beginChange()
coordinates = fm.createFieldFiniteElement(3)
coordinates.setName('coordinates')
coordinates.setManaged(True)
coordinates.setTypeCoordinate(True)
coordinates.setCoordinateSystemType(Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN)
coordinates.setComponentName(1, 'x')
coordinates.setComponentName(2, 'y')
coordinates.setComponentName(3, 'z')
coordinates = zinc_utils.getOrCreateCoordinateField(fm)

nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
nodetemplate = nodes.createNodetemplate()
Expand Down
4 changes: 2 additions & 2 deletions scaffoldmaker/meshtypes/meshtype_3d_box1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base
from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite
from scaffoldmaker.utils.meshrefinement import MeshRefinement
from scaffoldmaker.utils.zinc_utils import *
from scaffoldmaker.utils import zinc_utils
from opencmiss.zinc.element import Element, Elementbasis
from opencmiss.zinc.field import Field
from opencmiss.zinc.node import Node
Expand Down Expand Up @@ -73,7 +73,7 @@ def generateBaseMesh(region, options):

fm = region.getFieldmodule()
fm.beginChange()
coordinates = getOrCreateCoordinateField(fm)
coordinates = zinc_utils.getOrCreateCoordinateField(fm)

nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
nodetemplate = nodes.createNodetemplate()
Expand Down
10 changes: 2 additions & 8 deletions scaffoldmaker/meshtypes/meshtype_3d_boxhole1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from scaffoldmaker.meshtypes.scaffold_base import Scaffold_base
from scaffoldmaker.utils.eftfactory_tricubichermite import eftfactory_tricubichermite
from scaffoldmaker.utils.interpolation import interpolateCubicHermite, interpolateCubicHermiteDerivative
from scaffoldmaker.utils import zinc_utils
from opencmiss.zinc.element import Element, Elementbasis, Elementfieldtemplate
from opencmiss.zinc.field import Field
from opencmiss.zinc.node import Node
Expand Down Expand Up @@ -76,14 +77,7 @@ def generateMesh(region, options):

fm = region.getFieldmodule()
fm.beginChange()
coordinates = fm.createFieldFiniteElement(3)
coordinates.setName('coordinates')
coordinates.setManaged(True)
coordinates.setTypeCoordinate(True)
coordinates.setCoordinateSystemType(Field.COORDINATE_SYSTEM_TYPE_RECTANGULAR_CARTESIAN)
coordinates.setComponentName(1, 'x')
coordinates.setComponentName(2, 'y')
coordinates.setComponentName(3, 'z')
coordinates = zinc_utils.getOrCreateCoordinateField(fm)

nodes = fm.findNodesetByFieldDomainType(Field.DOMAIN_TYPE_NODES)
nodetemplate = nodes.createNodetemplate()
Expand Down
Loading