Commit 8dede236 authored by John Tourtellott's avatar John Tourtellott

Revise phase to be single attribute type with "fluid" option

* Previously had phase-fluid and phase-solid types
* Code now sets material-system name based on material number(s)
* Code also reports circular transitions as RuntimeError
parent 60c64bd5
......@@ -319,8 +319,13 @@ format_table = {
card('density-deviation', item_path='density-deviation', as_property=True),
card('specific heat', item_path='specific-heat', as_property=True),
card('conductivity', item_path='conductivity', as_property=True),
card('electrical conductivity', item_path='electrical-properties/electrical-conductivity', as_property=True),
card('viscosity', item_path='viscosity', as_property=True)
card('viscosity', item_path='viscosity', if_condition=FLUID_PHASE, as_property=True),
card('electrical conductivity', item_path='electrical-properties/electrical-conductivity',
if_condition=INDUCTION_HEATING,as_property=True),
card('electrical susceptibility', item_path='electrical-properties/electrical-susceptibility',
if_condition=INDUCTION_HEATING,as_property=True),
card('magnetic susceptibility', item_path='electrical-properties/magnetic-susceptibility',
if_condition=INDUCTION_HEATING,as_property=True)
],
'PHYSICAL_CONSTANTS': [
card('absolute_zero', item_path='absolute-zero'),
......
......@@ -22,7 +22,7 @@
</Component>
</ItemDefinitions>
</AttDef>
<AttDef Type="phase" Abstract="true" BaseType="" Version="0" Unique="true">
<AttDef Type="phase" BaseType="" Label="Phase" Version="0" Unique="true">
<AssociationsDef Name="MaterialAssociations" Version="0" NumberOfRequiredValues="0" Extensible="true">
<MembershipMask>volume</MembershipMask>
</AssociationsDef>
......@@ -77,6 +77,24 @@ density from the reference density</BriefDescription>
<Min Inclusive="false">0.0</Min>
</RangeInfo>
</Double>
<Group Name="fluid" Label="Fluid" Optional="true" IsEnabledByDefault="false">
<ItemDefinitions>
<Double Name="viscosity" Label="Viscosity (nu)">
<BriefDescription>The dynamic viscosity of a fluid phase</BriefDescription>
<Categories>
<Cat>Fluid Flow</Cat>
<Cat>Heat Transfer</Cat>
<Cat>Induction Heating</Cat>
<Cat>Solid Mechanics</Cat>
</Categories>
<DefaultValue>0.0</DefaultValue>
<ExpressionType>fn.material.viscosity</ExpressionType>
<RangeInfo>
<Min Inclusive="false">0.0</Min>
</RangeInfo>
</Double>
</ItemDefinitions>
</Group>
<!-- Electromagnetic properties-->
<Group Name="electrical-properties" Label="Electrical Properties">
<ItemDefinitions>
......@@ -102,31 +120,9 @@ density from the reference density</BriefDescription>
</Group>
</ItemDefinitions>
</AttDef>
<AttDef Type="phase-solid" BaseType="phase" Label="Solid"/>
<AttDef Type="phase-fluid" BaseType="phase" Label="Fluid">
<ItemDefinitions>
<Double Name="viscosity" Label="Viscosity (nu)">
<BriefDescription>The dynamic viscosity of a fluid phase</BriefDescription>
<Categories>
<Cat>Fluid Flow</Cat>
<Cat>Heat Transfer</Cat>
<Cat>Induction Heating</Cat>
<Cat>Solid Mechanics</Cat>
</Categories>
<DefaultValue>0.0</DefaultValue>
<ExpressionType>fn.material.viscosity</ExpressionType>
<RangeInfo>
<Min Inclusive="false">0.0</Min>
</RangeInfo>
</Double>
</ItemDefinitions>
</AttDef>
<AttDef Type="phase-transition" BaseType="" Label="Transition" Version="0">
<AssociationsDef Name="MaterialAssociations" Version="0" NumberOfRequiredValues="0" Extensible="true">
<MembershipMask>volume</MembershipMask>
</AssociationsDef>
<AttDef Type="phase-transition" BaseType="" Label="Phase Transition" Version="0">
<ItemDefinitions>
<Component Name="lower" Label="Lower Phase" NumberOfRequiredValues="1">
<Component Name="lower" Label="Low-Temperature phase" NumberOfRequiredValues="1">
<Accepts>
<Resource Name="smtk::attribute::Resource" Filter="attribute[type='phase']"/>
</Accepts>
......@@ -148,7 +144,7 @@ density from the reference density</BriefDescription>
<Min Inclusive="false">0.0</Min>
</RangeInfo>
</Double>
<Double Name="lower-transition-temperature" Label="Lower Transition Temperature (Ts)">
<Double Name="lower-transition-temperature" Label="Low Transition Temperature (Ts)">
<Categories>
<Cat>Fluid Flow</Cat>
<Cat>Heat Transfer</Cat>
......@@ -157,7 +153,7 @@ density from the reference density</BriefDescription>
</Categories>
<DefaultValue>0.0</DefaultValue>
</Double>
<Double Name="upper-transition-temperature" Label="Upper Transition Temperature (Tl)">
<Double Name="upper-transition-temperature" Label="High Transition Temperature (Tl)">
<Categories>
<Cat>Fluid Flow</Cat>
<Cat>Heat Transfer</Cat>
......@@ -166,7 +162,7 @@ density from the reference density</BriefDescription>
</Categories>
<DefaultValue>100.0</DefaultValue>
</Double>
<Component Name="upper" Label="Upper Phase" NumberOfRequiredValues="1">
<Component Name="upper" Label="High-Temperature Phase" NumberOfRequiredValues="1">
<Categories>
<Cat>Fluid Flow</Cat>
<Cat>Heat Transfer</Cat>
......
......@@ -38,7 +38,7 @@ SMTK_AttributeResource(Version="3")
Resource(Name="smtk::attribute::Resource" Filter="attribute[type='phase']")
+categories-all
AttDef(Type="phase" Abstract="true" BaseType="" Version="0" Unique="true")
AttDef(Type="phase" BaseType="" Label="Phase" Version="0" Unique="true")
AssociationsDef(Name="MaterialAssociations" Version="0"
NumberOfRequiredValues="0" Extensible="true")
MembershipMask volume
......@@ -69,27 +69,23 @@ SMTK_AttributeResource(Version="3")
RangeInfo
Min(Inclusive="false") 0.0
Group(Name="fluid" Label="Fluid" Optional="true" IsEnabledByDefault="false")
ItemDefinitions
Double(Name="viscosity" Label="Viscosity (nu)")
BriefDescription
| The dynamic viscosity of a fluid phase
+categories-all
DefaultValue 0.0
ExpressionType fn.material.viscosity
RangeInfo
Min(Inclusive="false") 0.0
// Electromagnetic properties
+electrical
AttDef(Type="phase-solid" BaseType="phase" Label="Solid")
AttDef(Type="phase-fluid" BaseType="phase" Label="Fluid")
ItemDefinitions
Double(Name="viscosity" Label="Viscosity (nu)")
BriefDescription
| The dynamic viscosity of a fluid phase
+categories-all
DefaultValue 0.0
ExpressionType fn.material.viscosity
RangeInfo
Min(Inclusive="false") 0.0
AttDef(Type="phase-transition" BaseType="" Label="Transition" Version="0")
AssociationsDef(Name="MaterialAssociations" Version="0"
NumberOfRequiredValues="0" Extensible="true")
MembershipMask volume
AttDef(Type="phase-transition" BaseType="" Label="Phase Transition" Version="0")
ItemDefinitions
Component(Name="lower" Label="Lower Phase" NumberOfRequiredValues="1")
Component(Name="lower" Label="Low-Temperature phase" NumberOfRequiredValues="1")
Accepts
Resource(Name="smtk::attribute::Resource" Filter="attribute[type='phase']")
+categories-all
......@@ -97,13 +93,13 @@ SMTK_AttributeResource(Version="3")
+categories-all
RangeInfo
Min(Inclusive="false") 0.0
Double(Name="lower-transition-temperature" Label="Lower Transition Temperature (Ts)")
Double(Name="lower-transition-temperature" Label="Low Transition Temperature (Ts)")
+categories-all
DefaultValue 0.0
Double(Name="upper-transition-temperature" Label="Upper Transition Temperature (Tl)")
Double(Name="upper-transition-temperature" Label="High Transition Temperature (Tl)")
+categories-all
DefaultValue 100.0
Component(Name="upper" Label="Upper Phase" NumberOfRequiredValues="1")
Component(Name="upper" Label="High-Temperature Phase" NumberOfRequiredValues="1")
+categories-all
Accepts
Resource(Name="smtk::attribute::Resource" Filter="attribute[type='phase']")
......
......@@ -721,7 +721,7 @@ class Writer:
# multiple python objects for same c++ object
def check_phase(phase_id, transition_dict, label):
"""Checks that phase not already used on transition dictionary"""
"""Checks that phase not already used in transition dictionary"""
if phase_id in transition_dict:
phase_att = self.sim_atts.findAttribute(phase_id)
tpl = 'ERROR: Phase attribute \"{}\" twice used as {} part of phase transitions'
......@@ -734,7 +734,8 @@ class Writer:
trans_atts = self.sim_atts.findAttributes('phase-transition')
for trans_att in trans_atts:
if not trans_att.isValid():
msg = 'ERROR: invalid Phase Transition attribute \"{}\"'.format(att.name())
tpl = 'ERROR: invalid Phase Transition attribute \"{}\"'
msg = tpl.format(trans_att.name())
print(msg)
raise RuntimeError(msg)
......@@ -782,19 +783,23 @@ class Writer:
# print('material_list: {}'.format(material_list))
# Traverse material list
# Also keep track of transitions, to make sure *all* get used
trans_id_list = [t.id() for t in trans_atts]
trans_id_set = set(trans_id_list)
for att in material_list:
if att.type() in ['phase-fluid', 'phase-solid']:
if att.type() == 'phase':
# Write single phase material
self._write_phase_namelist(att)
self._write_material_namelist(att)
self._write_material_system_namelist(att)
elif att.type() == 'phase-transition':
trans_att = att
# Write multiple phase material
# Write multiple phase material, starting with lowest-temp phase
lower_att = trans_att.findComponent('lower').value()
self._write_phase_namelist(lower_att)
self._write_material_namelist(lower_att)
while trans_att is not None:
trans_id_set.discard(trans_att.id())
upper_att = trans_att.findComponent('upper').value()
self._write_phase_namelist(upper_att)
self._write_material_namelist(upper_att)
......@@ -805,6 +810,14 @@ class Writer:
else:
raise RuntimeError('ERROR - unexpected attribute type ', att.type())
# Any transaction atts not removed above indicate error(s)
if trans_id_set:
unused_atts = [self.sim_atts.findAttribute(id) for id in trans_id_set]
unused_att_names = [att.name() for att in unused_atts]
tpl = 'ERROR - inconsistent transitions, probably circular: {}'
msg = tpl.format(unused_att_names)
raise RuntimeError(msg)
# --------------------------------------------------------------------
def _write_material_namelist(self, phase_att):
......@@ -823,16 +836,26 @@ class Writer:
CardFormat.write_value(self.out, 'material_name', phase_att.name())
CardFormat.write_value(self.out, 'material_number', number)
immobile = (phase_att.type() == "phase-solid")
fluid_item = phase_att.findGroup('fluid')
immobile = not fluid_item.isEnabled()
CardFormat.write_value(self.out, 'immobile', immobile, as_boolean=True)
if fluid_item.isEnabled():
CardFormat.Conditions.add(FLUID_PHASE)
for card in format_list:
card.write(self.out, phase_att)
CardFormat.Conditions.discard(FLUID_PHASE)
# Hard-code material density
# Todo set to zero for void materials
CardFormat.write_value(self.out, 'density', 1.0)
# Check if this material is the background material
if phase_att.id() == self.background_material_id:
CardFormat.write_value(self.out, 'material_feature','background')
CardFormat.write_value(self.out, 'density', 1.0)
self._finish_namelist()
......@@ -864,11 +887,11 @@ class Writer:
self._start_namelist(title)
# Simple case - att is single "phase" attribute
if att.type() in ['phase-fluid', 'phase-solid']:
raw_name = att.name()
name = raw_name[:31] # max length
if att.type() == 'phase':
number = self.material_number_dict.get(att.id())
name = 'material {}'.format(number)
CardFormat.write_value(self.out, 'name', name, tab=6)
CardFormat.write_value(self.out, 'phases', name, tab=6)
CardFormat.write_value(self.out, 'phases', att.name(), tab=6)
self._finish_namelist()
return
......@@ -881,15 +904,20 @@ class Writer:
lower_temps = list()
upper_temps = list()
latent_heats = list()
numbers = list()
trans_att = att
lower_att = trans_att.findComponent('lower').value()
lower_name = lower_att.name()
number = self.material_number_dict.get(lower_att.id())
numbers.append(number)
phase_list.append('\"{}\"'.format(lower_name[:31]))
while trans_att is not None:
upper_att = trans_att.findComponent('upper').value()
upper_name = upper_att.name()
phase_list.append('\"{}\"'.format(upper_name[:31]))
number = self.material_number_dict.get(upper_att.id())
numbers.append(number)
lower_temp_item = trans_att.findDouble('lower-transition-temperature')
lower_temps.append(lower_temp_item.value())
......@@ -915,7 +943,10 @@ class Writer:
raise RuntimeError(msg)
prev_temp = temp
CardFormat.write_value(self.out, 'name', lower_name[:31])
numbers.sort()
number_string = '+'.join([str(n) for n in numbers])
name = 'material {}'.format(number_string)
CardFormat.write_value(self.out, 'name', name)
CardFormat.write_value(self.out, 'phases', phase_list)
CardFormat.write_value(self.out, 'transition_temps_low', lower_temps)
CardFormat.write_value(self.out, 'transition_temps_high', upper_temps)
......
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