firedrake.fml package¶
Submodules¶
firedrake.fml.form_manipulation_language module¶
A language for manipulating forms using labels.
- class firedrake.fml.form_manipulation_language.Label(label, *, value=True, validator=None)[source]¶
Bases:
objectObject for tagging forms, allowing them to be manipulated.
- __call__(target, value=None)[source]¶
Apply the label to a form or term.
- Parameters:
target – The form, term or labelled form to be labelled.
value – The value to attach to this label. Defaults to None.
- Raises:
ValueError – If the \(target\) is not a ufl.BaseForm, Term or LabelledForm.
- Returns:
A Term is returned if the target is a Term, otherwise a LabelledForm is returned.
- Return type:
Union[Term, LabelledForm]
- default_value¶
- label¶
- remove(target)[source]¶
Remove a label from a term or labelled form.
This removes any Label with this
labelfromtarget. If called on an LabelledForm, it acts term-wise.- Parameters:
target – Term or labelled form to have this label removed from.
- Raises:
ValueError – If the \(target\) is not a Term or a LabelledForm.
- update_value(target, new)[source]¶
Update the label of a term or labelled form.
This updates the value of any Label with this
labelfromtarget. If called on an LabelledForm, it acts term-wise.- Parameters:
target – Term or labelled form to have this label updated.
new – The new value for this label to take. The type is subject to the label’s validator (if it has one).
- Raises:
ValueError – If the \(target\) is not a Term or a LabelledForm.
- validator¶
- value¶
- class firedrake.fml.form_manipulation_language.LabelledForm(*terms)[source]¶
Bases:
objectA form, broken down into terms that pair individual forms with labels.
The LabelledForm object holds a list of terms, which pair
ufl.Formobjects withLabels. The label_map routine allows the terms to be manipulated or selected based on particular filters.- property form¶
Provide the whole form from the labelled form.
- Raises:
TypeError – If the labelled form has no terms.
- Returns:
The whole form corresponding to all the terms.
- Return type:
- label_map(term_filter, map_if_true=<function identity>, map_if_false=<function identity>)[source]¶
Map selected terms in the labelled form, returning a new labelled form.
- Parameters:
term_filter – A function to filter the labelled form’s terms.
map_if_true – How to map the terms for which the term_filter returns True. Defaults to identity.
map_if_false – How to map the terms for which the term_filter returns False. Defaults to identity.
- Returns:
A new labelled form with the terms mapped.
- Return type:
- terms¶
- class firedrake.fml.form_manipulation_language.Term(form, label_dict=None)[source]¶
Bases:
objectA Term object contains a form and its labels.
- form¶
- get(label)[source]¶
Return the value of a label.
- Parameters:
label – The label to return the value of.
- Returns:
The value of a label.
- Return type:
Any
- has_label(*labels, return_tuple=False)[source]¶
Return whether the specified labels are attached to this term.
- Parameters:
*labels – A label or series of labels. A tuple is automatically returned if multiple labels are provided as arguments.
return_tuple – If True, forces a tuple to be returned even if only one label is provided as an argument. Defaults to False.
- Returns:
Booleans corresponding to whether the term has the specified labels.
- Return type:
- labels¶
- firedrake.fml.form_manipulation_language.all_terms(t)[source]¶
Map all terms to
True.- Parameters:
t – A term.
- Returns:
True.
- Return type:
- firedrake.fml.form_manipulation_language.drop(t)[source]¶
Map all terms to
None.- Parameters:
t – A term.
- Returns:
None.
- Return type:
None
firedrake.fml.replacement module¶
Generic routines for replacing functions using FML.
- firedrake.fml.replacement.replace_subject(new_subj, old_idx=None, new_idx=None)[source]¶
Replace the subject in a term with a new variable.
- Parameters:
new – The new expression to replace the subject.
old_idx – The index of the old subject to be replaced. If the old variable is not indexable then this should be None.
new_idx – The index of the new subject to replace with. If the new variable is not indexable then this should be None.
- Returns:
A function that takes in t, a Term, and returns a new Term with form containing the
new_testandlabels=t.labels- Return type:
Callable
- firedrake.fml.replacement.replace_test_function(new_test, old_idx=None, new_idx=None)[source]¶
Replace the test function in a term with a new test function.
- Parameters:
new_test – The new test function.
old_idx – The index of the old TestFunction to be replaced. If the old variable is not indexable then this should be None.
new_idx – The index of the new TestFunction to replace with. If the new variable is not indexable then this should be None.
- Returns:
A function that takes in t, a .Term, and returns a new .Term with form containing the
new_testandlabels=t.labels- Return type:
Callable
- firedrake.fml.replacement.replace_trial_function(new_trial, old_idx=None, new_idx=None)[source]¶
Replace the trial function in a term with a new expression.
- Parameters:
new – The new function.
old_idx – The index of the old Function or TrialFunction to be replaced. If the old variable is not indexable then this should be None.
new_idx – The index of the new Function or TrialFunction to replace with. If the new variable is not indexable then this should be None.
- Returns:
A function that takes in t, a Term, and returns a new Term with form containing the
new_testandlabels=t.labels- Return type:
Callable
