def __init__(self, filename): self.element_types = {} self.states = {} self.uflinput = {} optionfile = OptionFile(filename) # Build dictionary of element types for meshes self.element_types = {} # Get shape and degree for each mesh for mesh in optionfile.meshes(): self.element_types[mesh.name] = mesh.shape, mesh.degree # Build dictionary of material phases aliased_fields = [] for phase in optionfile.material_phases(): # Build state (dictionary of fields) state = UflState() # Add vector field 'Coordinate' on 'CoordinateMesh', # which is always present shape, degree = self.element_types['CoordinateMesh'] state.insert_field('Coordinate', 1, shape, degree) for field in optionfile.fields(phase.path): # For an aliased field, store material phase and field it is # aliased to, come back later to assign element of the target # field if field.field_type == 'aliased': field.phase = phase.name aliased_fields.append(field) else: shape, degree = self.element_types[field.mesh] # Insert the field in the state # FIXME currently we simply pass the quadrature degree as the # quadrature_shape parameter when creating a UFL element # is that a clean / safe way? state.insert_field(field.name, field.rank, shape, degree, optionfile.quadrature_degree()) # Store the UFL input if present if hasattr(field, 'ufl_equation'): self.uflinput[phase.name+field.name] \ = (phase.name, field.name, field.ufl_equation) self.states[phase.name] = state # Resolve aliased fields for alias in aliased_fields: self.states[alias.phase][alias.rank][alias.name] \ = self.states[alias.to_phase][alias.rank][alias.to_field] # Build list of UFL equations with associated state for key in self.uflinput: ufl = self.uflinput[key][2] phase = self.uflinput[key][0] self.uflinput[key] = ufl, self.states[phase]
def parse(self, filename): # read ufl input file with open(filename, 'r') as fd: ufl_input = fd.read() phase = "" # Build a fake state dict state = UflState() state.insert_field('Coordinate',1) state.insert_field('Tracer',0) state.insert_field('Height',0) state.insert_field('Velocity',1) state.insert_field('NewVelocity',1) state.insert_field('TracerDiffusivity',2) # Build a fake states dict states = {phase: state} return [FluidityEquation("model", ufl_input, state, states)]