Beispiel #1
0
parser.add_argument("--tp", type=float, help="Time at loading")
args = parser.parse_known_args()[0]

#
# Convert and read mesh and tags
#
meshname = args.mesh
filedir = os.path.dirname(__file__)

t0 = time()
infile = XDMFFile(MPI.COMM_WORLD,
                  os.path.join(filedir, "mesh/{}.xdmf".format(meshname)), "r")
mesh = infile.read_mesh(name="Grid")
mesh.topology.create_connectivity_all()
mt_cell = infile.read_meshtags(mesh, "Grid")
infile.close()

infile = XDMFFile(
    MPI.COMM_WORLD,
    os.path.join(filedir, "mesh/{}_triangle.xdmf".format(meshname)), "r")
mt_facet = infile.read_meshtags(mesh, "Grid")
infile.close()

# External boundary facets
ds = ufl.Measure("ds",
                 domain=mesh,
                 subdomain_data=mt_facet,
                 metadata={"quadrature_degree": 2})
dx = ufl.Measure("dx",
                 domain=mesh,
                 subdomain_data=mt_cell,
Beispiel #2
0
file.write_mesh(mesh)

# Step in time
t = 0.0

# Check if we are running on CI server and reduce run time
if "CI" in os.environ.keys() or "GITHUB_ACTIONS" in os.environ.keys():
    T = 3 * dt
else:
    T = 50 * dt

u.vector.copy(result=u0.vector)
u0.vector.ghostUpdate(addv=PETSc.InsertMode.INSERT,
                      mode=PETSc.ScatterMode.FORWARD)

while (t < T):
    t += dt
    r = solver.solve(problem, u.vector)
    print("Step, num iterations:", int(t / dt), r[0])
    u.vector.copy(result=u0.vector)
    file.write_function(u.sub(0), t)

file.close()

# Within the time stepping loop, the nonlinear problem is solved by
# calling :py:func:`solver.solve(problem,u.vector)<dolfinx.cpp.NewtonSolver.solve>`,
# with the new solution vector returned in :py:func:`u.vector<dolfinx.cpp.Function.vector>`.
# The solution vector associated with ``u`` is copied to ``u0`` at the
# end of each time step, and the ``c`` component of the solution
# (the first component of ``u``) is then written to file.
                      default=False)
    comp = parser.add_mutually_exclusive_group(required=False)
    comp.add_argument('--compare',
                      dest='compare',
                      action='store_true',
                      help="Compare with global solution",
                      default=False)
    time = parser.add_mutually_exclusive_group(required=False)
    time.add_argument('--timing',
                      dest='timing',
                      action='store_true',
                      help="List timings",
                      default=False)

    args = parser.parse_args()

    # Create results file
    outfile = XDMFFile(MPI.COMM_WORLD, "results/demo_contact_2D.xdmf", "w")

    # Run demo for input parameters
    demo_stacked_cubes(outfile,
                       theta=args.theta,
                       gmsh=args.gmsh,
                       quad=args.quad,
                       compare=args.compare,
                       res=args.res)

    outfile.close()
    if args.timing:
        list_timings(MPI.COMM_WORLD, [TimingType.wall])