5 from optparse
import OptionParser
7 env = cf.Core.environment()
10 env.assertion_throws =
False
11 env.assertion_backtrace =
False
12 env.exception_backtrace =
False
13 env.regist_signal_handlers =
False
26 def __init__(self, builder, dt, element, prefix):
34 if self.
model !=
None:
35 self.model.delete_component()
38 domain = self.model.Domain
39 blocks = domain.create_component(
'blocks',
'cf3.mesh.BlockMesh.BlockArrays')
40 points = blocks.create_points(dimensions = 2, nb_points = 6)
41 points[0] = [-0.5, -0.5]
42 points[1] = [0.5, -0.5]
43 points[2] = [-0.5, 0.]
45 points[4] = [-0.5,0.5]
46 points[5] = [0.5, 0.5]
48 block_nodes = blocks.create_blocks(2)
49 block_nodes[0] = [0, 1, 3, 2]
50 block_nodes[1] = [2, 3, 5, 4]
52 block_subdivs = blocks.create_block_subdivisions()
53 block_subdivs[0] = [segments, segments/2]
54 block_subdivs[1] = [segments, segments/2]
56 gradings = blocks.create_block_gradings()
57 gradings[0] = [1., 1., 1., 1.]
58 gradings[1] = [1., 1., 1., 1.]
60 left_patch = blocks.create_patch_nb_faces(name =
'left', nb_faces = 2)
61 left_patch[0] = [2, 0]
62 left_patch[1] = [4, 2]
64 bottom_patch = blocks.create_patch_nb_faces(name =
'bottom', nb_faces = 1)
65 bottom_patch[0] = [0, 1]
67 top_patch = blocks.create_patch_nb_faces(name =
'top', nb_faces = 1)
70 right_patch = blocks.create_patch_nb_faces(name =
'right', nb_faces = 2)
71 right_patch[0] = [1, 3]
72 right_patch[1] = [3, 5]
74 blocks.partition_blocks(nb_partitions = cf.Core.nb_procs(), direction = 0)
76 mesh = domain.create_component(
'Mesh',
'cf3.mesh.Mesh')
79 blocks.create_mesh(mesh.uri())
81 create_point_region = domain.create_component(
'CreatePointRegion',
'cf3.mesh.actions.AddPointRegion')
82 create_point_region.coordinates = [0., 0.]
83 create_point_region.region_name =
'center'
84 create_point_region.mesh = mesh
85 create_point_region.execute()
88 triangulator = domain.create_component(
'Triangulator',
'cf3.mesh.MeshTriangulator')
89 triangulator.mesh = mesh
90 triangulator.execute()
92 partitioner = domain.create_component(
'Partitioner',
'cf3.mesh.actions.PeriodicMeshPartitioner')
93 partitioner.mesh = mesh
95 link_horizontal = partitioner.create_link_periodic_nodes()
96 link_horizontal.source_region = mesh.topology.right
97 link_horizontal.destination_region = mesh.topology.left
98 link_horizontal.translation_vector = [-1., 0.]
100 link_vertical = partitioner.create_link_periodic_nodes()
101 link_vertical.source_region = mesh.topology.top
102 link_vertical.destination_region = mesh.topology.bottom
103 link_vertical.translation_vector = [0., -1.]
105 partitioner.execute()
107 domain.write_mesh(cf.URI(self.
prefix +
'.cf3mesh'))
110 reader = self.model.Domain.create_component(
'CF3MeshReader',
'cf3.mesh.cf3mesh.Reader')
111 reader.mesh = self.model.Domain.create_component(
'Mesh',
'cf3.mesh.Mesh')
112 reader.file = cf.URI(filename)
114 self.
mesh = reader.mesh
117 if self.
builder ==
'cf3.UFEM.NavierStokes':
118 ic_comp = self.solver.InitialConditions
119 u_tag =
'navier_stokes_solution'
120 p_tag =
'navier_stokes_solution'
122 ic_comp = self.solver.InitialConditions.NavierStokes
123 u_tag =
'navier_stokes_u_solution'
124 p_tag =
'navier_stokes_p_solution'
126 ic_u = ic_comp.create_initial_condition(builder_name =
'cf3.UFEM.InitialConditionFunction', field_tag = u_tag)
127 ic_u.variable_name =
'Velocity'
128 ic_u.regions = [self.mesh.topology.interior.uri()]
129 ic_u.value = [
'{Ua} - cos(pi/{D}*x)*sin(pi/{D}*y)'.format(Ua = self.
Ua, D = self.
D),
'{Va} + sin(pi/{D}*x)*cos(pi/{D}*y)'.format(Va = self.
Va, D = self.
D)]
131 ic_p = ic_comp.create_initial_condition(builder_name =
'cf3.UFEM.InitialConditionFunction', field_tag = p_tag)
132 ic_p.regions = [self.mesh.topology.interior.uri()]
133 ic_p.variable_name =
'Pressure'
134 ic_p.value = [
'-0.25*(cos(2*pi/{D}*x) + cos(2*pi/{D}*y))'.format(D = self.
D)]
137 if self.
builder ==
'cf3.UFEM.NavierStokes':
138 reader = self.solver.InitialConditions.create_component(
'Reader',
'cf3.solver.actions.ReadRestartFile')
140 reader = self.solver.InitialConditions.Restarts.create_component(
'Reader',
'cf3.solver.actions.ReadRestartFile')
141 reader.mesh = self.
mesh
142 reader.file = cf.URI(filename)
145 if self.
model !=
None:
146 self.model.delete_component()
150 domain = model.create_domain()
151 physics = model.create_physics(
'cf3.UFEM.NavierStokesPhysics')
152 self.
solver = model.create_solver(
'cf3.UFEM.Solver')
153 self.
ns_solver = self.solver.add_unsteady_solver(builder)
155 self.restart_writer.Writer.file = cf.URI(self.
prefix+
'-{iteration}.cf3restart')
159 physics.dynamic_viscosity = 0.001
164 bc.regions = [self.mesh.topology.uri()]
165 nu = self.model.NavierStokesPhysics.kinematic_viscosity
166 bc.add_function_bc(region_name =
'center', variable_name = var_name).value = [
'-0.25 * (cos(2*pi/{D}*(x - {Ua}*(t+{dt}))) + cos(2*pi/{D}*(y - {Va}*(t+{dt})))) * exp(-4*{nu}*pi^2/{D}^2*(t+{dt})) '.format(D = self.
D, nu = nu, Ua = self.
Ua, Va = self.
Va, dt = self.
dt)]
174 self.ns_solver.regions = [mesh.topology.interior.uri()]
175 self.ns_solver.options.theta = theta
178 series_writer = self.solver.TimeLoop.create_component(
'TimeWriter',
'cf3.solver.actions.TimeSeriesWriter')
179 writer = series_writer.create_component(
'Writer',
'cf3.mesh.VTKXML.Writer')
180 writer.file = cf.URI(self.
prefix+
'-{iteration}.pvtu')
181 writer.mesh = self.
mesh
183 if self.
builder ==
'cf3.UFEM.NavierStokes':
185 self.solver.create_fields()
186 writer.fields = [mesh.geometry.navier_stokes_solution.uri()]
187 lss = self.ns_solver.LSS
188 lss.SolutionStrategy.Parameters.preconditioner_type =
'ML'
189 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.convergence_tolerance = 1e-14
190 lss.SolutionStrategy.Parameters.LinearSolverTypes.Belos.SolverTypes.BlockGMRES.maximum_iterations = 2000
191 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.default_values =
'NSSA'
192 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.eigen_analysis_type =
'Anorm'
193 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.add_parameter(name =
'PDE equations', value =3)
194 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.aggregation_type =
'Uncoupled-MIS'
195 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_type =
'Chebyshev'
196 lss.SolutionStrategy.Parameters.PreconditionerTypes.ML.MLSettings.smoother_sweeps = 3
199 self.ns_solver.PressureLSS.LSS.SolutionStrategy.Parameters.linear_solver_type =
'Amesos'
200 self.ns_solver.VelocityLSS.LSS.SolutionStrategy.Parameters.linear_solver_type =
'Amesos'
201 self.ns_solver.PressureLSS.LSS.SolutionStrategy.print_settings =
False
202 self.ns_solver.VelocityLSS.LSS.SolutionStrategy.print_settings =
False
206 self.solver.create_fields()
207 writer.fields = [mesh.geometry.navier_stokes_p_solution.uri(), mesh.geometry.navier_stokes_u_solution.uri()]
209 def iterate(self, numsteps, save_interval = 1):
211 self.restart_writer.interval = save_interval
214 time = self.model.create_time()
215 time.time_step = tstep
216 if self.
builder ==
'cf3.UFEM.NavierStokes':
217 time.end_time = numsteps*tstep
218 self.model.simulate()
221 while time.end_time < numsteps*tstep:
222 time.end_time += save_interval*tstep
223 self.model.simulate()
224 self.solver.InitialConditions.options.disabled_actions = [
'NavierStokes',
'linearized_velocity']
225 self.model.print_timing_tree()
228 self.restart_writer.interval = save_interval
231 time = self.model.create_time()
232 time.end_time = end_time
233 self.model.simulate()
234 self.model.print_timing_tree()
242 tg_impl =
TaylorGreen(builder =
'cf3.UFEM.NavierStokes', dt = dt, element=elem, prefix=
'restart-implicit-full')
243 tg_impl.create_mesh(segs)
244 tg_impl.setup(0.3, 0.2, D=0.5, theta=theta)
246 tg_impl.iterate(10, 5)
249 tg_impl_restart =
TaylorGreen(builder =
'cf3.UFEM.NavierStokes', dt = dt, element=elem, prefix=
'restart-implicit-restarted')
250 tg_impl_restart.read_mesh(tg_impl.prefix +
'.cf3mesh')
251 tg_impl_restart.setup(0.3, 0.2, D=0.5, theta=theta)
252 tg_impl_restart.set_restart(tg_impl.prefix+
'-5.cf3restart')
253 tg_impl_restart.iterate_restart(10.*dt, 5)
255 root = cf.Core.root()
256 meshdiff = root.create_component(
'MeshDiff',
'cf3.mesh.actions.MeshDiff')
257 meshdiff.left = tg_impl.mesh
258 meshdiff.right = tg_impl_restart.mesh
259 meshdiff.max_ulps = 1000000000
261 if not meshdiff.properties()[
'mesh_equal']:
262 raise Exception(
'Bad restart for implicit solve')
265 tg_semi_impl =
TaylorGreen(builder =
'cf3.UFEM.NavierStokesSemiImplicit', dt = dt, element=elem, prefix=
'restart-semi-full')
266 tg_semi_impl.create_mesh(segs)
267 tg_semi_impl.setup(0.3, 0.2, D=0.5, theta=theta)
268 tg_semi_impl.setup_ic()
269 tg_semi_impl.iterate(10, 5)
272 tg_semi_impl_restart =
TaylorGreen(builder =
'cf3.UFEM.NavierStokesSemiImplicit', dt = dt, element=elem, prefix=
'restart-semi-restarted')
273 tg_semi_impl_restart.read_mesh(tg_semi_impl.prefix +
'.cf3mesh')
274 tg_semi_impl_restart.setup(0.3, 0.2, D=0.5, theta=theta)
275 tg_semi_impl_restart.set_restart(tg_semi_impl.prefix+
'-5.cf3restart')
276 tg_semi_impl_restart.iterate_restart(10.*dt, 5)
278 meshdiff.max_ulps = 1000000000
279 meshdiff.left = tg_semi_impl.mesh
280 meshdiff.right = tg_semi_impl_restart.mesh
282 if not meshdiff.properties()[
'mesh_equal']:
283 raise Exception(
'Bad restart for semi-implicit solve')
def create_mesh(self, segments)
def setup_model(self, builder)
boost::python::object create_component(ComponentWrapper &self, const std::string &name, const std::string &builder_name)
def read_mesh(self, filename)
def set_restart(self, filename)
def setup(self, Ua, Va, D, theta)
def __init__(self, builder, dt, element, prefix)