gel.fix_dofs
Base implementation of the function to restrict the control variables of the inverse model to only those in the event horizon.
Generalized usage is also possible, this function will be overriden in
gel.fix_dofs_overloaded with appropriate adjoint information for use
with automatic differentiation.
Credit https://fenicsproject.discourse.group/t/specific-dof-of-a-function-as-control-variable/3300/3
1"""Base implementation of the function to restrict the control variables 2of the inverse model to only those in the event horizon. 3 4Generalized usage is also possible, this function will be overriden in 5`gel.fix_dofs_overloaded` with appropriate adjoint information for use 6with automatic differentiation. 7 8Credit https://fenicsproject.discourse.group/t/specific-dof-of-a-function-as-control-variable/3300/3""" 9from fenics import * 10from fenics_adjoint import * 11 12 13def fix_dofs(func, fixed_indexes, fixed_values): 14 """Forces DoF values of a FE function to specific values. 15 16 * `func` is a FEniCS function in a space with DoFs 17 * `fixed_indexes` is an iterable of integer local DoF indices 18 * `fixed_values` is an iterable of the same size as `fixed_indexes` 19 with the float values to set the DoFs to. 20 """ 21 new_fun = Function(func.function_space(), func.vector()) 22 for idx, val in zip(fixed_indexes, fixed_values): 23 new_fun.vector().vec().setValueLocal(idx, val) 24 new_fun.vector().apply("") 25 return new_fun
def
fix_dofs(func, fixed_indexes, fixed_values):
14def fix_dofs(func, fixed_indexes, fixed_values): 15 """Forces DoF values of a FE function to specific values. 16 17 * `func` is a FEniCS function in a space with DoFs 18 * `fixed_indexes` is an iterable of integer local DoF indices 19 * `fixed_values` is an iterable of the same size as `fixed_indexes` 20 with the float values to set the DoFs to. 21 """ 22 new_fun = Function(func.function_space(), func.vector()) 23 for idx, val in zip(fixed_indexes, fixed_values): 24 new_fun.vector().vec().setValueLocal(idx, val) 25 new_fun.vector().apply("") 26 return new_fun
Forces DoF values of a FE function to specific values.
funcis a FEniCS function in a space with DoFsfixed_indexesis an iterable of integer local DoF indicesfixed_valuesis an iterable of the same size asfixed_indexeswith the float values to set the DoFs to.