Skip to content

Commit

Permalink
corrected small error for calculation of refinement functions; update…
Browse files Browse the repository at this point in the history
…d documentation
  • Loading branch information
PhilippMetsch committed Oct 21, 2020
1 parent c3119a9 commit cf3eb6a
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docs/examples/bodyCenteredCubicCell2DCircle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Code
"interInclusionRefinement": True, # flag to indicate active refinement of space between inclusions (inter-inclusion refinement)
"elementsPerCircumference": 18, # use 18 elements per inclusion circumference for inclusion refinement
"elementsBetweenInclusions": 3, # ensure 3 elements between close inclusions for inter-inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 1 for inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 3 for inclusion refinement
"transitionElements": "auto", # automatically calculate number of transitioning elements (elements in which tanh function jumps from h_min to h_max) for inter-inclusion refinement
"aspectRatio": 1.5 # aspect ratio for inter-inclusion refinement: ratio of refinement in inclusion distance and perpendicular directions
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/faceCenteredCubicCell3DCylinder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ Code
"interInclusionRefinement": True, # flag to indicate active refinement of space between inclusions (inter-inclusion refinement)
"elementsPerCircumference": 18, # use 18 elements per inclusion circumference for inclusion refinement
"elementsBetweenInclusions": 3, # ensure 3 elements between close inclusions for inter-inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 1 for inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 3 for inclusion refinement
"transitionElements": "auto", # automatically calculate number of transitioning elements (elements in which tanh function jumps from h_min to h_max) for inter-inclusion refinement
"aspectRatio": 1.5 # aspect ratio for inter-inclusion refinement: ratio of refinement in inclusion distance and perpendicular directions
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/helicalChain2DCircle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Code
"interInclusionRefinement": True, # flag to indicate active refinement of space between inclusions (inter-inclusion refinement)
"elementsPerCircumference": 18, # use 18 elements per inclusion circumference for inclusion refinement
"elementsBetweenInclusions": 3, # ensure 3 elements between close inclusions for inter-inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 1 for inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 3 for inclusion refinement
"transitionElements": "auto", # automatically calculate number of transitioning elements (elements in which tanh function jumps from h_min to h_max) for inter-inclusion refinement
"aspectRatio": 1.5 # aspect ratio for inter-inclusion refinement: ratio of refinement in inclusion distance and perpendicular directions
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/helicalChain3DSphere.rst
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Code
"interInclusionRefinement": True, # flag to indicate active refinement of space between inclusions (inter-inclusion refinement)
"elementsPerCircumference": 18, # use 18 elements per inclusion circumference for inclusion refinement
"elementsBetweenInclusions": 3, # ensure 3 elements between close inclusions for inter-inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 1 for inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 3 for inclusion refinement
"transitionElements": "auto", # automatically calculate number of transitioning elements (elements in which tanh function jumps from h_min to h_max) for inter-inclusion refinement
"aspectRatio": 1.5 # aspect ratio for inter-inclusion refinement: ratio of refinement in inclusion distance and perpendicular directions
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/hexagonalCell3DSphere.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Code
"interInclusionRefinement": True, # flag to indicate active refinement of space between inclusions (inter-inclusion refinement)
"elementsPerCircumference": 18, # use 18 elements per inclusion circumference for inclusion refinement
"elementsBetweenInclusions": 3, # ensure 3 elements between close inclusions for inter-inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 1 for inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 3 for inclusion refinement
"transitionElements": "auto", # automatically calculate number of transitioning elements (elements in which tanh function jumps from h_min to h_max) for inter-inclusion refinement
"aspectRatio": 1.5 # aspect ratio for inter-inclusion refinement: ratio of refinement in inclusion distance and perpendicular directions
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/randomInclusions2DCircle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Code
"interInclusionRefinement": True, # flag to indicate active refinement of space between inclusions (inter-inclusion refinement)
"elementsPerCircumference": 18, # use 18 elements per inclusion circumference for inclusion refinement
"elementsBetweenInclusions": 3, # ensure 3 elements between close inclusions for inter-inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 1 for inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 3 for inclusion refinement
"transitionElements": "auto", # automatically calculate number of transitioning elements (elements in which tanh function jumps from h_min to h_max) for inter-inclusion refinement
"aspectRatio": 1.5 # aspect ratio for inter-inclusion refinement: ratio of refinement in inclusion distance and perpendicular directions
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/randomInclusions3DCylinder.rst
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Code
"interInclusionRefinement": True, # flag to indicate active refinement of space between inclusions (inter-inclusion refinement)
"elementsPerCircumference": 18, # use 18 elements per inclusion circumference for inclusion refinement
"elementsBetweenInclusions": 3, # ensure 3 elements between close inclusions for inter-inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 1 for inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 3 for inclusion refinement
"transitionElements": "auto", # automatically calculate number of transitioning elements (elements in which tanh function jumps from h_min to h_max) for inter-inclusion refinement
"aspectRatio": 1.5 # aspect ratio for inter-inclusion refinement: ratio of refinement in inclusion distance and perpendicular directions
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/randomInclusions3DSphere.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ Code
"interInclusionRefinement": True, # flag to indicate active refinement of space between inclusions (inter-inclusion refinement)
"elementsPerCircumference": 18, # use 18 elements per inclusion circumference for inclusion refinement
"elementsBetweenInclusions": 3, # ensure 3 elements between close inclusions for inter-inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 1 for inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 3 for inclusion refinement
"transitionElements": "auto", # automatically calculate number of transitioning elements (elements in which tanh function jumps from h_min to h_max) for inter-inclusion refinement
"aspectRatio": 1.5 # aspect ratio for inter-inclusion refinement: ratio of refinement in inclusion distance and perpendicular directions
}
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/simpleCubicCell3DSphere.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ Code
"interInclusionRefinement": True, # flag to indicate active refinement of space between inclusions (inter-inclusion refinement)
"elementsPerCircumference": 18, # use 18 elements per inclusion circumference for inclusion refinement
"elementsBetweenInclusions": 3, # ensure 3 elements between close inclusions for inter-inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 1 for inclusion refinement
"inclusionRefinementWidth": 3, # use a relative (to inclusion radius) refinement width of 3 for inclusion refinement
"transitionElements": "auto", # automatically calculate number of transitioning elements (elements in which tanh function jumps from h_min to h_max) for inter-inclusion refinement
"aspectRatio": 1.5 # aspect ratio for inter-inclusion refinement: ratio of refinement in inclusion distance and perpendicular directions
}
Expand Down
11 changes: 11 additions & 0 deletions docs/gmshModel/MeshExport/MeshExport.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MeshExport
==========
The MeshExport provides a simple mesh conversion for FEAP.


