Commit 46078015 authored by John Tourtellott's avatar John Tourtellott

Write out functions, plus other minor updates

parent 6679e7ae
......@@ -3,5 +3,8 @@
*.pyo
__pycache__/
# IDE config files
.vscode/
# Exclude OS X .DS_Store files.
.DS_Store
......@@ -236,10 +236,10 @@ format_table = {
# card('face_block_ids', use_model_entities_for_value=True),
# card('emissivity', item_path='emissivity')
# ],
# 'FUNCTION': [
# card('name', use_name_for_value=True),
# card('type', literal_value='tabular')
# ],
'FUNCTION': [
card('name', use_name_for_value=True),
card('type', item_path='type')
],
'INDUCTION_COIL': [
card('nturns', item_path='type/nturns'),
card('center', item_path='type/center'),
......@@ -337,6 +337,7 @@ format_table = {
'PHYSICS': [
card('fluid_flow', use_condition_for_boolean=FLOW_ANALYSIS),
card('heat_transport', use_condition_for_boolean=THERMAL_ANALYSIS),
card('electromagnetics', use_condition_for_boolean=INDUCTION_HEATING),
card('body_force', att_type='physics', item_path='fluid-body-force',
if_condition=FLOW_ANALYSIS)
# card('inviscid', if_condition=FLOW_ANALYSIS,
......@@ -375,6 +376,7 @@ namelist_sequence = [
namelist('PHYSICS', custom_method='_write_physics'),
# Note: internally, the materials writer includes PHASE and MATERIAL_SYSTEM
namelist('MATERIAL', custom_method='_write_materials', separator='MATERIALS'),
namelist('FUNCTION', att_type='fn.material', custom_method='_write_function'),
namelist('DIFFUSION_SOLVER',
if_condition=ONLY_THERMAL_ANALYSIS,
att_type='ht.solver',
......@@ -412,6 +414,7 @@ namelist_sequence = [
namelist('BC',
att_type='boundary-condition', custom_method='_write_bc'),
namelist('BODY', att_type='material', custom_method='_write_body', separator='BODIES'),
namelist('FUNCTION', att_type='fn.initial-condition', custom_method='_write_function'),
namelist('DS_SOURCE', att_type='ht.source'),
namelist('PROBE', att_type='probe'),
namelist(
......
......@@ -55,12 +55,12 @@
</Double>
<Group Name="polynomial-terms" Label="Polynomial Terms" Extensible="true" NumberOfRequiredGroups="1">
<ItemDefinitions>
<Double Name="Coefficient" NumberOfRequiredValues="1">
<Double Name="X" Label="Coefficient" NumberOfRequiredValues="1">
<Categories>
<Cat>Heat Transfer</Cat>
</Categories>
</Double>
<Int Name="Exponent (Temp)" NumberOfRequiredValues="1">
<Int Name="Value" Label="Exponent (Temp)" NumberOfRequiredValues="1">
<Categories>
<Cat>Heat Transfer</Cat>
</Categories>
......@@ -70,14 +70,14 @@
</ChildrenDefinitions>
<DiscreteInfo>
<Structure>
<Value Enum="Polynomial"></Value>
<Value Enum="Polynomial">polynomial</Value>
<Items>
<Item>center</Item>
<Item>polynomial-terms</Item>
</Items>
</Structure>
<Structure>
<Value Enum="Tabular"></Value>
<Value Enum="Tabular">tabular</Value>
<Items>
<Item>interpolation</Item>
<Item>extrapolation</Item>
......@@ -136,12 +136,12 @@
</Double>
<Group Name="polynomial-terms" Label="Polynomial Terms" Extensible="true" NumberOfRequiredGroups="1">
<ItemDefinitions>
<Double Name="Coefficient" NumberOfRequiredValues="1">
<Double Name="X" Label="Coefficient" NumberOfRequiredValues="1">
<Categories>
<Cat>Heat Transfer</Cat>
</Categories>
</Double>
<Int Name="Exponent (Temp)" NumberOfRequiredValues="1">
<Int Name="Value" Label="Exponent (Temp)" NumberOfRequiredValues="1">
<Categories>
<Cat>Heat Transfer</Cat>
</Categories>
......@@ -151,14 +151,14 @@
</ChildrenDefinitions>
<DiscreteInfo>
<Structure>
<Value Enum="Polynomial"></Value>
<Value Enum="Polynomial">polynomial</Value>
<Items>
<Item>center</Item>
<Item>polynomial-terms</Item>
</Items>
</Structure>
<Structure>
<Value Enum="Tabular"></Value>
<Value Enum="Tabular">tabular</Value>
<Items>
<Item>interpolation</Item>
<Item>extrapolation</Item>
......@@ -251,14 +251,14 @@
</ChildrenDefinitions>
<DiscreteInfo>
<Structure>
<Value Enum="Polynomial"></Value>
<Value Enum="Polynomial">polynomial</Value>
<Items>
<Item>center</Item>
<Item>polynomial-terms</Item>
</Items>
</Structure>
<Structure>
<Value Enum="Tabular"></Value>
<Value Enum="Tabular">tabular</Value>
<Items>
<Item>interpolation</Item>
<Item>extrapolation</Item>
......
......@@ -168,19 +168,19 @@
</ChildrenDefinitions>
<DiscreteInfo DefaultIndex="0">
<Structure>
<Value Enum="Single Turn">single</Value>
<Value Enum="Multiple Turn">multiple</Value>
<Items>
<Item>nturns</Item>
<Item>center</Item>
<Item>radius</Item>
<Item>length</Item>
</Items>
</Structure>
<Structure>
<Value Enum="Multiple Turn">multiple</Value>
<Value Enum="Single Turn">single</Value>
<Items>
<Item>nturns</Item>
<Item>center</Item>
<Item>radius</Item>
<Item>length</Item>
</Items>
</Structure>
</DiscreteInfo>
......
......@@ -141,7 +141,7 @@ temperature error norm used by the BDF2 integrator</BriefDescription>
<Max Inclusive="true">1.0</Max>
</RangeInfo>
</Double>
<Void Name="verbose-stepping" Label="Verbose stepping" Optional="true" IsEnabledByDefault="false">
<Void Name="verbose-stepping" Label="Verbose stepping" Optional="true" IsEnabledByDefault="true">
<BriefDescription>Enables the output of detailed BDF2 time stepping information</BriefDescription>
<Categories>
<Cat>Heat Transfer</Cat>
......
......@@ -16,12 +16,12 @@ mixin fnDiscreteInfo
//- DiscreteInfo section common to all functions
DiscreteInfo
Structure
Value(Enum="Polynomial")
Value(Enum="Polynomial") polynomial
Items
Item center
Item polynomial-terms
Structure
Value(Enum="Tabular")
Value(Enum="Tabular") tabular
Items
Item interpolation
Item extrapolation
......@@ -50,9 +50,9 @@ mixin fn1(category, tabLabels, polyLabels)
DefaultValue 0
Group(Name="polynomial-terms" Label=polyLabels[1] Extensible="true" NumberOfRequiredGroups="1")
ItemDefinitions
Double(Name=polyLabels[2] NumberOfRequiredValues="1")
Double(Name="X" Label=polyLabels[2] NumberOfRequiredValues="1")
Categories #[Cat= category]
Int(Name=polyLabels[3] NumberOfRequiredValues="1")
Int(Name="Value" Label=polyLabels[3] NumberOfRequiredValues="1")
Categories #[Cat= category]
+fnDiscreteInfo
......
......@@ -127,17 +127,17 @@ SMTK_AttributeResource(Version="3")
DiscreteInfo(DefaultIndex="0")
Structure
Value(Enum="Single Turn") single
Value(Enum="Multiple Turn") multiple
Items
Item nturns
Item center
Item radius
Item length
Structure
Value(Enum="Multiple Turn") multiple
Value(Enum="Single Turn") single
Items
Item nturns
Item center
Item radius
Item length
//- Todo handle time-dependent current
Double(Name="current" Label="Current" NumberOfRequiredValues="1" Version="0")
......
......@@ -106,7 +106,7 @@ SMTK_AttributeResource(Version="3")
Min(Inclusive="true") 0.0
Max(Inclusive="true") 1.0
Void(Name="verbose-stepping" Label="Verbose stepping"
Optional="true" IsEnabledByDefault="false")
Optional="true" IsEnabledByDefault="true")
BriefDescription Enables the output of detailed BDF2 time stepping information
Categories #[Cat Heat Transfer]
Int(Name="max-nlk-itr" Label="Max NLK iterations" AdvanceLevel="1")
......
......@@ -360,6 +360,10 @@ class CardFormat:
'''Writes value to output stream
'''
if isinstance(value, list):
value = ', '.join(map(str, value))
quote_string = False
# Use str.format() method to set first column width
if len(keyword) > tab:
tab = len(keyword)
......
......@@ -671,22 +671,51 @@ class Writer:
att_list.sort(key=lambda att: att.name())
for att in att_list:
self.out.write('\n&%s\n' % namelist.title)
#CardFormat.write_value(self.out, 'name', att.name())
for card in format_list:
card.write(self.out, att)
# Write out the data
CardFormat.write_value(self.out, 'table', '', quote_string=False)
x_item = att.itemAtPath('ValuePairs/X', '/')
y_item = att.itemAtPath('ValuePairs/Value', '/')
num_rows = x_item.numberOfValues()
last_row = num_rows - 1
for i in range(num_rows):
x = x_item.value(i)
y = y_item.value(i)
self.out.write(' %s, %s' % (x, y))
if i < last_row:
self.out.write(',')
self.out.write('\n')
# Write type-specific function data
type_item = att.findString('type')
function_type = type_item.value(0)
if function_type == 'polynomial':
group_item = att.itemAtPath('type/polynomial-terms')
coef_table = dict() # <exponent, coefficient>
for i in range(group_item.numberOfGroups()):
x = group_item.item(i, 0).value()
y = group_item.item(i, 1).value()
coef_table[y] = x
# Get max coefficient
ytop = max(coef_table.keys()) + 1
exp_list = range(ytop)
coef_list = [0] * ytop
for i in exp_list:
coef_list[i] = coef_table.get(i, 0)
CardFormat.write_value(self.out, 'poly_coefficients', coef_list)
CardFormat.write_value(self.out, 'poly_exponents(1,:)', exp_list)
# Finish with the center value
CardFormat('poly_refvars', item_path='type/center').write(self.out, att)
elif function_type == 'tabular':
CardFormat.write_value(self.out, 'tabular_dim', 1)
group_item = att.itemAtPath('type/tabular-data')
num_terms = group_item.numberOfGroups()
xvals = [0.0] * num_terms
yvals = [0.0] * num_terms
for i in range(num_terms):
xvals[i] = group_item.item(i, 0).value()
yvals[i] = group_item.item(i, 1).value()
CardFormat.write_value(self.out, 'tabular_data(1,:)', xvals)
CardFormat.write_value(self.out, 'tabular_data(2,:)', yvals)
# Finish with interpolation & extrapolation
CardFormat('tabular_interp', item_path='type/interpolation').write(self.out, att)
CardFormat('tabular_extrap', item_path='type/extrapolation').write(self.out, att)
self.out.write('/\n')
# ---------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment