Skip to content

Commit

Permalink
Update gismo export and add a flag to export in CPS-format for OW
Browse files Browse the repository at this point in the history
  • Loading branch information
jzwar committed Jul 12, 2023
1 parent f8ed544 commit de58dbf
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions splinepy/io/gismo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from splinepy.utils.log import debug, warning


def _spline_to_ET(root, multipatch, index_offset, fields_only=False):
def _spline_to_ET(root, multipatch, index_offset, fields_only=False, cps_keys=False):
"""
Write spline data to xml element in gismo format
Expand All @@ -24,6 +24,9 @@ def _spline_to_ET(root, multipatch, index_offset, fields_only=False):
xml file)
fields_only : bool (False)
If set, exports only the fields associated to the multipatch data
cps_keys : bool
Uses gismo key words from version utilized at Cyber-Physical Simulation
institute
Returns
-------
Expand All @@ -34,6 +37,13 @@ def _spline_to_ET(root, multipatch, index_offset, fields_only=False):

if fields_only and (len(multipatch.fields) == 0):
return

def wrap_type_keys(key, paradim):
if cps_keys:
return key
else:
return "Tensor" + key + str(paradim)


if fields_only:
supports = np.array(
Expand Down Expand Up @@ -74,13 +84,13 @@ def _spline_to_ET(root, multipatch, index_offset, fields_only=False):
coefs = np.hstack(
[multipatch.fields[j][id].control_points for j in support]
)
if "weights" in spline.required_properties:
if spline.is_rational:
weights = np.hstack(
[multipatch.fields[j][id].weights for j in support]
)
else:
coefs = spline.control_points
if "weights" in spline.required_properties:
if spline.is_rational:
weights = spline.weights

if not issubclass(type(spline), Spline):
Expand All @@ -92,20 +102,11 @@ def _spline_to_ET(root, multipatch, index_offset, fields_only=False):
# Transform bezier types, as they are not supported in gismo
if spline.name.startswith("Bezier"):
type_name = "BSpline"
spline = BSpline(
**spline.todict(),
knot_vectors=[
[0] * (a + 1) + [1] * (a + 1) for a in spline.degrees
],
)
spline = spline.bspline
elif spline.name.startswith("RationalBezier"):
type_name = "Nurbs"
spline = NURBS(
**spline.todict(),
knot_vectors=[
[0] * (a + 1) + [1] * (a + 1) for a in spline.degrees
],
)
spline = spline.nurbs

elif spline.name.startswith("BSpline"):
type_name = "BSpline"
elif spline.name.startswith("NURBS"):
Expand All @@ -115,7 +116,7 @@ def _spline_to_ET(root, multipatch, index_offset, fields_only=False):
spline_element = ET.SubElement(
root,
"Geometry",
type="Tensor" + type_name + str(spline.para_dim),
type=wrap_type_keys(type_name, spline.para_dim),
id=str(id + index_offset),
)

Expand All @@ -124,18 +125,18 @@ def _spline_to_ET(root, multipatch, index_offset, fields_only=False):
spline_basis_base = ET.SubElement(
spline_element,
"Basis",
type="Tensor" + type_name + "Basis" + str(spline.para_dim),
type=wrap_type_keys(type_name + "Basis", spline.para_dim),
)
spline_basis = ET.SubElement(
spline_basis_base,
"Basis",
type="TensorBSplineBasis" + str(spline.para_dim),
type=wrap_type_keys("BSplineBasis", spline.para_dim),
)
else:
spline_basis = ET.SubElement(
spline_element,
"Basis",
type="Tensor" + type_name + "Basis" + str(spline.para_dim),
type=wrap_type_keys(type_name + "Basis", spline.para_dim),
)

for i_para in range(spline.para_dim):
Expand Down Expand Up @@ -174,6 +175,7 @@ def export(
labeled_boundaries=True,
options=None,
export_fields=False,
cps_keys=False,
):
"""Export as gismo readable xml geometry file
Use gismo-specific xml-keywords to export (list of) splines. All Bezier
Expand Down Expand Up @@ -201,6 +203,9 @@ def export(
collapse_fields : cool
Only valid if export_fields is True, writes all fields in the same file
by collapsing the control points, requires conformity (not checked)
cps_keys : bool
Uses gismo key words from version utilized at Cyber-Physical Simulation
institute
Returns
-------
Expand Down Expand Up @@ -382,7 +387,7 @@ def export(
# Export fields first, as all necessary information is already available
if export_fields:
field_xml = copy.deepcopy(xml_data)
_spline_to_ET(field_xml, multipatch, index_offset, fields_only=True)
_spline_to_ET(field_xml, multipatch, index_offset, fields_only=True, cps_keys=cps_keys)
if int(python_version.split(".")[1]) >= 9 and indent:
ET.indent(field_xml)
file_content = ET.tostring(field_xml)
Expand Down

0 comments on commit de58dbf

Please sign in to comment.