Class Definition
----------------

.. autoclass:: gmshModel.MeshExport.MeshExport
:show-inheritance:
:members:
13 changes: 13 additions & 0 deletions docs/gmshModel/MeshExport/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _api_meshExport_ref:

MeshExport
==========

This module provides additional methods for mesh export formats that cannot be
handled using meshio. At the moment, only a special export method for FEAP is
implemented - other export formats can be added here, if required.

.. toctree::
:maxdepth: 1

MeshExport
26 changes: 14 additions & 12 deletions docs/gmshModel/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,29 @@
API Reference
=============

The core functionality of GmshModel is the mesh generation for complex models
The core functionality of GmshModel is the mesh generation for complex models
using Gmsh and the Gmsh-Python-API. The creation of such complex models, often
requires methods for the geometry generation. To this end, basic geometric objects
and helper methods for, e.g., distance calculations are provided within the
``Geometry`` module of GmshModel: using boolean operations for
groups of basic geometric objects, complex models can be defined step by step.
requires methods for the geometry generation. To this end, basic geometric objects
and helper methods for, e.g., distance calculations are provided within the
``Geometry`` module of GmshModel: using boolean operations for
groups of basic geometric objects, complex models can be defined step by step.
An extension of the modules will help to broaden the range of available models.
After the geometry is defined, it has to be transferred into a Gmsh model: all

After the geometry is defined, it has to be transferred into a Gmsh model: all
geometric objects are translated to their Gmsh representations, boolean
operations are performed and physical groups are added to the model. Within
the Model module of ``Model``, predefined models can be found.
Since, so far, the focus of GmshModel was on mesh models for representative
volume elements with multiple, randomly placed inclusions, especially those models
are already defined in GmshModel. However, since the GenericModel defines all required
methods for the model generation, the basic tasks for the development of a new
model are the definitions of required geometric objects and their arrangement within
are already defined in GmshModel. However, since the GenericModel defines all required
methods for the model generation, the basic tasks for the development of a new
model are the definitions of required geometric objects and their arrangement within
the model, of boolean operations and physical groups to be performed/added in Gmsh
and of refinement information for an auomated mesh size computation.
and of refinement information for an auomated mesh size computation.

Finally, basic GUIs for the geometry and mesh visualization are defined within
the ``Visualization`` module.
the ``Visualization`` module while an extension of the mesh conversion capabilities
of meshio for simulations using FEAP is defined within the ``MeshExport`` module.


.. toctree::
Expand All @@ -33,3 +34,4 @@ the ``Visualization`` module.
Model/index
Geometry/index
Visualization/index
MeshExport/index
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ and its features: ::

$ python3 -m pip install gmshModel

For ``conda`` users, the installation command is straightforward, too:
For ``conda`` users, the installation command is straightforward, too: ::

$ conda install -c conda-forge gmshModel

Expand Down Expand Up @@ -97,6 +97,7 @@ and how you can use them to generate your own model:
* :ref:`api_geometry_ref` gives information on available geometric objects
* :ref:`api_model_ref` explains all available models
* :ref:`api_visualization_ref` gives information on the visualization capabilities of gmshModel
* :ref:`api_meshExport_ref` comments on additional mesh output formats (extending meshio)

