45 for (
int d = 0; d <
dim; d++) { res += x(d) * x(d); }
52 for (
int i = 1; i < F.
Size(); i++) { F(i) = (i+1)*pow(-1, i)*F(0); }
55 int main (
int argc,
char *argv[])
58 const char *src_mesh_file =
"../meshing/square01.mesh";
59 const char *tar_mesh_file =
"../../data/inline-tri.mesh";
60 const char *src_sltn_file =
"must_be_provided_by_the_user.gf";
61 int src_fieldtype = 0;
63 int src_gf_ordering = 0;
67 bool visualization =
true;
71 args.
AddOption(&src_mesh_file,
"-m1",
"--mesh1",
72 "Mesh file for the starting solution.");
73 args.
AddOption(&tar_mesh_file,
"-m2",
"--mesh2",
74 "Mesh file for interpolation.");
75 args.
AddOption(&src_sltn_file,
"-s1",
"--solution1",
76 "(optional) GridFunction file compatible with src_mesh_file." 77 "Set src_fieldtype to -1 if this option is used.");
78 args.
AddOption(&src_fieldtype,
"-fts",
"--field-type-src",
79 "Source GridFunction type:" 80 "0 - H1 (default), 1 - L2, 2 - H(div), 3 - H(curl).");
81 args.
AddOption(&src_ncomp,
"-nc",
"--ncomp",
82 "Number of components for H1 or L2 GridFunctions.");
83 args.
AddOption(&src_gf_ordering,
"-gfo",
"--gfo",
84 "Node ordering: 0 (byNodes) or 1 (byVDim)");
85 args.
AddOption(&ref_levels,
"-r",
"--refine",
86 "Number of refinements of the interpolation mesh.");
87 args.
AddOption(&fieldtype,
"-ft",
"--field-type",
88 "Target GridFunction type: -1 - source GridFunction type (default)," 89 "0 - H1, 1 - L2, 2 - H(div), 3 - H(curl).");
91 "Order of the interpolated solution.");
92 args.
AddOption(&visualization,
"-vis",
"--visualization",
"-no-vis",
94 "Enable or disable GLVis visualization.");
104 Mesh mesh_1(src_mesh_file, 1, 1,
false);
105 Mesh mesh_2(tar_mesh_file, 1, 1,
false);
107 MFEM_ASSERT(
dim == mesh_2.
Dimension(),
"Source and target meshes " 108 "must be in the same dimension.");
109 MFEM_VERIFY(
dim > 1,
"GSLIB requires a 2D or a 3D mesh" );
111 for (
int lev = 0; lev < ref_levels; lev++)
118 const int mesh_poly_deg =
119 mesh_2.
GetNodes()->FESpace()->GetElementOrder(0);
120 cout <<
"Source mesh curvature: " 121 << mesh_1.
GetNodes()->OwnFEC()->Name() << endl
122 <<
"Target mesh curvature: " 123 << mesh_2.
GetNodes()->OwnFEC()->Name() << endl;
125 int src_vdim = src_ncomp;
129 if (src_fieldtype < 0)
131 ifstream mat_stream_1(src_sltn_file);
135 else if (src_fieldtype == 0)
139 else if (src_fieldtype == 1)
143 else if (src_fieldtype == 2)
149 else if (src_fieldtype == 3)
157 MFEM_ABORT(
"Invalid FECollection type.");
160 if (src_fieldtype > -1)
162 MFEM_VERIFY(src_gf_ordering >= 0 && src_gf_ordering <= 1,
163 " Source grid function ordering must be 0 (byNodes)" 181 cout <<
"Unable to connect to GLVis server at " 187 sout1 <<
"solution\n" << mesh_1 << *func_source
188 <<
"window_title 'Source mesh and solution'" 189 <<
"window_geometry 0 0 600 600";
190 if (
dim == 2) { sout1 <<
"keys RmjAc"; }
191 if (
dim == 3) { sout1 <<
"keys mA\n"; }
200 "are not currently supported.");
204 std::cout <<
"Source FE collection: " << fec_in->
Name() << std::endl;
206 if (src_fieldtype < 0)
212 if (fec_h1) { src_fieldtype = 0; }
213 else if (fec_l2) { src_fieldtype = 1; }
214 else if (fec_rt) { src_fieldtype = 2; }
215 else if (fec_nd) { src_fieldtype = 3; }
216 else { MFEM_ABORT(
"GridFunction type not supported yet."); }
218 if (fieldtype < 0) { fieldtype = src_fieldtype; }
224 int tar_vdim = src_vdim;
228 tar_vdim = (src_fieldtype > 1) ?
dim : src_vdim;
230 else if (fieldtype == 1)
233 tar_vdim = (src_fieldtype > 1) ?
dim : src_vdim;
235 else if (fieldtype == 2)
239 MFEM_VERIFY(src_fieldtype > 1,
"Cannot interpolate a scalar " 240 "grid function to a vector");
243 else if (fieldtype == 3)
247 MFEM_VERIFY(src_fieldtype > 1,
"Cannot interpolate a scalar " 248 "grid function to a vector");
252 MFEM_ABORT(
"GridFunction type not supported.");
254 std::cout <<
"Target FE collection: " << tar_fec->
Name() << std::endl;
259 const int NE = mesh_2.
GetNE(),
261 tar_ncomp = func_target.VectorDim();
266 if (fieldtype == 0 && order == mesh_poly_deg)
269 point_ordering = mesh_2.
GetNodes()->FESpace()->GetOrdering();
274 for (
int i = 0; i < NE; i++)
283 rowy(vxyz.
GetData() + i*nsp + NE*nsp, nsp),
295 const int nodes_cnt = vxyz.
Size() /
dim;
298 Vector interp_vals(nodes_cnt*tar_ncomp);
300 finder.
Setup(mesh_1);
301 finder.
Interpolate(vxyz, *func_source, interp_vals, point_ordering);
306 if ((fieldtype == 0 && order == mesh_poly_deg) || fieldtype == 1)
308 func_target = interp_vals;
314 Vector elem_dof_vals(nsp*tar_ncomp);
316 for (
int i = 0; i < mesh_2.
GetNE(); i++)
320 for (
int j = 0; j < nsp; j++)
322 for (
int d = 0; d < tar_ncomp; d++)
326 d*nsp*NE + i*nsp + j : i*nsp*
dim + d + j*
dim;
327 elem_dof_vals(j + d*nsp) = interp_vals(idx);
330 func_target.SetSubVector(vdofs, elem_dof_vals);
338 Vector elem_dof_vals(nsp*tar_ncomp);
340 for (
int i = 0; i < mesh_2.
GetNE(); i++)
344 for (
int j = 0; j < nsp; j++)
346 for (
int d = 0; d < tar_ncomp; d++)
350 d*nsp*NE + i*nsp + j : i*nsp*
dim + d + j*
dim;
351 elem_dof_vals(j*tar_ncomp+d) = interp_vals(idx);
357 func_target.SetSubVector(vdofs, vals);
370 cout <<
"Unable to connect to GLVis server at " 376 sout1 <<
"solution\n" << mesh_2 << func_target
377 <<
"window_title 'Target mesh and solution'" 378 <<
"window_geometry 600 0 600 600";
379 if (
dim == 2) { sout1 <<
"keys RmjAc"; }
380 if (
dim == 3) { sout1 <<
"keys mA\n"; }
386 ostringstream rho_name;
387 rho_name <<
"interpolated.gf";
388 ofstream rho_ofs(rho_name.str().c_str());
389 rho_ofs.precision(8);
390 func_target.Save(rho_ofs);
Abstract class for all finite elements.
virtual void Interpolate(const GridFunction &field_in, Vector &field_out)
int GetNPoints() const
Returns the number of the points in the integration rule.
Class for an integration rule - an Array of IntegrationPoint.
const FiniteElementSpace * GetNodalFESpace() const
Class for grid function - Vector with associated FE space.
virtual void ProjectFromNodes(Vector &vc, ElementTransformation &Trans, Vector &dofs) const
Given a vector of values at the finite element nodes and a transformation, compute its projection (ap...
void PrintOptions(std::ostream &out) const
Print the options.
void SetSize(int s)
Resize the vector to size s.
void PrintUsage(std::ostream &out) const
Print the usage message.
int Size() const
Returns the size of the vector.
Data type dense matrix using column-major storage.
bool Good() const
Return true if the command line options were parsed successfully.
virtual const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
int GetNumGeometries(int dim) const
Return the number of geometries of the given dimension present in the mesh.
int close()
Close the socketstream.
Geometry::Type GetGeomType() const
Returns the Geometry::Type of the reference element.
double scalar_func(const Vector &x)
void Parse()
Parse the command-line options. Note that this function expects all the options provided through the ...
const FiniteElementCollection * FEColl() const
void UniformRefinement(int i, const DSTable &, int *, int *, int *)
virtual void SetCurvature(int order, bool discont=false, int space_dim=-1, int ordering=1)
Set the curvature of the mesh nodes using the given polynomial degree.
void Setup(Mesh &m, const double bb_t=0.1, const double newt_tol=1.0e-12, const int npt_max=256)
virtual const char * Name() const
int main(int argc, char *argv[])
FiniteElementSpace * FESpace()
double * GetData() const
Return a pointer to the beginning of the Vector data.
Arbitrary order H(div)-conforming Raviart-Thomas finite elements.
int GetVDim() const
Returns vector dimension.
A general vector function coefficient.
DofTransformation * GetElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom in array dofs for i'th element.
double p(const Vector &x, double t)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
void GetRow(int r, Vector &row) const
Collection of finite elements from the same family in multiple dimensions. This class is used to matc...
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...
void SetDataAndSize(double *d, int s)
Set the Vector data and size.
int GetNE() const
Returns number of elements.
void vector_func(const Vector &p, Vector &F)
Ordering::Type GetOrdering() const
Return the ordering method.
virtual void ProjectCoefficient(Coefficient &coeff)
Project coeff Coefficient to this GridFunction. The projection computation depends on the choice of t...
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
int Size() const
Return the logical size of the array.
Arbitrary order H(curl)-conforming Nedelec finite elements.
FindPointsGSLIB can robustly evaluate a GridFunction on an arbitrary collection of points...
Arbitrary order H1-conforming (continuous) finite elements.
void GetNodes(Vector &node_coord) const
const IntegrationRule & GetNodes() const
Get a const reference to the nodes of the element.
Arbitrary order "L2-conforming" discontinuous finite elements.
ElementTransformation * GetElementTransformation(int i) const
Returns ElementTransformation for the i-th element.