Hello all,
I am working with FEniCS 2019.2.dev0 version coupled with TFEL//MFront.
I am trying to create a save/checkpoint where I could restart the solve process from.
My save variables are in Quadrature space, hence I cannot directly use write_checkpoint().
I can write out the numpy array associated with the variable (using np.hstack and allgather from MPIRUN - writing out text in parallel - #6 by dokken) :
(In the following minimal example, I am using DG1 space, but in reality I am using quadrature for my problem)
Code to write numy array associated with variable
from dolfin import *
import numpy as np
parameters['reorder_dofs_serial'] = False
mesh = UnitCubeMesh.create(8, 8, 8, CellType.Type.tetrahedron)
ScalarSpaceDG = FunctionSpace(mesh, 'DG', 1)
expres = Expression('(x[0]*x[0]+x[1]*x[1]+x[2]*x[2])',degree=1)
Test = project(expres,ScalarSpaceDG)
DATA = Test.vector().vec().getArray()
np.savetxt("Output.txt", DATA, fmt='%e')
I want to read the variable back from the text file into the simulation, while using “mpirun”
from dolfin import *
import numpy as np
parameters['reorder_dofs_serial'] = False
comm = MPI.comm_world
MPI.comm_world.barrier()
if MPI.comm_world.rank ==0:
DATA = np.loadtxt("Output.txt", dtype=float)
MPI.comm_world.barrier()
mesh = UnitCubeMesh.create(8, 8, 8, CellType.Type.tetrahedron)
ScalarSpaceDG = FunctionSpace(mesh, 'DG', 1)
Test = Function(ScalarSpaceDG)
Test.vector().vec().setArray(DATA)
The above code runs well in serial but using mpirun, I have problems with the array of each processes.
How can I read a numpy array and assign it to a functional variable, while in mpirun?