.. toctree::
:hidden:
Expand Down
28 changes: 13 additions & 15 deletions gmshModel/MeshExport/MeshExport.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
import numpy as np
import math

def FeapExport(model):

# nodal transformation for connectivity needed for 2nd order tetrahedron
# -> swap last two entries
tet_2 = [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 9 , 8]

# prerequisites - abbreviations for easier access
model = model.gmshAPI
mesh = model.mesh
meshfile = 'drve'

# necessary information for writing feap mesh file
dim = model.getDimension()
print("Physical dimension:",dim)
meshfile = str(dim)+meshfile

# get information on nodes
nodeTags, nodalCoord, paramCoord = mesh.getNodes(dim,-1,includeBoundary=True)
nodeTags,indices = np.unique(nodeTags, return_index=True)
nNodes = max(nodeTags)
print("Number of nodes:",nNodes)

# sort nodes and coordinates before writing
nodalX = nodalCoord[0::3]
nodalY = nodalCoord[1::3]
nodalZ = nodalCoord[2::3]
nodalX = nodalX[indices]
nodalY = nodalY[indices]
nodalZ = nodalZ[indices]

nodalCoord = np.zeros(int(nNodes*3))
nodalCoord[0::3] = nodalX
nodalCoord[1::3] = nodalY
nodalCoord[2::3] = nodalZ

# get information on elements
elemTypes,elemTags,connectivity = mesh.getElements(dim,-1)
nElem = 0
Expand All @@ -48,11 +47,11 @@ def FeapExport(model):
maxNodesPerElem = int(currNodesPerElem)
print("Number of elements:", nElem)
print("Maximum number of nodes per element:",maxNodesPerElem)

# get information on materials
phyGroup = model.getPhysicalGroups(dim)
numberOfMat = len(phyGroup)

## build database where each element has a material
elem2mat = np.zeros((nElem,2),dtype=int)
startind = 0
Expand All @@ -65,19 +64,19 @@ def FeapExport(model):
elem2mat[startind:startind+len(currElemTags[0]),0] = currElemTags[0]
elem2mat[startind:startind+len(currElemTags[0]),1] = i+1
startind = startind+len(currElemTags[0])

# write problem type file PROB_XXX with general definitions
with open('PROB_'+meshfile,'wt') as outfile:
outfile.writelines(str(nNodes)+' '+str(nElem)+' '+str(numberOfMat)+' '+str(dim)+' '+str(dim)+' '+str(maxNodesPerElem)+'\n')
outfile.writelines('! nodes, elements, material sets, mesh dimension, maximum nodal DOF (default = dim), max nodes/element')

# write mesh file MESH_XXX with nodal coordinates and element connectivity for every element type
with open('MESH_'+meshfile,'wt') as outfile:
outfile.writelines('COORDinate\n')
for i in range(0,nNodes):
coordStr = np.array2string(nodalCoord[3*i:3*(i+1)],max_line_width=100000)
outfile.writelines(str(i+1)+' 0 '+coordStr[1:-1]+'\n')

totalElemCount = 0
for i in range(0,len(elemTypes)):
currNodesPerElem = int(len(connectivity[i])/len(elemTags[i]))
Expand All @@ -87,7 +86,7 @@ def FeapExport(model):
print('Elements of current type:',elemsOfType)
outfile.writelines('\n')
outfile.writelines('ELEMent NODEs='+str(currNodesPerElem)+'\n')

# due to limited input records in one line (=16), elements with more
# than 13 nodes have to be split into several rows
for j in range(0,elemsOfType):
Expand All @@ -103,7 +102,6 @@ def FeapExport(model):
outfile.writelines(connectStr13[1:-1]+'\n')
# writing entries 14 - x of connectivity in new lines
# automatic linebreak every 16th entry
for cLines in range(0,int(math.ceil(max(currNodesPerElem-13,0)/16))):
for cLines in range(0,int(np.ceil(max(currNodesPerElem-13,0)/16))):
connectStr14x = np.array2string(currConnectivity[13+cLines*16:min(13+(cLines+1)*16,currNodesPerElem)],max_line_width=100000)
outfile.writelines(' '+connectStr14x[1:-1]+'\n')

2 changes: 1 addition & 1 deletion gmshModel/Model/GenericModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def saveMesh(self,file=None):
os.makedirs(fileDir,exist_ok=True) # ensure that the file directory exists
if fileExt == ".msh": # file extension is ".msh"
gmsh.write(fileDir+"/"+fileName+fileExt) # -> save mesh using built-in gmsh.write method
elif fileExt == ".feap": # file extension is ".feap" -> write feap mesh files
elif fileExt == ".feap": # file extension is ".feap" -> write feap mesh files
FeapExport(self)
else: # file extension is different from ".msh"
if fileExt in SUPPORTED_MESH_FORMATS: # -> check if file extension is supported by meshio
Expand Down

0 comments on commit cf3eb6a

Please sign in to comment.