-
Notifications
You must be signed in to change notification settings - Fork 35
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
Changes from 5 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
171484a
Add scaffold package for nested scaffolds with edits
rchristie 5c48636
More scaffold package methods
rchristie b48baaa
Make colon central path ScaffoldPackage option
rchristie 244bc70
Restore colon checking haustra options
rchristie 9d2510f
Use common functions to find or create fields
rchristie 0980224
Remove import * for zinc_utils
rchristie 80966f1
Tidy vector, matrix utils imports and use
rchristie 4e538b9
Tidy tubemesh imports and use
rchristie 3cf8225
Tidy interpolation imports and use
rchristie 4af8c45
Tidy geometry imports
rchristie 0245811
Tidy eft_utils imports
rchristie c35ac70
Store meshEdits in group 'meshEdits'
rchristie b65c7f9
Deprecate MeshType functions for Scaffold
rchristie cc07ebe
Remove @author and date tags
rchristie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.zinc_utils import * | ||
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 = 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make same changes to meshtype_3d_boxhole1.py, meshtyple_3d_sphereshellseptum1.py, meshtype_3d_stomachhuman1.py, meshtype_3d_tube1.py, meshtype_3d_tubeseptum1.py