32 int main(
int argc,
char *argv[])
34 MPI_Init(&argc, &argv);
38 MPI_Comm_size(MPI_COMM_WORLD, &num_procs);
39 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
44 const char *source_mesh_file =
"../../data/inline-tri.mesh";
45 const char *destination_mesh_file =
"../../data/inline-quad.mesh";
47 int src_n_refinements = 0;
48 int dest_n_refinements = 0;
49 int source_fe_order = 1;
50 int dest_fe_order = 1;
51 bool visualization =
true;
52 bool use_vector_fe =
false;
54 bool assemble_mass_and_coupling_together =
true;
57 args.
AddOption(&source_mesh_file,
"-s",
"--source_mesh",
58 "Mesh file to use for src.");
59 args.
AddOption(&destination_mesh_file,
"-d",
"--destination_mesh",
60 "Mesh file to use for dest.");
61 args.
AddOption(&src_n_refinements,
"-sr",
"--source_refinements",
62 "Number of src refinements");
63 args.
AddOption(&dest_n_refinements,
"-dr",
"--dest_refinements",
64 "Number of dest refinements");
65 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
67 "Enable or disable GLVis visualization.");
68 args.
AddOption(&source_fe_order,
"-so",
"--source_fe_order",
69 "Order of the src finite elements");
70 args.
AddOption(&dest_fe_order,
"-do",
"--dest_fe_order",
71 "Order of the dest finite elements");
72 args.
AddOption(&verbose,
"-verb",
"--verbose",
"--no-verb",
"--no-verbose",
73 "Enable/Disable verbose output");
74 args.
AddOption(&use_vector_fe,
"-vfe",
"--use_vector_fe",
"-no-vfe",
75 "--no-vector_fe",
"Use vector finite elements (Experimental)");
76 args.
AddOption(&assemble_mass_and_coupling_together,
"-act",
77 "--assemble_mass_and_coupling_together",
"-no-act",
78 "--no-assemble_mass_and_coupling_together",
79 "Assemble mass and coupling operators together (better for non-affine elements)");
83 shared_ptr<Mesh> src_mesh, dest_mesh;
87 imesh.open(destination_mesh_file);
90 dest_mesh = make_shared<Mesh>(imesh, 1, 1);
96 mfem::err <<
"WARNING: Destination mesh file not found: "
97 << destination_mesh_file <<
"\n"
98 <<
"Using default 2D quad mesh.";
103 const int dim = dest_mesh->Dimension();
107 Vector box_min(dim), box_max(dim), range(dim);
108 dest_mesh->GetBoundingBox(box_min, box_max);
112 imesh.open(source_mesh_file);
116 src_mesh = make_shared<Mesh>(imesh, 1, 1);
122 mfem::err <<
"WARNING: Source mesh file not found: " << source_mesh_file
124 <<
"Using default box mesh.\n";
137 for (
int i = 0; i < src_mesh->GetNV(); ++i)
139 double *v = src_mesh->GetVertex(i);
141 for (
int d = 0; d <
dim; ++d)
148 for (
int i = 0; i < src_n_refinements; ++i)
150 src_mesh->UniformRefinement();
153 for (
int i = 0; i < dest_n_refinements; ++i)
155 dest_mesh->UniformRefinement();
158 auto p_src_mesh = make_shared<ParMesh>(MPI_COMM_WORLD, *src_mesh);
159 auto p_dest_mesh = make_shared<ParMesh>(MPI_COMM_WORLD, *dest_mesh);
161 shared_ptr<FiniteElementCollection> src_fe_coll, dest_fe_coll;
166 make_shared<RT_FECollection>(source_fe_order, src_mesh->Dimension());
168 make_shared<RT_FECollection>(dest_fe_order, dest_mesh->Dimension());
173 make_shared<L2_FECollection>(source_fe_order, src_mesh->Dimension());
175 make_shared<L2_FECollection>(dest_fe_order, dest_mesh->Dimension());
179 make_shared<ParFiniteElementSpace>(p_src_mesh.get(), src_fe_coll.get());
182 make_shared<ParFiniteElementSpace>(p_dest_mesh.get(), dest_fe_coll.get());
194 src_fun.ProjectCoefficient(vector_coeff);
199 src_fun.ProjectCoefficient(coeff);
209 assemble_mass_and_coupling_together);
221 if (assembler.
Transfer(src_fun, dest_fun))
231 src_err = src_fun.ComputeL2Error(vector_coeff);
232 dest_err = dest_fun.ComputeL2Error(vector_coeff);
236 src_err = src_fun.ComputeL2Error(coeff);
237 dest_err = dest_fun.ComputeL2Error(coeff);
242 mfem::out <<
"l2 error: src: " << src_err <<
", dest: " << dest_err
246 plot(*p_src_mesh, src_fun,
"source");
247 plot(*p_dest_mesh, dest_fun,
"destination");
252 mfem::out <<
"No intersection no transfer!" << std::endl;
257 return MPI_Finalize();
void SetVerbose(const bool verbose)
Expose process details with verbose output.
void destination_transform(const Vector &x, Vector &x_new)
This class implements the parallel variational transfer between finite element spaces. Variational transfer has been shown to have better approximation properties than standard interpolation. This facilities can be used for supporting applications which require the handling of non matching meshes. For instance: General multi-physics problems, fluid structure interaction, or even visualization of average quantities within subvolumes. This particular code is also used with LLNL for large scale multilevel Monte Carlo simulations. This algorithm allows to perform quadrature in the intersection of elements of two separate, unrelated, and arbitrarily distributed meshes. It generates quadrature rules in the intersection which allows us to integrate with to machine precision using the mfem::MortarIntegrator interface. See https://doi.org/10.1137/15M1008361 for and in-depth explanation. At this time curved elements are not supported. Convex non-affine elements are partially supported, however, high order (>3) finite element discretizations or nonlinear geometric transformations might generate undesired oscillations. Discontinuous fields in general can only be mapped to order 0 destination fields. For such cases localized versions of the projection will have to be developed.
bool Transfer(const ParGridFunction &src_fun, ParGridFunction &dest_fun)
transfer a function from source to destination. if the transfer is to be performed multiple times use...
void check_options(mfem::OptionsParser &args)
void InitTransfer(int argc, char *argv[])
Initializes the par_moonolith library. It also calls MPI_Init.
void AddMortarIntegrator(const std::shared_ptr< MortarIntegrator > &integrator)
This method must be called before Assemble or Transfer. It will assemble the operator in all intersec...
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
virtual void Update()
Transform by the Space UpdateMatrix (e.g., on Mesh change).
A general vector function coefficient.
void plot(mfem::Mesh &mesh, mfem::GridFunction &x, std::string title)
OutStream err(std::cerr)
Global stream used by the library for standard error output. Initially it uses the same std::streambu...
void AddOption(bool *var, const char *enable_short_name, const char *enable_long_name, const char *disable_short_name, const char *disable_long_name, const char *description, bool required=false)
Add a boolean option and set 'var' to receive the value. Enable/disable tags are used to set the bool...
double example_fun(const mfem::Vector &x)
void vector_fun(const mfem::Vector &x, mfem::Vector &f)
A general function coefficient.
void SetAssembleMassAndCouplingTogether(const bool value)
Control if the Mass matrix is computed together with the coupling operator every time.
Class for parallel grid function.
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
int FinalizeTransfer()
Finalize the par_moonolith library.