Пример #1
0
print libspud.get_option_shape(tensor_path)
print libspud.get_option_rank(tensor_path)
print libspud.get_option(tensor_path)
assert (libspud.get_option(tensor_path) == [[5.0, 6.0], [7.0, 8.0]])

try:
    libspud.add_option('/foo')
except libspud.SpudNewKeyWarning, e:
    print "caught libspud.SpudNewKeyWarning: " + e.message
print libspud.option_count('/foo')

libspud.set_option('/problem_type', 'helloworld')
print libspud.get_option('/problem_type')

try:
    libspud.set_option_attribute('/foo/bar', 'foobar')
except libspud.SpudNewKeyWarning, e:
    print "caught libspud.SpudNewKeyWarning: " + e.message
print libspud.get_option('/foo/bar')

libspud.delete_option('/foo')
print libspud.option_count('/foo')

try:
    libspud.get_option('/foo')
except libspud.SpudKeyError, e:
    print "caught libspud.SpudKeyError: " + e.message

try:
    libspud.get_option('/geometry')
except libspud.SpudTypeError, e:
Пример #2
0
assert(libspud.get_option(tensor_path)==[[5.0, 6.0, 2.0],[7.0, 8.0, 1.0]])

try:
  libspud.add_option('/foo')
  assert False
except libspud.SpudNewKeyWarning, e:
  pass

assert libspud.option_count('/foo') == 1

libspud.set_option('/problem_type', 'helloworld')
assert libspud.get_option('/problem_type') == "helloworld"

try:
  libspud.set_option_attribute('/foo/bar', 'foobar')
  assert False
except libspud.SpudNewKeyWarning, e:
  pass

assert libspud.get_option('/foo/bar') == "foobar"
  
libspud.delete_option('/foo')
assert libspud.option_count('/foo') == 0

try:
  libspud.get_option('/foo')
  assert False
except libspud.SpudKeyError, e:
  pass
