15 #include "../general/osockstream.hpp"
32 #if defined(MFEM_DEBUG) || defined(MFEM_USE_MPI)
42 MFEM_VERIFY(m != NULL,
"No mesh has been given to the AdaptivityEvaluator.");
59 MFEM_VERIFY(oper != NULL,
60 "No FE space has been given to the AdaptivityEvaluator.");
61 ode_solver.
Init(*oper);
65 for (
int i = 0; i < m->
GetNE(); i++)
70 const int s = u.FESpace()->GetVSize() / 2;
71 for (
int i = 0; i < s; i++)
73 const double vel = u(i) * u(i) + u(i+s) * u(i+s);
74 v_max = std::max(v_max, vel);
81 v_max = std::sqrt(v_max);
82 double dt = 0.5 * min_h / v_max;
87 MPI_Allreduce(&dt, &glob_dt, 1, MPI_DOUBLE, MPI_MIN,
pfes->
GetComm());
92 bool last_step =
false;
93 for (
int ti = 1; !last_step; ti++)
95 if (t + glob_dt >= 1.0)
100 mfem::out <<
"Remap took " << ti <<
" steps." << std::endl;
106 ode_solver.
Step(new_field, t, glob_dt);
110 const double minv = field0.
Min(), maxv = field0.
Max();
111 for (
int i = 0; i < new_field.
Size(); i++)
113 if (new_field(i) < minv) { new_field(i) = minv; }
114 if (new_field(i) > maxv) { new_field(i) = maxv; }
127 x0(x_start), x_now(*fes.GetMesh()->GetNodes()),
128 u(vel), u_coeff(&u), M(&fes), K(&fes)
148 K.BilinearForm::operator=(0.0);
152 M.BilinearForm::operator=(0.0);
163 lin_solver.
Mult(rhs, di_dt);
171 x0(x_start), x_now(*pfes.GetMesh()->GetNodes()),
172 u(vel), u_coeff(&u), M(&pfes), K(&pfes)
192 K.BilinearForm::operator=(0.0);
196 M.BilinearForm::operator=(0.0);
207 lin_solver.SetPreconditioner(prec);
208 lin_solver.SetOperator(*Mh);
209 lin_solver.SetRelTol(1e-8);
210 lin_solver.SetAbsTol(0.0);
211 lin_solver.SetMaxIter(100);
212 lin_solver.SetPrintLevel(0);
213 lin_solver.Mult(*RHS, X);
225 double energy_in = 0.0;
228 MFEM_VERIFY(!(parallel && p_nlf == NULL),
"Invalid Operator subclass.");
235 const bool serial = !parallel;
237 MFEM_VERIFY(!(serial && nlf == NULL),
"Invalid Operator subclass.");
249 DenseMatrix Jpr(dim), dshape(dof, dim), pos(dof, dim);
253 bool x_out_ok =
false;
254 double scale = 1.0, energy_out = 0.0;
255 double norm0 =
Norm(
r);
258 for (
int i = 0; i < 12; i++)
260 add(x, -scale,
c, x_out);
265 if (!cP) {x_out_loc.SetData(x_out.GetData());}
266 else {cP->
Mult(x_out,x_out_loc);}
277 if (energy_out > 1.2*energy_in || std::isnan(energy_out) != 0)
280 {
mfem::out <<
"Scale = " << scale <<
" Increasing energy.\n"; }
281 scale *= 0.5;
continue;
285 for (
int i = 0; i < NE; i++)
288 x_out_loc.GetSubVector(xdofs, posV);
289 for (
int j = 0; j < nsp; j++)
293 if (Jpr.Det() <= 0.0) { jac_ok = 0;
goto break2; }
297 int jac_ok_all = jac_ok;
301 MPI_Allreduce(&jac_ok, &jac_ok_all, 1, MPI_INT, MPI_LAND,
309 {
mfem::out <<
"Scale = " << scale <<
" Neg det(J) found.\n"; }
310 scale *= 0.5;
continue;
314 if (have_b) {
r -=
b; }
315 double norm =
Norm(
r);
317 if (norm > 1.2*norm0)
320 {
mfem::out <<
"Scale = " << scale <<
" Norm increased.\n"; }
321 scale *= 0.5;
continue;
323 else { x_out_ok =
true;
break; }
329 << (energy_in - energy_out) / energy_in * 100.0
330 <<
"% with " << scale <<
" scaling.\n";
333 if (x_out_ok ==
false) { scale = 0.0; }
359 double energy_in = 0.0;
362 MFEM_VERIFY(!(parallel && p_nlf == NULL),
"Invalid Operator subclass.");
369 const bool serial = !parallel;
371 MFEM_VERIFY(!(serial && nlf == NULL),
"Invalid Operator subclass.");
381 DenseMatrix Jpr(dim), dshape(dof, dim), pos(dof, dim);
386 for (
int i = 0; i < NE; i++)
389 x_loc.GetSubVector(xdofs, posV);
391 for (
int j = 0; j < nsp; j++)
395 min_detJ = std::min(min_detJ, Jpr.Det());
398 double min_detJ_all = min_detJ;
402 MPI_Allreduce(&min_detJ, &min_detJ_all, 1, MPI_DOUBLE, MPI_MIN,
408 mfem::out <<
"Minimum det(J) = " << min_detJ_all <<
'\n';
412 bool x_out_ok =
false;
413 double scale = 1.0, energy_out = 0.0;
415 for (
int i = 0; i < 7; i++)
417 add(x, -scale,
c, x_out);
421 if (!cP) {x_loc.SetData(x_out.GetData());}
422 else {cP->
Mult(x_out,x_loc);}
433 if (energy_out > energy_in || std::isnan(energy_out) != 0)
437 else { x_out_ok =
true;
break; }
443 << (energy_in - energy_out) / energy_in * 100.0
444 <<
"% with " << scale <<
" scaling.\n";
447 if (x_out_ok ==
false) {
return 0.0; }
475 char *title,
int position)
484 sock.
open(
"localhost", 19916);
485 sock <<
"solution\n";
491 sock <<
"window_title '"<< title <<
"'\n"
492 <<
"window_geometry "
493 << position <<
" " << 0 <<
" " << 600 <<
" " << 600 <<
"\n"
503 char *title,
int position)
510 sock <<
"solution\n";
514 sock <<
"window_title '"<< title <<
"'\n"
515 <<
"window_geometry "
516 << position <<
" " << 0 <<
" " << 600 <<
" " << 600 <<
"\n"
int GetNPoints() const
Returns the number of the points in the integration rule.
VectorGridFunctionCoefficient u_coeff
void vis_tmop_metric_p(int order, TMOP_QualityMetric &qm, const TargetConstructor &tc, ParMesh &pmesh, char *title, int position)
virtual double GetTime() const
Read the currently set time.
int GetVSize() const
Return the number of vector dofs, i.e. GetNDofs() x GetVDim().
virtual void Print(std::ostream &out=mfem::out) const
Conjugate gradient method.
int GetDim() const
Returns the reference space dimension for the finite element.
Class for grid function - Vector with associated FE space.
const SparseMatrix * GetConformingProlongation() const
The returned SparseMatrix is owned by the FiniteElementSpace.
Data type for scaled Jacobi-type smoother of sparse matrix.
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
virtual void Step(Vector &x, double &t, double &dt)
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in]...
virtual const Operator * GetProlongationMatrix() const
The returned Operator is owned by the FiniteElementSpace.
void InterpolateTMOP_QualityMetric(TMOP_QualityMetric &metric, const TargetConstructor &tc, const Mesh &mesh, GridFunction &metric_gf)
Interpolates the metric's values at the nodes of metric_gf.
void GetElementVDofs(int i, Array< int > &vdofs) const
Returns indexes of degrees of freedom in array dofs for i'th element.
Base abstract class for first order time dependent operators.
void SaveAsOne(std::ostream &out=mfem::out)
Merge the local grid functions.
ParFiniteElementSpace * pfes
Data type dense matrix using column-major storage.
int Size() const
Returns the size of the vector.
int GetNE() const
Returns number of elements.
virtual void Mult(const Vector &x, Vector &y) const =0
Operator application: y=A(x).
Abstract parallel finite element space.
void vis_tmop_metric_s(int order, TMOP_QualityMetric &qm, const TargetConstructor &tc, Mesh &mesh, char *title, int position)
void add(const Vector &v1, const Vector &v2, Vector &v)
double Norm(const Vector &x) const
virtual void ProcessNewState(const Vector &x) const
This method can be overloaded in derived classes to perform computations that need knowledge of the n...
virtual void ComputeAtNewPosition(const Vector &new_nodes, Vector &new_field)
virtual void Save(std::ostream &out) const
Save the GridFunction to an output stream.
Abstract class for local mesh quality metrics in the target-matrix optimization paradigm (TMOP) by P...
IntegrationPoint & IntPoint(int i)
Returns a reference to the i-th integration point.
void SetPrintLevel(int print_lvl)
virtual void Init(TimeDependentOperator &_f)
Associate a TimeDependentOperator with the ODE solver.
int Height() const
Get the height (size of output) of the Operator. Synonym with NumRows().
Mesh * GetMesh() const
Returns the mesh.
SerialAdvectorCGOper(const Vector &x_start, GridFunction &vel, FiniteElementSpace &fes)
void PrintAsOne(std::ostream &out=mfem::out)
virtual void Mult(const Vector &ind, Vector &di_dt) const
Perform the action of the operator: y = k = f(x, t), where k solves the algebraic equation F(x...
void SetMaxIter(int max_it)
virtual const Operator * GetProlongationMatrix() const
The returned Operator is owned by the FiniteElementSpace.
Performs a single remap advection step in serial.
Parallel smoothers in hypre.
void UpdateTargetSpecification(const Vector &new_x)
FiniteElementSpace * FESpace()
double GetElementSize(int i, int type=0)
Get the size of the i-th element relative to the perfect reference element.
Wrapper for hypre's parallel vector class.
double Min() const
Returns the minimal element of the vector.
virtual void ProcessNewState(const Vector &x) const
This method can be overloaded in derived classes to perform computations that need knowledge of the n...
double * Data() const
Returns the matrix data array.
void SetAbsTol(double atol)
void SetRelTol(double rtol)
Class FiniteElementSpace - responsible for providing FEM view of the mesh, mainly managing the set of...
int GetDof() const
Returns the number of degrees of freedom in the finite element.
virtual void Mult(const Vector &x, Vector &y) const
Matrix vector multiplication.
ParAdvectorCGOper(const Vector &x_start, GridFunction &vel, ParFiniteElementSpace &pfes)
void subtract(const Vector &x, const Vector &y, Vector &z)
Performs a single remap advection step in parallel.
double Max() const
Returns the maximal element of the vector.
virtual void SetInitialField(const Vector &init_nodes, const Vector &init_field)
VectorGridFunctionCoefficient u_coeff
const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement associated with i'th element.
double infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
int open(const char hostname[], int port)
virtual void Mult(const Vector &ind, Vector &di_dt) const
Perform the action of the operator: y = k = f(x, t), where k solves the algebraic equation F(x...
virtual void SetOperator(const Operator &op)
Also calls SetOperator for the preconditioner if there is one.
void MultAtB(const DenseMatrix &A, const DenseMatrix &B, DenseMatrix &AtB)
Multiply the transpose of a matrix A with a matrix B: At*B.
void GetNodes(Vector &node_coord) const
virtual double ComputeScalingFactor(const Vector &x, const Vector &b) const
This method can be overloaded in derived classes to implement line search algorithms.
virtual void SetPreconditioner(Solver &pr)
This should be called before SetOperator.
Class for parallel grid function.
Base class representing target-matrix construction algorithms for mesh optimization via the target-ma...
OutStream out(std::cout)
Global stream used by the library for standard output. Initially it uses the same std::streambuf as s...
Wrapper for hypre's ParCSR matrix class.
virtual void CalcDShape(const IntegrationPoint &ip, DenseMatrix &dshape) const =0
Evaluate the gradients of all shape functions of a scalar finite element in reference space at the gi...
virtual double ComputeScalingFactor(const Vector &x, const Vector &b) const
This method can be overloaded in derived classes to implement line search algorithms.
Class for parallel meshes.
void SetType(HypreSmoother::Type type, int relax_times=1)
Set the relaxation type and number of sweeps.
Arbitrary order "L2-conforming" discontinuous finite elements.