37 #ifndef QualityMetric_hpp
38 #define QualityMetric_hpp
40 #ifndef MSQ_USE_OLD_C_HEADERS
192 {
return 0.5*(det+
sqrt(det*det+4*delta*delta)); }
236 int num_vtx,
double &metric_value,
246 int num_free_vtx,
double &metric_value,
MsqError &err);
254 int num_free_vtx,
double &metric_value,
MsqError &err);
264 int num_free_vtx,
double &metric_value,
MsqError &err);
295 double average_metrics(
const double metric_values[],
const int& num_values,
308 int num_metric_values,
314 const double metric_values[],
315 const int& num_values,
MsqError &err);
326 double &metric_value,
337 int num_free_vtx,
double &metric_value,
350 double &metric_value,
365 double &metric_value,
375 double &metric_value,
384 double &metric_value,
461 double &metric_value,
499 double &metric_value,
507 num_free_vtx, metric_value, err);
512 num_free_vtx, metric_value, err);
525 const int& num_values,
MsqError &err)
529 double total_value=0.0;
530 double temp_value=0.0;
541 for (i=0;i<num_values;++
i){
542 total_value*=(metric_values[
i]);
544 total_value=
pow(total_value, (1/((
double) num_values)));
549 for (i=0;i<num_values;++
i){
555 total_value+=(1/metric_values[
i]);
563 total_value=num_values/total_value;
567 for (i=0;i<num_values;++
i){
568 total_value+=metric_values[
i];
570 total_value/= (double) num_values;
574 total_value = metric_values[0];
575 for (i = 1; i < num_values; ++
i){
576 if (metric_values[i] > total_value){
577 total_value = metric_values[
i];
583 total_value = metric_values[0];
584 for (i = 1; i < num_values; ++
i){
585 if (metric_values[i] < total_value) {
586 total_value = metric_values[
i];
596 for (i=0;i<num_values;++
i){
597 total_value+=(metric_values[
i]*metric_values[
i]);
599 total_value/= (double) num_values;
600 total_value=
sqrt(total_value);
605 for (i=0;i<num_values;++
i){
606 if (metric_values[i]*metric_values[i] <
MSQ_MIN) {
609 total_value += (1.0/(metric_values[
i]*metric_values[
i]));
616 total_value =
sqrt(num_values/total_value);
622 for (i=0;i<num_values;++
i){
623 temp_value+=metric_values[
i];
624 total_value+=(metric_values[
i]*metric_values[
i]);
626 temp_value/= (double) num_values;
627 temp_value*=temp_value;
628 total_value/= (double) num_values;
629 total_value-=temp_value;
633 for (i=0;i<num_values;++
i){
634 total_value+=metric_values[
i];
639 for (i=0;i<num_values;++
i){
640 total_value+= (metric_values[
i]*metric_values[
i]);
648 for (i=0;i<num_values;++
i){
649 if(metric_values[i]<temp_value){
650 temp_value=metric_values[
i];
652 if(metric_values[i]>total_value){
653 total_value=metric_values[
i];
661 total_value-=temp_value;
668 for (i=0;i<num_values;++
i){
669 if(metric_values[i]<temp_value){
670 temp_value=metric_values[
i];
672 if(metric_values[i]>total_value){
673 total_value=metric_values[
i];
681 total_value/=temp_value;
685 for (j=0;j<num_values;++
j){
687 if (metric_values[j] <
MSQ_MIN) {
690 for (i=0;i<num_values;++
i){
691 total_value+=((metric_values[
i]/metric_values[
j])*
692 (metric_values[i]/metric_values[j]));
695 total_value/=(double)(num_values*num_values);
709 const double metric_values[],
710 const int& num_values,
MsqError &err)
714 double total_value=0.0;
724 for (i=0;i<num_values;++
i){
725 total_value += coef[
i]*metric_values[
i];
727 total_value /= (double) num_values;
742 #endif // QualityMetric_hpp
void set_averaging_method(AveragingMethod method, MsqError &err)
MetricType get_metric_type()
bool compute_element_numerical_gradient(PatchData &pd, MsqMeshEntity *element, MsqVertex *free_vtces[], Vector3D grad_vec[], int num_free_vtx, double &metric_value, MsqError &err)
Non-virtual function which numerically computes the gradient of a QualityMetric of a given element fo...
int get_negate_flag()
Returns negateFlag.
ElementEvaluationMode get_element_evaluation_mode()
Returns the evaluation mode for the metric.
double vertex_barrier_function(double det, double delta)
Escobar Barrier Function for Shape and Other Metrics.
bool compute_element_numerical_hessian(PatchData &pd, MsqMeshEntity *element, MsqVertex *free_vtces[], Vector3D grad_vec[], Matrix3D hessian[], int num_free_vtx, double &metric_value, MsqError &err)
bool compute_vertex_gradient(PatchData &pd, MsqVertex &vertex, MsqVertex *vertices[], Vector3D grad_vec[], int num_vtx, double &metric_value, MsqError &err)
Calls compute_vertex_numerical_gradient if gradType equals NUMERCIAL_GRADIENT. Calls compute_vertex_a...
Used to hold the error state and return it to the application.
Base class for concrete quality metrics.
requested functionality is not (yet) implemented
MsqMeshEntity is the Mesquite object that stores information about the elements in the mesh...
Vector3D is the object that effeciently stores information about about three-deminsional vectors...
msq_std::string metricName
virtual bool compute_element_analytical_hessian(PatchData &pd, MsqMeshEntity *element, MsqVertex *free_vtces[], Vector3D grad_vec[], Matrix3D hessian[], int num_free_vtx, double &metric_value, MsqError &err)
double average_metric_and_weights(double metric_values[], int num_metric_values, MsqError &err)
Given a list of metric values, calculate the average metric valude according to the current avgMethod...
void set_hessian_type(HESSIAN_TYPE ht)
Sets hessianType for this metric.
bool compute_element_hessian(PatchData &pd, MsqMeshEntity *element, MsqVertex *free_vtces[], Vector3D grad_vec[], Matrix3D hessian[], int num_free_vtx, double &metric_value, MsqError &err)
For MetricType == ELEMENT_BASED. Calls either compute_element_numerical_hessian() or compute_element_...
invalid function argument passed
virtual void change_metric_type(MetricType t, MsqError &err)
void set_element_evaluation_mode(ElementEvaluationMode mode, MsqError &err)
Sets the evaluation mode for the ELEMENT_BASED metrics.
#define MSQ_CHKERR(err)
Mesquite's Error Checking macro.
3*3 Matric class, row-oriented, 0-based [i][j] indexing.
bool compute_element_gradient(PatchData &pd, MsqMeshEntity *element, MsqVertex *free_vtces[], Vector3D grad_vec[], int num_free_vtx, double &metric_value, MsqError &err)
For MetricType == ELEMENT_BASED. Calls either compute_element_numerical_gradient() or compute_element...
double weighted_average_metrics(const double coef[], const double metric_values[], const int &num_values, MsqError &err)
takes an array of coefficients and an array of metrics (both of length num_value) and averages the co...
#define MSQ_SETERR(err)
Macro to set error - use err.clear() to clear.
void set_negate_flag(int neg)
virtual bool compute_element_analytical_gradient(PatchData &pd, MsqMeshEntity *element, MsqVertex *free_vtces[], Vector3D grad_vec[], int num_free_vtx, double &metric_value, MsqError &err)
Virtual function that computes the gradient of the QualityMetric analytically. The base class impleme...
virtual bool evaluate_element(PatchData &, MsqMeshEntity *, double &, MsqError &err)
Evaluate the metric for an element.
double det(const Matrix3D &A)
virtual bool evaluate_vertex(PatchData &, MsqVertex *, double &, MsqError &err)
Evaluate the metric for a vertex.
msq_std::string get_name()
Returns the name of this metric (as a string).
void set_feasible_constraint(int alpha)
bool compute_element_gradient_expanded(PatchData &pd, MsqMeshEntity *element, MsqVertex *free_vtces[], Vector3D grad_vec[], int num_free_vtx, double &metric_value, MsqError &err)
void set_gradient_type(GRADIENT_TYPE grad)
Sets gradType for this metric.
object is in an invalid state
void set_metric_type(MetricType t)
This function should be used in the constructor of every concrete quality metric. ...
double average_metrics(const double metric_values[], const int &num_values, MsqError &err)
average_metrics takes an array of length num_values and averages the contents using averaging method ...
ElementEvaluationMode evalMode
AveragingMethod avgMethod
MsqVertex is the Mesquite object that stores information about the vertices in the mesh...
virtual bool compute_vertex_analytical_gradient(PatchData &pd, MsqVertex &vertex, MsqVertex *vertices[], Vector3D grad_vec[], int num_vtx, double &metric_value, MsqError &err)
Virtual function that computes the gradient of the QualityMetric analytically. The base class impleme...
int get_feasible_constraint()
Returns the feasible flag for this metric.
void set_name(msq_std::string st)
Sets the name of this metric.
double pow(double value, const Exponent &exp)
bool compute_vertex_numerical_gradient(PatchData &pd, MsqVertex &vertex, MsqVertex *vertices[], Vector3D grad_vec[], int num_vtx, double &metric_value, MsqError &err)