15 #include "../general/osockstream.hpp"
33 const int pnt_cnt = new_field.
Size()/
ncomp;
37 for (
int i = 0; i <
ncomp; i++)
39 Vector new_field_temp(new_field.
GetData()+i*pnt_cnt, pnt_cnt);
40 ComputeAtNewPositionScalar(new_nodes, new_field_temp);
47 void AdvectorCG::ComputeAtNewPositionScalar(
const Vector &new_nodes,
55 MFEM_VERIFY(m != NULL,
"No mesh has been given to the AdaptivityEvaluator.");
60 double minv = new_field.
Min(), maxv = new_field.
Max();
84 MFEM_VERIFY(oper != NULL,
85 "No FE space has been given to the AdaptivityEvaluator.");
86 ode_solver.
Init(*oper);
90 for (
int i = 0; i < m->
GetNE(); i++)
95 const int s = new_field.
Size();
97 for (
int i = 0; i < s; i++)
100 for (
int j = 0; j <
dim; j++)
102 vel += u(i+j*s)*u(i+j*s);
104 v_max = std::max(v_max, vel);
110 double v_loc = v_max, h_loc = h_min;
111 MPI_Allreduce(&v_loc, &v_max, 1, MPI_DOUBLE, MPI_MAX,
pfes->
GetComm());
112 MPI_Allreduce(&h_loc, &h_min, 1, MPI_DOUBLE, MPI_MIN,
pfes->
GetComm());
126 v_max = std::sqrt(v_max);
127 double dt = dt_scale * h_min / v_max;
130 bool last_step =
false;
131 for (
int ti = 1; !last_step; ti++)
138 ode_solver.
Step(new_field, t, dt);
141 double glob_minv = minv,
146 MPI_Allreduce(&minv, &glob_minv, 1, MPI_DOUBLE, MPI_MIN,
pfes->
GetComm());
147 MPI_Allreduce(&maxv, &glob_maxv, 1, MPI_DOUBLE, MPI_MAX,
pfes->
GetComm());
152 for (
int i = 0; i < s; i++)
154 if (new_field(i) < glob_minv) { new_field(i) = glob_minv; }
155 if (new_field(i) > glob_maxv) { new_field(i) = glob_maxv; }
169 x0(x_start), x_now(*fes.GetMesh()->GetNodes()),
170 u(vel), u_coeff(&u), M(&fes), K(&fes)
190 K.BilinearForm::operator=(0.0);
194 M.BilinearForm::operator=(0.0);
205 lin_solver.
Mult(rhs, di_dt);
213 x0(x_start), x_now(*pfes.GetMesh()->GetNodes()),
214 u(vel), u_coeff(&u), M(&pfes), K(&pfes)
234 K.BilinearForm::operator=(0.0);
238 M.BilinearForm::operator=(0.0);
249 lin_solver.SetPreconditioner(prec);
250 lin_solver.SetOperator(*Mh);
251 lin_solver.SetRelTol(1e-8);
252 lin_solver.SetAbsTol(0.0);
253 lin_solver.SetMaxIter(100);
254 lin_solver.SetPrintLevel(0);
255 lin_solver.Mult(*RHS, X);
263 #ifdef MFEM_USE_GSLIB
274 const double rel_bbox_el = 0.1;
275 const double newton_tol = 1.0e-12;
276 const int npts_at_once = 256;
295 finder->
Setup(*m, rel_bbox_el, newton_tol, npts_at_once);
298 field0_gf = init_field;
306 finder->
Interpolate(new_nodes, field0_gf, new_field);
315 double energy_in = 0.0;
318 MFEM_VERIFY(!(
parallel && p_nlf == NULL),
"Invalid Operator subclass.");
327 MFEM_VERIFY(!(serial && nlf == NULL),
"Invalid Operator subclass.");
343 if (!cP) { x_out_loc = x; }
344 else { cP->
Mult(x, x_out_loc); }
356 for (
int i = 0; i < NE; i++)
363 x_out_loc.GetSubVector(xdofs, posV);
367 for (
int j = 0; j < nsp; j++)
371 min_detJ = std::min(min_detJ, Jpr.
Det());
374 double min_detJ_all = min_detJ;
378 MPI_Allreduce(&min_detJ, &min_detJ_all, 1, MPI_DOUBLE, MPI_MIN,
382 const bool untangling = (min_detJ_all <= 0) ?
true :
false;
387 bool x_out_ok =
false;
388 double scale = 1.0, energy_out = 0.0;
389 const double norm0 =
Norm(
r);
391 const double detJ_factor = (
solver_type == 1) ? 0.25 : 0.5;
394 for (
int i = 0; i < 12; i++)
396 add(x, -scale,
c, x_out);
401 if (!cP) { x_out_loc = x_out; }
402 else { cP->
Mult(x_out, x_out_loc); }
415 for (
int i = 0; i < NE; i++)
422 x_out_loc.GetSubVector(xdofs, posV);
426 for (
int j = 0; j < nsp; j++)
430 if (Jpr.
Det() <= 0.0) { jac_ok = 0;
goto break2; }
435 int jac_ok_all = jac_ok;
439 MPI_Allreduce(&jac_ok, &jac_ok_all, 1, MPI_INT, MPI_LAND,
447 {
mfem::out <<
"Scale = " << scale <<
" Neg det(J) found.\n"; }
448 scale *= detJ_factor;
continue;
466 if (energy_out > energy_in || std::isnan(energy_out) != 0)
470 else { x_out_ok =
true;
break; }
474 if (energy_out > 1.2*energy_in || std::isnan(energy_out) != 0)
477 {
mfem::out <<
"Scale = " << scale <<
" Increasing energy.\n"; }
478 scale *= 0.5;
continue;
481 oper->
Mult(x_out,
r);
482 if (have_b) {
r -=
b; }
483 double norm =
Norm(
r);
485 if (norm > 1.2*norm0)
488 {
mfem::out <<
"Scale = " << scale <<
" Norm increased.\n"; }
489 scale *= 0.5;
continue;
491 else { x_out_ok =
true;
break; }
498 << (energy_in - energy_out) / energy_in * 100.0
499 <<
"% with " << scale <<
" scaling.\n";
502 if (x_out_ok ==
false) { scale = 0.0; }
516 for (
int i = 0; i < integs.
Size(); i++)
528 for (
int j = 0; j < ati.
Size(); j++)
530 dtc = ati[j]->GetDiscreteAdaptTC();
544 for (
int i = 0; i < integs.
Size(); i++)
557 for (
int j = 0; j < ati.
Size(); j++)
559 ati[j]->ComputeFDh(x_loc, *pfesc);
580 for (
int i = 0; i < integs.
Size(); i++)
593 for (
int j = 0; j < ati.
Size(); j++)
595 ati[j]->ComputeFDh(x_loc, *fesc);
604 const Vector &x_new)
const
606 const bool update_flag =
true;
625 char *title,
int position)
634 sock.
open(
"localhost", 19916);
635 sock <<
"solution\n";
641 sock <<
"window_title '"<< title <<
"'\n"
642 <<
"window_geometry "
643 << position <<
" " << 0 <<
" " << 600 <<
" " << 600 <<
"\n"
653 char *title,
int position)
660 sock <<
"solution\n";
664 sock <<
"window_title '"<< title <<
"'\n"
665 <<
"window_geometry "
666 << 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)
void Interpolate(const GridFunction &field_in, Vector &field_out)
virtual double GetTime() const
Read the currently set time.
int Size() const
Return the logical size of the array.
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 an integration rule - an Array of IntegrationPoint.
Class for grid function - Vector with associated FE space.
void UpdateAfterMeshChange(const Vector &new_x)
const SparseMatrix * GetConformingProlongation() const
The returned SparseMatrix is owned by the FiniteElementSpace.
Data type for scaled Jacobi-type smoother of sparse matrix.
ParMesh * GetParMesh() const
void UpdateDiscreteTC(const TMOP_Integrator &ti, const Vector &x_new) const
virtual void Mult(const Vector &b, Vector &x) const
Operator application: y=A(x).
virtual const Operator * GetProlongationMatrix() const
The returned Operator is owned by the FiniteElementSpace.
void SetSize(int s)
Resize the vector to size s.
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.
const IntegrationRule & GetIntegrationRule(const FiniteElement &el) const
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 UpdateGradientTargetSpecification(const Vector &x, double dx, bool use_flag=false)
double * GetData() const
Return a pointer to the beginning of the Vector data.
void add(const Vector &v1, const Vector &v2, Vector &v)
double Norm(const Vector &x) const
void UpdateTargetSpecification(const Vector &new_x, bool use_flag=false)
virtual void ComputeAtNewPosition(const Vector &new_nodes, Vector &new_field)
void Init(TimeDependentOperator &_f) override
Associate a TimeDependentOperator with the ODE solver.
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)
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.
void Setup(Mesh &m, const double bb_t=0.1, const double newt_tol=1.0e-12, const int npt_max=256)
Performs a single remap advection step in serial.
Parallel smoothers in hypre.
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)
void UpdateHessianTargetSpecification(const Vector &x, double dx, bool use_flag=false)
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.
DiscreteAdaptTC * GetDiscreteAdaptTC() const
void ResetUpdateFlags()
Used in combination with the Update methods to avoid extra computations.
virtual void ComputeAtNewPosition(const Vector &new_nodes, Vector &new_field)
void ComputeFDh(const Vector &x, const FiniteElementSpace &fes)
Determines the perturbation, h, for FD-based approximation.
double Max() const
Returns the maximal element of the vector.
void vel(const Vector &x, double t, Vector &u)
virtual void SetInitialField(const Vector &init_nodes, const Vector &init_field)
VectorGridFunctionCoefficient u_coeff
virtual void Mult(const Vector &x, Vector &y) const
Perform the action of the operator: y = k = f(x, t), where k solves the algebraic equation F(x...
const FiniteElement * GetFE(int i) const
Returns pointer to the FiniteElement in the FiniteElementCollection associated with i'th element in t...
double infinity()
Define a shortcut for std::numeric_limits<double>::infinity()
virtual void SetSpace(FiniteElementSpace *f)
Associate a new FiniteElementSpace with the GridFunction.
int open(const char hostname[], int port)
Open the socket stream on 'port' at 'hostname'.
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.
FindPointsGSLIB can robustly evaluate a GridFunction on an arbitrary collection of points...
const FiniteElementCollection * FEColl() const
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.
void Step(Vector &x, double &t, double &dt) override
Perform a time step from time t [in] to time t [out] based on the requested step size dt [in]...
void SetNodes(const Vector &node_coord)
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...
Class for parallel meshes.
const Array< TMOP_Integrator * > & GetTMOPIntegrators() const
void SetType(HypreSmoother::Type type, int relax_times=1)
Set the relaxation type and number of sweeps.
virtual void SetInitialField(const Vector &init_nodes, const Vector &init_field)
Arbitrary order "L2-conforming" discontinuous finite elements.
double f(const Vector &p)
A TMOP integrator class based on any given TMOP_QualityMetric and TargetConstructor.