Пример #3
0
def convert(fluidity_options_file_path, ff_options_file_path):

    # Read in Fluidity simulation options

    libspud.clear_options()
    libspud.load_options(fluidity_options_file_path)

    # Simulation name
    simulation_name = libspud.get_option("/simulation_name")

    # Geometry
    base = "/geometry"
    dimension = libspud.get_option(base + "/dimension")
    mesh_path = libspud.get_option(
        base + "/mesh::CoordinateMesh/from_file/file_name"
    ) + ".msh"  # FIXME: Always assumes gmsh format.

    # Function spaces
    velocity_function_space = FunctionSpace("/geometry", 1)
    freesurface_function_space = FunctionSpace("/geometry", 2)

    # Timestepping
    base = "/timestepping"
    current_time = libspud.get_option(base + "/current_time")
    timestep = libspud.get_option(base + "/timestep")
    finish_time = libspud.get_option(base + "/finish_time")

    ## Steady-state
    if (libspud.have_option(base + "/steady_state")):
        if (libspud.have_option(base + "/steady_state/tolerance")):
            steady_state = libspud.get_option(base + "/steady_state/tolerance")
        else:
            steady_state = 1e-7
    else:
        steady_state = None

    # I/O
    base = "/io"
    dump_format = libspud.get_option(base + "/dump_format")
    if (libspud.have_option(base + "/dump_period")):
        dump_period = libspud.get_option(base + "/dump_period/constant")
    elif (libspud.have_option(base + "/dump_period_in_timesteps")):
        dump_period = libspud.get_option(
            base + "/dump_period_in_timesteps/constant") * timestep
    else:
        print "Unable to obtain dump_period."
        sys.exit()

    # Gravity
    g_magnitude = libspud.get_option("/physical_parameters/gravity/magnitude")

    # Velocity field (momentum equation)
    base = "/material_phase[0]/vector_field::Velocity"

    ## Depth (free surface mean height)
    c = libspud.get_child_name(
        base +
        "/prognostic/equation::ShallowWater/scalar_field::BottomDepth/prescribed/value::WholeMesh/",
        1)
    depth = libspud.get_option(
        base +
        "/prognostic/equation::ShallowWater/scalar_field::BottomDepth/prescribed/value::WholeMesh/%s"
        % c)

    ## Bottom drag coefficient
    if (libspud.have_option(base +
                            "/prognostic/equation::ShallowWater/bottom_drag")):
        c = libspud.get_child_name(
            base +
            "/prognostic/equation::ShallowWater/bottom_drag/scalar_field::BottomDragCoefficient/prescribed/value::WholeMesh/",
            1)
        bottom_drag = libspud.get_option(
            base +
            "/prognostic/equation::ShallowWater/bottom_drag/scalar_field::BottomDragCoefficient/prescribed/value::WholeMesh/%s"
            % c)
    else:
        bottom_drag = None

    ## Viscosity
    if (libspud.have_option(base + "/prognostic/tensor_field::Viscosity")):
        viscosity = libspud.get_option(
            base +
            "/prognostic/tensor_field::Viscosity/prescribed/value::WholeMesh/anisotropic_symmetric/constant"
        )[0][0]
    else:
        viscosity = None

    ## Momentum source
    if (libspud.have_option(base + "/prognostic/vector_field::Source")):
        c = libspud.get_child_name(
            base +
            "/prognostic/vector_field::Source/prescribed/value::WholeMesh/", 1)
        momentum_source = libspud.get_option(
            base +
            "/prognostic/vector_field::Source/prescribed/value::WholeMesh/%s" %
            c)
    else:
        momentum_source = None

    ## Initial condition
    if (libspud.have_option(base +
                            "/prognostic/initial_condition::WholeMesh")):
        c = libspud.get_child_name(
            base + "/prognostic/initial_condition::WholeMesh/", 1)
        velocity_initial_condition = libspud.get_option(
            base + "/prognostic/initial_condition::WholeMesh/%s" % c)
    else:
        velocity_initial_condition = 0.0

    ## Boundary conditions
    number_of_bcs = libspud.option_count(base +
                                         "/prognostic/boundary_conditions")
    velocity_bcs = []
    for i in range(number_of_bcs):
        velocity_bcs.append(
            VelocityBoundaryCondition(base +
                                      "/prognostic/boundary_conditions[%d]" %
                                      i))

    # Pressure field (continuity equation)
    base = "/material_phase[0]/scalar_field::Pressure"
    integrate_by_parts = libspud.have_option(
        base +
        "/prognostic/spatial_discretisation/continuous_galerkin/integrate_continuity_by_parts"
    )

    ## Initial condition
    if (libspud.have_option(base +
                            "/prognostic/initial_condition::WholeMesh")):
        c = libspud.get_child_name(
            base + "/prognostic/initial_condition::WholeMesh/", 1)
        pressure_initial_condition = libspud.get_option(
            base + "/prognostic/initial_condition::WholeMesh/%s" % c)
    else:
        pressure_initial_condition = 0.0

    ## Boundary conditions
    number_of_bcs = libspud.option_count(base +
                                         "/prognostic/boundary_conditions")
    pressure_bcs = []
    for i in range(number_of_bcs):
        pressure_bcs.append(
            PressureBoundaryCondition(base +
                                      "/prognostic/boundary_conditions[%d]" %
                                      i))

    ## Continuity source
    if (libspud.have_option(base + "/prognostic/scalar_field::Source")):
        c = libspud.get_child_name(
            base +
            "/prognostic/scalar_field::Source/prescribed/value::WholeMesh/", 1)
        continuity_source = libspud.get_option(
            base +
            "/prognostic/scalar_field::Source/prescribed/value::WholeMesh/%s" %
            c)
    else:
        continuity_source = None

    # Write out to a Firedrake-Fluids simulation configuration file
    libspud.clear_options()

    # Create a bare-bones .swml file to add to.
    f = open(ff_options_file_path, "w")
    f.write("<?xml version='1.0' encoding='utf-8'?>\n")
    f.write("<shallow_water_options>\n")
    f.write("</shallow_water_options>\n")
    f.close()

    libspud.load_options(ff_options_file_path)

    # Simulation name
    libspud.set_option("/simulation_name", simulation_name)

    # Geometry
    base = "/geometry"
    libspud.set_option(base + "/dimension", dimension)
    libspud.set_option(base + "/mesh/from_file/relative_path", mesh_path)

    # Function spaces
    base = "/function_spaces"
    libspud.set_option(base + "/function_space::VelocityFunctionSpace/degree",
                       velocity_function_space.degree)
    libspud.set_option(base + "/function_space::VelocityFunctionSpace/family",
                       velocity_function_space.family)
    libspud.set_option(
        base + "/function_space::FreeSurfaceFunctionSpace/degree",
        freesurface_function_space.degree)
    libspud.set_option(
        base + "/function_space::FreeSurfaceFunctionSpace/family",
        freesurface_function_space.family)

    # I/O
    base = "/io"
    libspud.set_option(base + "/dump_format", dump_format)
    libspud.set_option(base + "/dump_period", dump_period)

    # Timestepping
    base = "/timestepping"
    print timestep
    libspud.set_option(base + "/current_time", current_time)
    try:
        libspud.set_option(base + "/timestep", timestep)
    except:
        pass
    libspud.set_option(base + "/finish_time", finish_time)

    ## Steady-state
    if (steady_state):
        libspud.set_option(base + "/steady_state/tolerance", steady_state)

    # Gravity
    libspud.set_option("/physical_parameters/gravity/magnitude", g_magnitude)

    # System/Core Fields: Velocity
    base = "/system/core_fields/vector_field::Velocity"

    ## Initial condition
    if (isinstance(velocity_initial_condition, str)):
        libspud.set_option(base + "/initial_condition/python",
                           velocity_initial_condition)
    else:
        libspud.set_option(base + "/initial_condition/constant",
                           velocity_initial_condition)

    ## Boundary conditions
    try:
        for i in range(len(velocity_bcs)):
            libspud.set_option(
                base +
                "/boundary_condition::%s/surface_ids" % velocity_bcs[i].name,
                velocity_bcs[i].surface_ids)
            libspud.set_option_attribute(
                base +
                "/boundary_condition::%s/type/name" % velocity_bcs[i].name,
                velocity_bcs[i].type)

            if (velocity_bcs[i].type == "dirichlet"):
                if (isinstance(velocity_bcs[i].value, str)):
                    libspud.set_option(
                        base +
                        "/boundary_condition::%s/type::dirichlet/value/python"
                        % velocity_bcs[i].name, velocity_bcs[i].value)
                else:
                    libspud.set_option(
                        base +
                        "/boundary_condition::%s/type::dirichlet/value/constant"
                        % velocity_bcs[i].name, velocity_bcs[i].value)
    except:
        pass

    # System/Core Fields: FreeSurfacePerturbation
    base = "/system/core_fields/scalar_field::FreeSurfacePerturbation"

    #FIXME: Pressure initial and boundary conditions are multiplied by 'g' in Fluidity, but not in Firedrake-Fluids.
    ## Initial condition
    if (isinstance(pressure_initial_condition, str)):
        libspud.set_option(base + "/initial_condition/python",
                           pressure_initial_condition)
    else:
        libspud.set_option(base + "/initial_condition/constant",
                           pressure_initial_condition)

    ## Boundary conditions
    try:
        for i in range(len(pressure_bcs)):
            libspud.set_option(
                base +
                "/boundary_condition::%s/surface_ids" % pressure_bcs[i].name,
                pressure_bcs[i].surface_ids)
            libspud.set_option(
                base +
                "/boundary_condition::%s/type/name" % pressure_bcs[i].name,
                pressure_bcs[i].type)

            if (pressure_bcs[i].type == "dirichlet"):
                if (isinstance(pressure_bcs[i].value, str)):
                    libspud.set_option(
                        base +
                        "/boundary_condition::%s/type::dirichlet/value/python"
                        % pressure_bcs[i].name, pressure_bcs[i].value)
                else:
                    libspud.set_option(
                        base +
                        "/boundary_condition::%s/type::dirichlet/value/constant"
                        % pressure_bcs[i].name, pressure_bcs[i].value)
    except:
        pass

    # System/Core Fields: FreeSurfaceMean
    base = "/system/core_fields/scalar_field::FreeSurfaceMean"
    if (isinstance(depth, str)):
        libspud.set_option(base + "/value/python", depth)
    else:
        libspud.set_option(base + "/value/constant", depth)

    # Equations: Continuity equation
    base = "/system/equations/continuity_equation"
    libspud.set_option(base + "/integrate_by_parts", integrate_by_parts)

    ## Source term
    if (continuity_source is not None):
        if (isinstance(continuity_source, str)):
            libspud.set_option(
                base + "/source_term/scalar_field::Source/value/python",
                continuity_source)
        else:
            libspud.set_option(
                base + "/source_term/scalar_field::Source/value/constant",
                continuity_source)

    # Equations: Momentum equation
    base = "/system/equations/momentum_equation"

    ## Viscosity
    if (viscosity is not None):
        if (isinstance(viscosity, str)):
            libspud.set_option(
                base + "/stress_term/scalar_field::Viscosity/value/python",
                viscosity)
        else:
            libspud.set_option(
                base + "/stress_term/scalar_field::Viscosity/value/constant",
                viscosity)

    ## Bottom drag
    if (bottom_drag is not None):
        if (isinstance(bottom_drag, str)):
            libspud.set_option(
                base +
                "/drag_term/scalar_field::BottomDragCoefficient/value/python",
                bottom_drag)
        else:
            libspud.set_option(
                base +
                "/drag_term/scalar_field::BottomDragCoefficient/value/constant",
                bottom_drag)

    ## Source term
    if (momentum_source is not None):
        if (isinstance(momentum_source, str)):
            libspud.set_option(
                base + "/source_term/vector_field::Source/value/python",
                momentum_source)
        else:
            libspud.set_option(
                base + "/source_term/vector_field::Source/value/constant",
                momentum_source)

    # Write all the applied options to file.
    libspud.write_options(ff_options_file_path)

    return
