# Boundary conditions bc = ns_solver.BoundaryConditions bc.regions = [mesh.topology.uri()] bc.add_constant_bc(region_name='bottom', variable_name='Velocity').value = [0., 0.] bc.add_constant_bc(region_name='top', variable_name='Velocity').value = [0., 0.] pressure_integral = solver.add_unsteady_solver('cf3.UFEM.SurfaceIntegral') pressure_integral.set_field(variable_name='Pressure', field_tag='navier_stokes_solution') pressure_integral.regions = [mesh.topology.access_component('bottom').uri()] pressure_integral.history = solver.create_component('ForceHistory', 'cf3.solver.History') pressure_integral.history.file = cf.URI('force-implicit.tsv') pressure_integral.history.dimension = 2 bulk_velocity = solver.add_unsteady_solver('cf3.UFEM.BulkVelocity') bulk_velocity.set_field(variable_name='Velocity', field_tag='navier_stokes_solution') bulk_velocity.regions = [mesh.topology.right.uri()] bulk_velocity.history = bulk_velocity.create_component('History', 'cf3.solver.History') bulk_velocity.history.file = cf.URI('bulk-velocity.tsv') bulk_velocity.history.dimension = 1 lss = ns_solver.LSS #lss.SolutionStrategy.Parameters.linear_solver_type = 'Amesos' #lss.SolutionStrategy.Parameters.preconditioner_type = 'ML' #lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.add_parameter(name = 'ML output', value = 10)
# setup a model model = root.create_component('NavierStokes', 'cf3.solver.ModelUnsteady') domain = model.create_domain() physics = model.create_physics('cf3.UFEM.KEpsilonPhysics') solver = model.create_solver('cf3.UFEM.Solver') # Add the Navier-Stokes solver as an unsteady solver nstokes = solver.add_unsteady_solver('cf3.UFEM.NavierStokes') # Add the k-epsilon turbulence model solver(ke) ke = solver.add_unsteady_solver('cf3.UFEM.StandardKEpsilon') ke.options.theta = theta ke.options.l_max = 10000. mesh = domain.load_mesh(file=cf.URI(sys.argv[1]), name='Mesh') # Make the boundary global, to allow wall distance and periodics to work correctly make_boundary_global = domain.create_component( 'MakeBoundaryGlobal', 'cf3.mesh.actions.MakeBoundaryGlobal') make_boundary_global.mesh = mesh make_boundary_global.execute() # Because of multi-region support, solvers do not automatically have a region assigned, so we must manually set the solvers to work on the whole mesh nstokes.regions = [mesh.topology.uri()] ke.regions = [mesh.topology.uri()] # solver setup lss = nstokes.create_lss( matrix_builder='cf3.math.LSS.TrilinosFEVbrMatrix', solution_strategy='cf3.math.LSS.TrilinosStratimikosStrategy')
####################################### # POST-PROCESSING ####################################### compute_char = model.create_component('compute_characteristics','cf3.dcm.equations.lineuler.ComputeCharacteristicVariablesUniform2D') compute_char.normal = [0.,-1.] compute_char.field = lineuler.solution compute_char.c0 = math.sqrt(lineuler.gamma*p0/rho0) compute_char.execute() ######################## # OUTPUT ######################## fields = [ lineuler.fields.solution.uri(), lineuler.fields.char.uri() ] vis_mesh = model.domain.create_component('vis_mesh','cf3.mesh.Mesh') mesh_gen.mesh = vis_mesh.uri() mesh_gen.nb_cells = [100,100] mesh_gen.execute() vis_solution = vis_mesh.geometry.create_field(name='solution',variables='rho,rho0u[vector],p') interpolator = model.tools.create_component('interpolator','cf3.mesh.ShapeFunctionInterpolator') interpolator.interpolate(source=lineuler.solution.uri(),target=vis_solution.uri()) vis_mesh.write_mesh(file=cf.URI('file:wallbc.plt'), fields=[vis_solution.uri()]) vis_mesh.write_mesh(file=cf.URI('file:wallbc.msh'), fields=[vis_solution.uri()])
import sys import coolfluid as cf # Global configuration cf.Core.environment().options().set('log_level', 4) # setup a model model = cf.Core.root().create_component('HotModel', 'cf3.solver.Model') domain = model.create_domain() physics = model.create_physics('cf3.UFEM.NavierStokesPhysics') solver = model.create_solver('cf3.UFEM.Solver') hc = solver.add_direct_solver('cf3.UFEM.HeatConductionSteady') # load the mesh (passed as first argument to the script) mesh = domain.load_mesh(file=cf.URI(sys.argv[1]), name='Mesh') hc.options().set('regions', [mesh.access_component('topology').uri()]) hc.children.SetSolution.options.relaxation_factor_hc = 1. # Boundary conditions bc = hc.get_child('BoundaryConditions') bc.add_constant_bc(region_name='inlet', variable_name='Temperature').options().set('value', 10) bc.add_constant_bc(region_name='outlet', variable_name='Temperature').options().set('value', 35) # run the simulation model.simulate() # check the result coords = mesh.access_component('geometry/coordinates')
mesh_generator.lengths = [10] mesh_generator.offsets = [-5] mesh_generator.execute() load_balance = mesh_generator.create_component("load_balancer","cf3.mesh.actions.LoadBalance") load_balance.options().set("mesh",mesh) load_balance.execute() model.build_faces(); ### Add PDE euler = model.add_pde(name='euler',type='cf3.dcm.equations.euler.Euler1D',shape_function='cf3.dcm.core.LegendreGaussEndP2') euler.add_term(name='rhs',type='cf3.sdm.br2.euler_RightHandSide1D') euler.gamma = 1.4 euler.R = 287.05 euler.add_bc(name='reflect',type='cf3.dcm.equations.euler.BCMirror1D',regions=[mesh.topology.xneg,mesh.topology.xpos]) ### Initial solution model.tools.init_field.init_field( field=euler.solution, functions = [ 'r_L:=4.696; r_R:=1.408; u_L:=0; u_R:=0; p_L:=404400; p_R:=101100; g:=1.4; if(x<=0,r_L,r_R)', 'r_L:=4.696; r_R:=1.408; u_L:=0; u_R:=0; p_L:=404400; p_R:=101100; g:=1.4; if(x<=0,r_L*u_L,r_R*u_R)', 'r_L:=4.696; r_R:=1.408; u_L:=0; u_R:=0; p_L:=404400; p_R:=101100; g:=1.4; if(x<=0,p_L/(g-1)+0.5*r_L*u_L*u_L,p_R/(g-1)+0.5*r_R*u_R*u_R)' ] ) ### Solve solver = model.add_solver(name='solver',pde=euler,solver='cf3.dcm.solver.erk.MidPoint') solver.children.time_step_computer.cfl=0.3 solver.solve_time_step(0.008) mesh.write_mesh(file=cf.URI('file:euler-shocktube-1d.plt'), fields=[euler.solution.uri()])
# Setup a time series write # write_manager = solver.add_unsteady_solver('cf3.solver.actions.TimeSeriesWriter') # write_manager.interval = 1 # writer = write_manager.create_component('VTKWriter', 'cf3.vtk.MultiblockWriter') # writer.mesh = mesh # writer.file = cf.URI('atest-channel-kepsilon-{iteration}.vtm') # Time setup time = model.create_time() time.time_step = 10. time.end_time = 3000. probe0 = solver.add_probe(name='Probe', parent=nstokes, dict=mesh.geometry) probe0.Log.variables = ['Velocity[0]', 'EffectiveViscosity'] probe0.coordinate = [x_size / 2., 0.] probe0.History.file = cf.URI('atest-channel-kepsilon-probe.tsv') # set up coprocessing # coproc = solver.add_unsteady_solver('cf3.vtk.LiveCoProcessor') # coproc.cf3_to_vtk = coproc.create_component('CF3ToVTK', 'cf3.vtk.CF3ToVTK') # coproc.cf3_to_vtk.mesh = mesh # Run the simulation model.simulate() model.print_timing_tree() # Plot simulation velocity try: import pylab as pl coords = np.array(mesh.geometry.coordinates) ns_sol = np.array(mesh.geometry.navier_stokes_solution)
scalaradv.BoundaryConditions.add_constant_bc( region_name='bottom2', variable_name='Temperature').options().set('value', phi_in) scalaradv.BoundaryConditions.add_constant_bc( region_name='bottom3', variable_name='Temperature').options().set('value', phi_in) scalaradv.BoundaryConditions.add_constant_bc( region_name='top', variable_name='Temperature').options().set('value', phi_in) # Time setup time = model.create_time() time.options().set('time_step', 0.01) # Setup a time series write final_end_time = 0.1 save_interval = 0.01 current_end_time = 0. iteration = 0 while current_end_time < final_end_time: current_end_time += save_interval time.options().set('end_time', current_end_time) model.simulate() domain.write_mesh( cf.URI('atest-flatplate2d-scalar-' + str(iteration) + '.pvtu')) iteration += 1 if iteration == 1: solver.options().set('disabled_actions', ['InitialConditions']) # print timings model.print_timing_tree()
mesh = domain.create_component('Mesh', 'cf3.mesh.Mesh') blocks.create_mesh(mesh.uri()) ns_solver.regions = [mesh.topology.uri()] u_in = [2., 0.] solver.create_fields() #initial condition for the velocity. Unset variables (i.e. the pressure) default to zero solver.InitialConditions.navier_stokes_solution.Velocity = u_in ic_visc.value = ['10. + 2*sin(2/pi*x)'] ic_visc.regions = [mesh.topology.uri()] ic_visc.execute() domain.write_mesh(cf.URI('laminar-channel-2d_output-init.pvtu')) # Physical constants physics.options().set('density', 1000.) physics.options().set('dynamic_viscosity', 10.) physics.options().set('reference_velocity', u_in[0]) # Boundary conditions bc = ns_solver.BoundaryConditions bc.add_constant_bc(region_name='left', variable_name='Velocity').value = u_in bc.add_constant_bc(region_name='bottom', variable_name='Velocity').value = [0., 0.] bc.add_constant_bc(region_name='top', variable_name='Velocity').value = [0., 0.] bc.add_constant_bc(region_name='right', variable_name='Pressure').value = 0.
root = cf.Core.root() # 2D triangles test mesh2d = root.create_component('mesh2d','cf3.mesh.Mesh') mesh_generator = root.create_component("mesh_generator","cf3.mesh.SimpleMeshGenerator") mesh_generator.options().set("mesh",mesh2d.uri()) mesh_generator.options().set("nb_cells",[100,100]) mesh_generator.options().set("lengths",[1.,1.]) mesh_generator.options().set("offsets",[0.,0.]) mesh_generator.execute() triangulator = root.create_component('triangulator', 'cf3.mesh.MeshTriangulator') triangulator.options().set('mesh', mesh2d) triangulator.execute() mesh2d.write_mesh(cf.URI('triangulated.msh')) # 3D tetrahedra test mesh3d = root.create_component('mesh3d','cf3.mesh.Mesh') blocks = root.create_component('model', 'cf3.mesh.BlockMesh.BlockArrays') points = blocks.create_points(dimensions = 2, nb_points = 4) points[0] = [0., 0.] points[1] = [1., 0.] points[2] = [1., 1.] points[3] = [0., 1.] block_nodes = blocks.create_blocks(1) block_nodes[0] = [0, 1, 2, 3] block_subdivs = blocks.create_block_subdivisions() block_subdivs[0] = [10,10] gradings = blocks.create_block_gradings()
bc = ke.LSS.BoundaryConditions bc.add_constant_bc(region_name='left', variable_name='epsilon').value = e0 bc.create_bc_action( region_name='top', builder_name='cf3.UFEM.BCWallEpsilon').options.theta = ke.options.theta # Time setup time = model.create_time() time.time_step = 0.001 time.end_time = 1. probe0 = solver.add_probe(name='Probe', parent=nstokes, dict=mesh.geometry) probe0.Log.variables = ['Velocity[0]', 'EffectiveViscosity'] probe0.coordinate = [x_size, 0.] probe0.History.file = cf.URI('atest-comte-bellot-probe.tsv') # Run the simulation model.simulate() # writer = domain.create_component('VTKWriter', 'cf3.vtk.MultiblockWriter') # writer.mesh = mesh # writer.file = cf.URI('atest-comte-bellot.vtm') # writer.execute() # Plot simulation velocity try: import numpy as np import pylab as pl import os
cf.environment.assertion_backtrace = False cf.environment.exception_backtrace = False cf.environment.regist_signal_handlers = False cf.environment.exception_log_level = 0 cf.environment.log_level = 1 cf.environment.exception_outputs = False # setup a model model = cf.Core.root().create_component('HotModel', 'cf3.solver.Model') domain = model.create_domain() physics = model.create_physics('cf3.UFEM.NavierStokesPhysics') solver = model.create_solver('cf3.UFEM.Solver') hc = solver.add_direct_solver('cf3.UFEM.HeatConductionSteady') # load the mesh (passed as first argument to the script) mesh = domain.load_mesh(file=cf.URI(sys.argv[1]), name='Mesh') hc.regions = [mesh.topology.uri()] # lss setup lss = hc.create_lss('cf3.math.LSS.TrilinosFEVbrMatrix') lss.Matrix.settings_file = sys.argv[2] # Boundary conditions bc = hc.BoundaryConditions bc.add_constant_bc(region_name='inner', variable_name='Temperature').value = 10 bc.add_constant_bc(region_name='outer', variable_name='Temperature').value = 35 # run the simulation model.simulate() # Write result domain.write_mesh(cf.URI('atest-ufem-heat2d-disk.pvtu'))
# Boundary conditions bc_u = ns_solver.InnerLoop.VelocitySystem.VelocityBC bc_u.create_bc_action( region_name='bottom', builder_name='cf3.UFEM.NavierStokesSemiExplicitVelocityBC').value = [ '0.', '0.' ] bc_u.create_bc_action( region_name='top', builder_name='cf3.UFEM.NavierStokesSemiExplicitVelocityBC').value = [ '0.', '0.' ] bc_u.create_bc_action( region_name='left', builder_name='cf3.UFEM.NavierStokesSemiExplicitVelocityBC' ).value = ic_u.value ns_solver.InnerLoop.PressureSystem.PressureBC.add_constant_bc( region_name='right', variable_name='Pressure').value = 0. # Time setup time = model.create_time() time.time_step = tstep time.end_time = 10. * tstep model.simulate() domain.write_mesh(cf.URI('explicit-implicit-laminar-channel-2d.pvtu')) # print timings model.print_timing_tree()
link_horizontal = partitioner.create_link_periodic_nodes() link_horizontal.source_region = mesh.topology.right link_horizontal.destination_region = mesh.topology.left link_horizontal.translation_vector = [-1., 0.] partitioner.execute() # link_horizontal.mesh = mesh # link_horizontal.execute() make_par_data = domain.create_component( 'MakeParData', 'cf3.solver.actions.ParallelDataToFields') make_par_data.mesh = mesh make_par_data.execute() domain.write_mesh(cf.URI('heat2d-periodic-input.pvtu')) hc.regions = [mesh.topology.interior.uri()] writer = domain.create_component('MshWriter', 'cf3.mesh.gmsh.Writer') writer.enable_overlap = True writer.mesh = mesh writer.fields = [mesh.geometry.node_gids.uri()] writer.file = cf.URI('heat2d-periodic-input.msh') writer.execute() # Boundary conditions bc = hc.BoundaryConditions bc.regions = [mesh.topology.uri()] bc.add_constant_bc(region_name='bottom', variable_name='Temperature').value = 10
link_horizontal.source_region = mesh.topology.right link_horizontal.destination_region = mesh.topology.left link_horizontal.translation_vector = [-1., 0.] link_horizontal.execute() make_par_data = root.create_component( 'MakeParData', 'cf3.solver.actions.ParallelDataToFields') make_par_data.mesh = mesh make_par_data.execute() p2space = mesh.create_continuous_space(name='TestP2Space', shape_function='cf3.mesh.LagrangeP2') mesh.print_tree() outfile = cf.URI('cf3test.cf3mesh') domain.write_mesh(outfile) reader = domain.create_component('CF3MeshReader', 'cf3.mesh.cf3mesh.Reader') reader.mesh = domain.create_component('ReadBackMesh', 'cf3.mesh.Mesh') reader.file = outfile reader.execute() reader.mesh.print_tree() meshdiff = domain.create_component('MeshDiff', 'cf3.mesh.actions.MeshDiff') meshdiff.left = mesh meshdiff.right = reader.mesh meshdiff.execute() if not meshdiff.properties()['mesh_equal']:
mesh3d = root.create_component('mesh3d', 'cf3.mesh.Mesh') blocks = root.create_component('model', 'cf3.mesh.BlockMesh.BlockArrays') points = blocks.create_points(dimensions=2, nb_points=4) points[0] = [0., 0.] points[1] = [1., 0.] points[2] = [1., 1.] points[3] = [0., 1.] block_nodes = blocks.create_blocks(1) block_nodes[0] = [0, 1, 2, 3] block_subdivs = blocks.create_block_subdivisions() block_subdivs[0] = [segs, segs] gradings = blocks.create_block_gradings() gradings[0] = [1., 1., 0.1, 0.1] blocks.create_patch_nb_faces(name='bottom', nb_faces=1)[0] = [0, 1] blocks.create_patch_nb_faces(name='right', nb_faces=1)[0] = [1, 2] blocks.create_patch_nb_faces(name='top', nb_faces=1)[0] = [2, 3] blocks.create_patch_nb_faces(name='left', nb_faces=1)[0] = [3, 0] blocks.extrude_blocks(positions=[1., 2.], nb_segments=[segs / 2, segs / 2], gradings=[1., 1.]) blocks.create_mesh(mesh3d.uri()) #mesh3d.write_mesh(cf.URI('hexahedrons.pvtu')) triangulator = root.create_component('Tetrahedralize', 'cf3.CGAL.Tetrahedralize') triangulator.options().set('mesh', mesh3d) triangulator.execute() mesh3d.write_mesh(cf.URI('tetrahedralized.vtk'))
ic_g = solver.InitialConditions.NavierStokes.create_initial_condition(builder_name = 'cf3.UFEM.InitialConditionFunction', field_tag = 'body_force') ic_g.variable_name = 'Force' ic_g.regions = [mesh.topology.uri()] ic_g.value = [str(a_tau), '0', '0'] # Boundary conditions bc_u = ns_solver.VelocityLSS.BC bc_u.add_constant_bc(region_name = 'bottom', variable_name = 'Velocity').value = [0., 0., 0.] bc_u.add_constant_bc(region_name = 'top', variable_name = 'Velocity').value = [0., 0., 0.] # Pressure BC ns_solver.PressureLSS.BC.add_constant_bc(region_name = 'center', variable_name = 'Pressure').value = 0. #statistics stats = solver.add_unsteady_solver('cf3.solver.actions.TurbulenceStatistics') stats.region = mesh.topology stats.file = cf.URI('turbulence-statistics.txt') stats.rolling_window = 1000 stats.add_probe([0., 0., 0. ]) solver.create_fields() stats.setup() #domain.write_mesh(cf.URI('chan180-mkmfields.cf3mesh')) # Restarter restart_writer = solver.add_restart_writer() restart_writer.Writer.file = cf.URI('chan180-{iteration}.cf3restart') restart_writer.interval = 1000 dir_avg = solver.TimeLoop.children.WriteRestartManager.create_component('DirectionalAverage', 'cf3.solver.actions.DirectionalAverage') dir_avg.direction = 1 dir_avg.field = mesh.geometry.turbulence_statistics
variable_name='SAViscosity').options().set( 'value', NU_wall) bc.add_constant_bc(region_name='bottom2', variable_name='SAViscosity').options().set( 'value', NU_wall) bc.add_constant_bc(region_name='bottom3', variable_name='SAViscosity').options().set('value', NU_in) bc.add_constant_bc(region_name='top', variable_name='SAViscosity').options().set('value', NU_in) write_manager = solver.add_unsteady_solver( 'cf3.solver.actions.TimeSeriesWriter') write_manager.interval = 1 writer = write_manager.create_component('VTKWriter', 'cf3.mesh.VTKXML.Writer') writer.mesh = mesh writer.fields = [ cf.URI('/NavierStokes/Domain/Mesh/geometry/navier_stokes_solution'), cf.URI('/NavierStokes/Domain/Mesh/geometry/spalart_allmaras_solution') ] writer.file = cf.URI('atest-flatplate2d-spalartallmaras-{iteration}.pvtu') # Time setup time = model.create_time() time.time_step = 0.1 time.end_time = 1.0 model.simulate() # print timings model.print_timing_tree()
# Setup a time series write final_end_time = 0.02 save_interval = 0.01 current_end_time = 0. iteration = 0 solver.TimeLoop.CouplingIteration.options.max_iter = 10 solver.create_fields() # must be after create_fields probe0 = solver.add_probe(name='Probe', parent=scalaradv, dict=mesh.children['cf3.mesh.LagrangeP0']) probe0.Log.variables = ['TemperatureGradient[0]', 'TemperatureGradient[1]'] probe0.coordinate = [0.5, 0.5] probe0.History.file = cf.URI('grad_t.tsv') solver.InitialConditions.execute() domain.write_mesh(cf.URI('atest-conjugate-heat-flatplate_output-initial.pvtu')) while current_end_time < final_end_time: current_end_time += save_interval time.options().set('end_time', current_end_time) model.simulate() domain.write_mesh( cf.URI('atest-cht-flatplate_10-iterations-' + str(iteration) + '.pvtu')) iteration += 1 if iteration == 1: solver.options().set('disabled_actions', ['InitialConditions']) # print timings
import coolfluid as cf import sys root = cf.Core.root() env = cf.Core.environment() env.options().set('assertion_backtrace', False) env.options().set('exception_backtrace', False) env.options().set('regist_signal_handlers', False) env.options().set('exception_log_level', 0) #env.options().set('log_level', 4) env.options().set('exception_outputs', False) model = root.create_component('model', 'cf3.solver.Model') model.create_domain() domain = model.get_child('Domain') generator = domain.create_component('generator', 'cf3.mesh.BlockMesh.ChannelGenerator') generator.options().set('mesh', cf.URI('//model/Domain/mesh')) generator.options().set('x_segments', 64) generator.execute() domain.create_component('writer', 'cf3.mesh.VTKXML.Writer') domain.write_mesh(cf.URI('utest-blockmesh-channelgenerator_output.pvtu'))
link_horizontal.translation_vector = [-1., 0.] link_horizontal.execute() make_par_data = root.create_component( 'MakeParData', 'cf3.solver.actions.ParallelDataToFields') make_par_data.mesh = mesh make_par_data.execute() # set time time = domain.create_component('Time', 'cf3.solver.Time') time.current_time = 2. time.time_step = 0.2 time.iteration = 10 # Write a restart file containing the data generated by MakeParData restart_file = cf.URI('restart-test.cf3restart') writer = domain.create_component('Writer', 'cf3.solver.actions.WriteRestartFile') writer.fields = [mesh.geometry.node_gids, mesh.elems_P0.element_gids] writer.file = restart_file writer.time = time writer.execute() # Store reference data and destroy the original ref_node_gids = copy_and_reset(mesh.geometry.node_gids, domain) ref_element_gids = copy_and_reset(mesh.elems_P0.element_gids, domain) time.current_time = 0. time.time_step = 1. time.iteration = 0 # Read back the data
bc_p_in = ns_solver.PressureBC.create_bc_action(region_name = 'left', builder_name = 'cf3.UFEM.BCDirichletFunction') bc_p_in.solving_for_difference = False bc_p_in.variable_name = 'Pressure' bc_p_in.field_tag = 'navier_stokes_p_solution' bc_p_in.value = ['20'] # Create the fields, to ensure LSS creation solver.create_fields() # LSS options lss = ns_solver.children.AuxiliaryLSS.create_lss() lss.SolutionStrategy.Parameters.preconditioner_type = 'ML' lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.default_values = 'SA' lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.aggregation_type = 'MIS' lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_type = 'symmetric block Gauss-Seidel' lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_sweeps = 2 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_pre_or_post = 'both' # Timestepping time = model.create_time() time.time_step = 0.1 time.end_time = 10.*time.time_step # Run the simulation model.simulate() # Print timings model.print_timing_tree() # Save result domain.write_mesh(cf.URI('chorin.msh'))
ns_solver = solver.add_unsteady_solver('cf3.UFEM.NavierStokes') ad_solver = solver.add_unsteady_solver('cf3.UFEM.adjoint.Adjoint') #ad_solver.ct = Ct0adj ad_solver.th = 0.4 # ad_solver.area = area ad_solver.turbulence = 0. # met ke model gradient1 = solver.add_unsteady_solver('cf3.UFEM.VelocityGradient') gradient1.options.gradient_tag = 'Adjvelocity_gradient' gradient1.options.velocity_variable = 'AdjVelocity' gradient1.options.velocity_tag = 'adjoint_solution' gradient1.options.gradient_name = 'U' mesh = domain.load_mesh(file=cf.URI('AlternatieveBuis.msh'), name='Mesh') ns_solver.regions = [mesh.topology.uri()] ad_solver.regions = [mesh.topology.uri()] satm.regions = [mesh.topology.uri()] # initial conditions solver.InitialConditions.navier_stokes_solution.Velocity = u_in solver.InitialConditions.density_ratio.density_ratio = 1. # This enables the body force solver.InitialConditions.adjoint_solution.AdjVelocity = u_in # viscositeit voor Spalart Allmaras NU_in = 0.001 solver.InitialConditions.spalart_allmaras_solution.SAViscosity = NU_in ic_k = solver.InitialConditions.create_initial_condition( builder_name='cf3.UFEM.InitialConditionFunction',
import coolfluid as cf import math ### Create new model specialized for SD model = cf.root.create_component('cylinder_2d','cf3.sdm.Model'); ### Load the mesh # mesh = model.domain.load_mesh(file = cf.URI('../../../resources/cylinder-quad-p2-16x4.msh'), name = 'cylinder2d'); mesh = model.domain.load_mesh(file = cf.URI('../../../resources/cylinder-quad-p2-32x8.msh'), name = 'cylinder2d'); # mesh = model.domain.load_mesh(file = cf.URI('../../../resources/cylinder-quad-p2-64x16.msh'), name = 'cylinder2d'); # mesh = model.domain.load_mesh(file = cf.URI('../../../resources/cylinder-quad-p2-128x32.msh'), name = 'cylinder2d'); ### Compute some physics variables gamma = 1.4 R = 287.05 M_inf = 0.38 p_inf = 1.0 rho_inf = 1.0 c_inf = math.sqrt(gamma*p_inf/rho_inf) u_inf = M_inf*c_inf rhoE_inf = p_inf/(gamma-1) + 0.5 * rho_inf * u_inf**2 #p_inf = (g-1) * ( rhoE - 0.5 * rho * ( u**2 ) ) ### Add the Partial Differential Equations to solve euler = model.add_pde(name='euler',type='cf3.sdm.equations.euler.Euler2D',shape_function='cf3.sdm.core.LegendreGaussEndP1') euler.gamma = gamma euler.R = R ### Add BC bc_wall = euler.add_bc( name='wall', type='cf3.sdm.equations.euler.BCMirror2D',
mesh_generator = domain.create_component("mesh_generator", "cf3.mesh.SimpleMeshGenerator") mesh_generator.options().set("mesh", mesh.uri()) mesh_generator.options().set("nb_cells", [1, 1]) mesh_generator.options().set("lengths", [1., 1.]) mesh_generator.options().set("offsets", [0., 0.]) mesh_generator.execute() polydisp.regions = [mesh.topology.interior.uri()] polydisp.children.ConcentrationSolver.LSS.SolutionStrategy.Parameters.linear_solver_type = 'Amesos' series_writer = solver.TimeLoop.create_component( 'TimeWriter', 'cf3.solver.actions.TimeSeriesWriter') writer = series_writer.create_component('Writer', 'cf3.mesh.VTKXML.Writer') writer.file = cf.URI('polydisperse-brownian-{iteration}.pvtu') writer.mesh = mesh series_writer.interval = write_interval solver.create_fields() writer.fields = [ mesh.geometry.particle_concentration_1.uri(), mesh.geometry.weighted_particle_volume_1.uri() ] # Time setup time = model.create_time() time.time_step = dt time.end_time = numsteps * dt model.simulate()
blocks.partition_blocks(nb_partitions=2, direction=0) blocks.partition_blocks(nb_partitions=2, direction=1) blocks.create_mesh(mesh.uri()) make_boundary_global = root.create_component( 'MakeBoundaryGlobal', 'cf3.mesh.actions.MakeBoundaryGlobal') make_boundary_global.mesh = mesh make_boundary_global.execute() wall_distance = root.create_component('WallDistance', 'cf3.mesh.actions.WallDistance') wall_distance.mesh = mesh wall_distance.regions = [mesh.topology.step] wall_distance.execute() domain.write_mesh(cf.URI('wall-distance-2dstep.pvtu')) mesh.delete_component() # 3D, triangle surface elements mesh = domain.load_mesh(file=cf.URI(sys.argv[1]), name='mesh') make_boundary_global.mesh = mesh make_boundary_global.execute() wall_distance.mesh = mesh wall_distance.regions = [mesh.topology.inner] wall_distance.execute() domain.write_mesh(cf.URI('wall-distance-sphere.pvtu')) mesh.delete_component() # 3D, quad surface elements
env.options().set('exception_backtrace', True) env.options().set('regist_signal_handlers', True) env.options().set('exception_log_level', 10) env.options().set('log_level', 3) env.options().set('exception_outputs', True) ############################ # Create simulation ############################ model = root.create_component('accousticpulse_2d','cf3.solver.Model'); solver = model.create_solver('cf3.sdm.SDSolver') physics = model.create_physics('cf3.physics.LinEuler.LinEuler2D') domain = model.create_domain() ### Load the mesh mesh = domain.load_mesh(file = coolfluid.URI('../../../resources/circle-quad-p1-32.msh'), name = 'circle'); gmsh_writer = model.create_component('load_writer','cf3.mesh.gmsh.Writer') gmsh_writer.options().set('mesh',mesh) gmsh_writer.options().set('file',coolfluid.URI('file:load.msh')) gmsh_writer.execute() ### Configure solver solver.options().set('mesh',mesh) solver.options().set('solution_vars','cf3.physics.LinEuler.Cons2D') solver.options().set('solution_order',4) solver.options().set('iterative_solver','cf3.sdm.ExplicitRungeKuttaLowStorage2') ### Configure timestepping solver.access_component('Time').options().set('time_step',1.); solver.access_component('Time').options().set('end_time',0.3);
env.options().configure_option('exception_aborts', True) env.options().configure_option('exception_outputs', True) env.options().configure_option('log_level', 4) env.options().configure_option('regist_signal_handlers', False) ### create model wizard = root.create_component('Wizard', 'cf3.RDM.SteadyExplicit') wizard.create_model(model_name='Model', physical_model='cf3.physics.Scalar.Scalar2D') model = root.get_child('Model') ### read mesh domain = model.get_child('Domain') domain.load_mesh(file=cf.URI('rotation-tg-p1.neu', cf.URI.Scheme.file), name='mesh') internal_regions = [cf.URI('//Model/Domain/mesh/topology/default_id1084')] # file:rotation-tg-p1.msh # file:rotation-tg-p2.msh # file:rotation-tg-p4.msh # file:rotation-qd-p1.msh # file:rotation-qd-p2.msh # file:rotation-qd-p3.msh # file:rotation-qd-p4.msh ### solver solver = model.get_child('RDSolver') solver.options().configure_option('update_vars', 'RotationAdv2D')
solver.create_fields() #initial condition for the velocity. Unset variables (i.e. the pressure) default to zero solver.InitialConditions.navier_stokes_solution.Velocity = u_in # Example of varying initial effective viscosity ic_visc = solver.InitialConditions.create_initial_condition( builder_name='cf3.UFEM.InitialConditionFunction', field_tag='navier_stokes_viscosity') ic_visc.variable_name = 'EffectiveViscosity' ic_visc.value = ['0.1 + 0.01*sin(2/pi*x)'] ic_visc.regions = [mesh.topology.uri()] ic_visc.execute() # Check initial conditions domain.write_mesh(cf.URI('laminar-channel-2d_output-init.pvtu')) # Physical constants physics.density = 1000. physics.dynamic_viscosity = 0.1 # Boundary conditions bc = ns_solver.BoundaryConditions bc.add_constant_bc(region_name='left', variable_name='Velocity').value = u_in bc.add_constant_bc(region_name='bottom', variable_name='Velocity').value = [0., 0.] bc.add_constant_bc(region_name='top', variable_name='Velocity').value = [0., 0.] bc.add_constant_bc(region_name='right', variable_name='Pressure').value = 0. # Setup a time series write
bc.add_constant_bc(region_name = 'bottom2', variable_name = 'Velocity').options().set('value', u_wall) bc.add_constant_component_bc(region_name = 'bottom3', variable_name = 'Velocity', component = 1).options().set('value', 0.) bc.add_constant_bc(region_name = 'outlet', variable_name = 'Pressure').options().set('value', 1.) bc.add_constant_bc(region_name = 'top', variable_name = 'Velocity').options().set('value', u_in) scalaradv.BoundaryConditions.add_constant_bc(region_name = 'inlet', variable_name = 'Scalar').options().set('value', phi_in) scalaradv.BoundaryConditions.add_constant_bc(region_name = 'bottom1', variable_name = 'Scalar').options().set('value', phi_wall) scalaradv.BoundaryConditions.add_constant_bc(region_name = 'bottom2', variable_name = 'Scalar').options().set('value', phi_in) scalaradv.BoundaryConditions.add_constant_bc(region_name = 'bottom3', variable_name = 'Scalar').options().set('value', phi_in) scalaradv.BoundaryConditions.add_constant_bc(region_name = 'top', variable_name = 'Scalar').options().set('value', phi_in) # Time setup time = model.create_time() time.options().set('time_step', 0.01) # Setup a time series write final_end_time = 0.1 save_interval = 0.01 current_end_time = 0. iteration = 0 while current_end_time < final_end_time: current_end_time += save_interval time.options().set('end_time', current_end_time) model.simulate() domain.write_mesh(cf.URI('atest-flatplate2d-scalar-' +str(iteration) + '.pvtu')) iteration += 1 if iteration == 1: solver.options().set('disabled_actions', ['InitialConditions']) # print timings model.print_timing_tree()
blocks.create_patch_nb_faces(name='left', nb_faces=1)[0] = [3, 0] blocks.create_mesh(mesh.uri()) time = domain.create_component('Time', 'cf3.solver.Time') time.time_step = 0.1 time.end_time = 1. series_writer = domain.create_component('SeriesWriter', 'cf3.solver.actions.TimeSeriesWriter') series_writer.time = time series_writer.interval = 5 writer = series_writer.create_component('Writer', 'cf3.mesh.cf3mesh.Writer') file_template = 'timeseries-{iteration}-{time}.cf3mesh' writer.file = cf.URI(file_template) writer.mesh = mesh advance_time = domain.create_component('AdvanceTime', 'cf3.solver.actions.AdvanceTime') advance_time.time = time # Write the time series for i in range(10): series_writer.execute() advance_time.execute() # Check that only the expected files exist, and if they do read and compare to reference mesh reader = domain.create_component('Reader', 'cf3.mesh.cf3mesh.Reader') meshdiff = domain.create_component('MeshDiff', 'cf3.mesh.actions.MeshDiff') meshdiff.left = mesh