Пример #4
0
def convert(fluidity_options_file_path, ff_options_file_path):
   
   # Read in Fluidity simulation options
   
   libspud.clear_options()
   libspud.load_options(fluidity_options_file_path)
   
   # Simulation name
   simulation_name = libspud.get_option("/simulation_name")
   
   # Geometry
   base = "/geometry"
   dimension = libspud.get_option(base + "/dimension")
   mesh_path = libspud.get_option(base + "/mesh::CoordinateMesh/from_file/file_name") + ".msh" # FIXME: Always assumes gmsh format.
  
   # Function spaces
   velocity_function_space = FunctionSpace("/geometry", 1)
   freesurface_function_space = FunctionSpace("/geometry", 2)
    
   # Timestepping
   base = "/timestepping"
   current_time = libspud.get_option(base + "/current_time")
   timestep = libspud.get_option(base + "/timestep")
   finish_time = libspud.get_option(base + "/finish_time")

   ## Steady-state
   if(libspud.have_option(base + "/steady_state")):
      if(libspud.have_option(base + "/steady_state/tolerance")):
         steady_state = libspud.get_option(base + "/steady_state/tolerance")
      else:
         steady_state = 1e-7
   else:
      steady_state = None   

   # I/O
   base = "/io"
   dump_format = libspud.get_option(base + "/dump_format")
   if(libspud.have_option(base + "/dump_period")):
      dump_period = libspud.get_option(base + "/dump_period/constant")
   elif(libspud.have_option(base + "/dump_period_in_timesteps")):
      dump_period = libspud.get_option(base + "/dump_period_in_timesteps/constant")*timestep
   else:
      print "Unable to obtain dump_period."
      sys.exit()
      
   # Gravity
   g_magnitude = libspud.get_option("/physical_parameters/gravity/magnitude")
   
   # Velocity field (momentum equation)
   base = "/material_phase[0]/vector_field::Velocity"
   
   ## Depth (free surface mean height)
   c = libspud.get_child_name(base + "/prognostic/equation::ShallowWater/scalar_field::BottomDepth/prescribed/value::WholeMesh/", 1)
   depth = libspud.get_option(base + "/prognostic/equation::ShallowWater/scalar_field::BottomDepth/prescribed/value::WholeMesh/%s" % c)
   
   ## Bottom drag coefficient
   if(libspud.have_option(base + "/prognostic/equation::ShallowWater/bottom_drag")):
      c = libspud.get_child_name(base + "/prognostic/equation::ShallowWater/bottom_drag/scalar_field::BottomDragCoefficient/prescribed/value::WholeMesh/", 1)
      bottom_drag = libspud.get_option(base + "/prognostic/equation::ShallowWater/bottom_drag/scalar_field::BottomDragCoefficient/prescribed/value::WholeMesh/%s" % c)
   else:
      bottom_drag = None
      
   ## Viscosity
   if(libspud.have_option(base + "/prognostic/tensor_field::Viscosity")):
      viscosity = libspud.get_option(base + "/prognostic/tensor_field::Viscosity/prescribed/value::WholeMesh/anisotropic_symmetric/constant")[0][0]
   else:
      viscosity = None

   ## Momentum source
   if(libspud.have_option(base + "/prognostic/vector_field::Source")):
      c = libspud.get_child_name(base + "/prognostic/vector_field::Source/prescribed/value::WholeMesh/", 1)
      momentum_source = libspud.get_option(base + "/prognostic/vector_field::Source/prescribed/value::WholeMesh/%s" % c)
   else:
      momentum_source = None
      
   ## Initial condition
   if(libspud.have_option(base + "/prognostic/initial_condition::WholeMesh")):
      c = libspud.get_child_name(base + "/prognostic/initial_condition::WholeMesh/", 1)
      velocity_initial_condition = libspud.get_option(base + "/prognostic/initial_condition::WholeMesh/%s" % c)
   else:
      velocity_initial_condition = 0.0
      
   ## Boundary conditions
   number_of_bcs = libspud.option_count(base + "/prognostic/boundary_conditions")
   velocity_bcs = []
   for i in range(number_of_bcs):
      velocity_bcs.append(VelocityBoundaryCondition(base + "/prognostic/boundary_conditions[%d]" % i))
   
   
   # Pressure field (continuity equation)
   base = "/material_phase[0]/scalar_field::Pressure"
   integrate_by_parts = libspud.have_option(base + "/prognostic/spatial_discretisation/continuous_galerkin/integrate_continuity_by_parts")
   
   ## Initial condition
   if(libspud.have_option(base + "/prognostic/initial_condition::WholeMesh")):
      c = libspud.get_child_name(base + "/prognostic/initial_condition::WholeMesh/", 1)
      pressure_initial_condition = libspud.get_option(base + "/prognostic/initial_condition::WholeMesh/%s" % c)
   else:
      pressure_initial_condition = 0.0
      
   ## Boundary conditions
   number_of_bcs = libspud.option_count(base + "/prognostic/boundary_conditions")
   pressure_bcs = []
   for i in range(number_of_bcs):
      pressure_bcs.append(PressureBoundaryCondition(base + "/prognostic/boundary_conditions[%d]" % i))
   
   ## Continuity source
   if(libspud.have_option(base + "/prognostic/scalar_field::Source")):
      c = libspud.get_child_name(base + "/prognostic/scalar_field::Source/prescribed/value::WholeMesh/", 1)
      continuity_source = libspud.get_option(base + "/prognostic/scalar_field::Source/prescribed/value::WholeMesh/%s" % c)
   else:
      continuity_source = None
   





   
   
   # Write out to a Firedrake-Fluids simulation configuration file
   libspud.clear_options()
   
   # Create a bare-bones .swml file to add to.
   f = open(ff_options_file_path, "w")
   f.write("<?xml version='1.0' encoding='utf-8'?>\n")
   f.write("<shallow_water_options>\n")
   f.write("</shallow_water_options>\n")
   f.close()
   
   libspud.load_options(ff_options_file_path)

   # Simulation name
   libspud.set_option("/simulation_name", simulation_name)
   
   # Geometry
   base = "/geometry"
   libspud.set_option(base + "/dimension", dimension)
   libspud.set_option(base + "/mesh/from_file/relative_path", mesh_path)
   
   # Function spaces
   base = "/function_spaces"
   libspud.set_option(base + "/function_space::VelocityFunctionSpace/degree", velocity_function_space.degree)
   libspud.set_option(base + "/function_space::VelocityFunctionSpace/family", velocity_function_space.family)
   libspud.set_option(base + "/function_space::FreeSurfaceFunctionSpace/degree", freesurface_function_space.degree)
   libspud.set_option(base + "/function_space::FreeSurfaceFunctionSpace/family", freesurface_function_space.family)
   
   # I/O
   base = "/io"
   libspud.set_option(base + "/dump_format", dump_format)
   libspud.set_option(base + "/dump_period", dump_period)
   
   # Timestepping
   base = "/timestepping"
   print timestep
   libspud.set_option(base + "/current_time", current_time)
   try:
      libspud.set_option(base + "/timestep", timestep)
   except:
      pass
   libspud.set_option(base + "/finish_time", finish_time)
   
   ## Steady-state
   if(steady_state):
      libspud.set_option(base + "/steady_state/tolerance", steady_state)
      
   # Gravity
   libspud.set_option("/physical_parameters/gravity/magnitude", g_magnitude)
   
   # System/Core Fields: Velocity
   base = "/system/core_fields/vector_field::Velocity"
   
   ## Initial condition
   if(isinstance(velocity_initial_condition, str)):
      libspud.set_option(base + "/initial_condition/python", velocity_initial_condition)
   else:
      libspud.set_option(base + "/initial_condition/constant", velocity_initial_condition)
   
   ## Boundary conditions
   try:
      for i in range(len(velocity_bcs)):
         libspud.set_option(base + "/boundary_condition::%s/surface_ids" % velocity_bcs[i].name, velocity_bcs[i].surface_ids)
         libspud.set_option_attribute(base + "/boundary_condition::%s/type/name" % velocity_bcs[i].name, velocity_bcs[i].type)
         
         if(velocity_bcs[i].type == "dirichlet"):
            if(isinstance(velocity_bcs[i].value, str)):
               libspud.set_option(base + "/boundary_condition::%s/type::dirichlet/value/python" % velocity_bcs[i].name, velocity_bcs[i].value)
            else:
               libspud.set_option(base + "/boundary_condition::%s/type::dirichlet/value/constant" % velocity_bcs[i].name, velocity_bcs[i].value)
   except:
      pass

   # System/Core Fields: FreeSurfacePerturbation
   base = "/system/core_fields/scalar_field::FreeSurfacePerturbation"
   
   #FIXME: Pressure initial and boundary conditions are multiplied by 'g' in Fluidity, but not in Firedrake-Fluids.
   ## Initial condition
   if(isinstance(pressure_initial_condition, str)):
      libspud.set_option(base + "/initial_condition/python", pressure_initial_condition)
   else:
      libspud.set_option(base + "/initial_condition/constant", pressure_initial_condition)
   
   ## Boundary conditions
   try:
      for i in range(len(pressure_bcs)):
         libspud.set_option(base + "/boundary_condition::%s/surface_ids" % pressure_bcs[i].name, pressure_bcs[i].surface_ids)
         libspud.set_option(base + "/boundary_condition::%s/type/name" % pressure_bcs[i].name, pressure_bcs[i].type)
         
         if(pressure_bcs[i].type == "dirichlet"):
            if(isinstance(pressure_bcs[i].value, str)):
               libspud.set_option(base + "/boundary_condition::%s/type::dirichlet/value/python" % pressure_bcs[i].name, pressure_bcs[i].value)
            else:
               libspud.set_option(base + "/boundary_condition::%s/type::dirichlet/value/constant" % pressure_bcs[i].name, pressure_bcs[i].value)
   except:
      pass

   # System/Core Fields: FreeSurfaceMean
   base = "/system/core_fields/scalar_field::FreeSurfaceMean"
   if(isinstance(depth, str)):
      libspud.set_option(base + "/value/python", depth)
   else:
      libspud.set_option(base + "/value/constant", depth)
      
   
   # Equations: Continuity equation
   base = "/system/equations/continuity_equation"
   libspud.set_option(base + "/integrate_by_parts", integrate_by_parts)

   ## Source term
   if(continuity_source is not None):
      if(isinstance(continuity_source, str)):
         libspud.set_option(base + "/source_term/scalar_field::Source/value/python", continuity_source)
      else:
         libspud.set_option(base + "/source_term/scalar_field::Source/value/constant", continuity_source)
         
   # Equations: Momentum equation
   base = "/system/equations/momentum_equation"
   
   ## Viscosity
   if(viscosity is not None):
      if(isinstance(viscosity, str)):
         libspud.set_option(base + "/stress_term/scalar_field::Viscosity/value/python", viscosity)
      else:
         libspud.set_option(base + "/stress_term/scalar_field::Viscosity/value/constant", viscosity)

   ## Bottom drag
   if(bottom_drag is not None):
      if(isinstance(bottom_drag, str)):
         libspud.set_option(base + "/drag_term/scalar_field::BottomDragCoefficient/value/python", bottom_drag)
      else:
         libspud.set_option(base + "/drag_term/scalar_field::BottomDragCoefficient/value/constant", bottom_drag)
   
   ## Source term
   if(momentum_source is not None):
      if(isinstance(momentum_source, str)):
         libspud.set_option(base + "/source_term/vector_field::Source/value/python", momentum_source)
      else:
         libspud.set_option(base + "/source_term/vector_field::Source/value/constant", momentum_source)
   
   
   # Write all the applied options to file.
   libspud.write_options(ff_options_file_path)
   
   return