Gromacs  2024.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros | Enumerations | Functions | Variables
#include "gmxpre.h"
#include <cmath>
#include "gromacs/math/utilities.h"
#include "gromacs/utility/arraysize.h"
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/exceptions.h"
#include "gromacs/utility/smalloc.h"
#include "keywords.h"
#include "selmethod.h"
+ Include dependency graph for sm_compare.cpp:

Description

Implements internal selection method for comparison expressions.

Author
Teemu Murtola teemu.nosp@m..mur.nosp@m.tola@.nosp@m.gmai.nosp@m.l.com

Classes

struct  t_compare_value
 Data structure for comparison expression operand values. More...
 
struct  t_methoddata_compare
 Data structure for comparison expression evaluation. More...
 

Macros

#define CMP_SINGLEVAL   1
 The operand has a single value. More...
 
#define CMP_DYNAMICVAL   2
 The operand value is dynamic. More...
 
#define CMP_REALVAL   4
 The value is real. More...
 
#define CMP_ALLOCINT   16
 The integer array is allocated. More...
 
#define CMP_ALLOCREAL   32
 The real array is allocated. More...
 

Enumerations

enum  e_comparison_t {
  CMP_INVALID, CMP_LESS, CMP_LEQ, CMP_GTR,
  CMP_GEQ, CMP_EQUAL, CMP_NEQ
}
 Defines the comparison operator for comparison expressions. More...
 

Functions

static void * init_data_compare (int npar, gmx_ana_selparam_t *param)
 Allocates data for comparison expression evaluation. More...
 
static void init_compare (const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data)
 Initializes data for comparison expression evaluation. More...
 
static void free_data_compare (void *data)
 Frees the memory allocated for comparison expression evaluation. More...
 
static void evaluate_compare (const gmx::SelMethodEvalContext &context, gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
 Evaluates comparison expressions. More...
 
static e_comparison_t comparison_type (const char *str)
 Returns a e_comparison_t value corresponding to an operator. More...
 
static const char * comparison_type_str (e_comparison_t cmpt)
 Returns a string corresponding to a e_comparison_t value. More...
 
void _gmx_selelem_print_compare_info (FILE *fp, void *data)
 Prints information about a comparison expression. More...
 
static e_comparison_t reverse_comparison_type (e_comparison_t type)
 Reverses a comparison operator. More...
 
static int init_comparison_value (t_compare_value *val, gmx_ana_selparam_t param[2])
 Initializes the value storage for comparison expression. More...
 
static void convert_int_real (int n, t_compare_value *val)
 Converts an integer value to floating point. More...
 
static void convert_real_int (int n, t_compare_value *val, e_comparison_t cmpt, bool bRight)
 Converts a floating point value to integer. More...
 
static void evaluate_compare_int (gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
 Implementation for evaluate_compare() for integer values. More...
 
static void evaluate_compare_real (gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
 Implementation for evaluate_compare() if either value is non-integer. More...
 

Variables

static gmx_ana_selparam_t smparams_compare []
 Parameters for comparison expression evaluation. More...
 
gmx_ana_selmethod_t sm_compare
 Selection method data for comparison expression evaluation. More...
 

Macro Definition Documentation

#define CMP_ALLOCINT   16

The integer array is allocated.

#define CMP_ALLOCREAL   32

The real array is allocated.

#define CMP_DYNAMICVAL   2

The operand value is dynamic.

#define CMP_REALVAL   4

The value is real.

#define CMP_SINGLEVAL   1

The operand has a single value.

Enumeration Type Documentation

Defines the comparison operator for comparison expressions.

Enumerator
CMP_INVALID 

Indicates an error.

CMP_LESS 

'<'

CMP_LEQ 

'<='

CMP_GTR 

'>'

CMP_GEQ 

'>='

CMP_EQUAL 

'=='

CMP_NEQ 

'!='

Function Documentation

void _gmx_selelem_print_compare_info ( FILE *  fp,
void *  data 
)

Prints information about a comparison expression.

Parameters
[in]fpFile to receive the output.
[in]dataShould point to a t_methoddata_compare.
static e_comparison_t comparison_type ( const char *  str)
static

Returns a e_comparison_t value corresponding to an operator.

Parameters
[in]strString to process.
Returns
The comparison type corresponding to the first one or two characters of str.

str can contain any number of characters; only the first two are used. If the beginning of str does not match any of the recognized types, CMP_INVALID is returned.

static const char* comparison_type_str ( e_comparison_t  cmpt)
static

Returns a string corresponding to a e_comparison_t value.

Parameters
[in]cmptComparison type to convert.
Returns
Pointer to a string that corresponds to cmpt.

The return value points to a string constant and should not be free'd.

The function returns NULL if cmpt is not one of the valid values.

static void convert_int_real ( int  n,
t_compare_value val 
)
static

Converts an integer value to floating point.

Parameters
[in]nNumber of values in the val->u array.
[in,out]valValue to convert.
static void convert_real_int ( int  n,
t_compare_value val,
e_comparison_t  cmpt,
bool  bRight 
)
static

Converts a floating point value to integer.

Parameters
[in]nNumber of values in the val->u array.
[in,out]valValue to convert.
[in]cmptComparison operator type.
[in]bRighttrue if val appears on the right hand size of cmpt.
Returns
0 on success, EINVAL on error.

The values are rounded such that the same comparison operator can be used.

static void evaluate_compare ( const gmx::SelMethodEvalContext context,
gmx_ana_index_t g,
gmx_ana_selvalue_t out,
void *  data 
)
static

Evaluates comparison expressions.

Parameters
[in]contextNot used.
[in]gEvaluation index group.
[out]outOutput data structure (out->u.g is used).
[in]dataShould point to a t_methoddata_compare.
static void evaluate_compare_int ( gmx_ana_index_t g,
gmx_ana_selvalue_t out,
void *  data 
)
static

Implementation for evaluate_compare() for integer values.

Parameters
[in]gEvaluation index group.
[out]outOutput data structure (out->u.g is used).
[in]dataShould point to a t_methoddata_compare.
static void evaluate_compare_real ( gmx_ana_index_t g,
gmx_ana_selvalue_t out,
void *  data 
)
static

Implementation for evaluate_compare() if either value is non-integer.

Parameters
[in]gEvaluation index group.
[out]outOutput data structure (out->u.g is used).
[in]dataShould point to a t_methoddata_compare.

Left value is assumed to be real-valued; right value can be either. This is ensured by the initialization method.

static void free_data_compare ( void *  data)
static

Frees the memory allocated for comparison expression evaluation.

Parameters
dataData to free (should point to a t_methoddata_compare).

Frees the memory allocated for t_methoddata_compare.

static void init_compare ( const gmx_mtop_t *  top,
int  npar,
gmx_ana_selparam_t param,
void *  data 
)
static

Initializes data for comparison expression evaluation.

Parameters
[in]topNot used.
[in]nparNot used (should be 5).
[in]paramMethod parameters (should point to smparams_compare).
[in]dataShould point to a t_methoddata_compare.
Returns
0 if the input data is valid, -1 on error.
static int init_comparison_value ( t_compare_value val,
gmx_ana_selparam_t  param[2] 
)
static

Initializes the value storage for comparison expression.

Parameters
[out]valValue structure to initialize.
[in]paramParameters to use for initialization.
Returns
The number of values provided for the value, 0 on error.
static void * init_data_compare ( int  npar,
gmx_ana_selparam_t param 
)
static

Allocates data for comparison expression evaluation.

Parameters
[in]nparNot used (should be 5).
[in,out]paramMethod parameters (should point to a copy of smparams_compare).
Returns
Pointer to the allocated data (t_methoddata_compare).

Allocates memory for a t_methoddata_compare structure.

static e_comparison_t reverse_comparison_type ( e_comparison_t  type)
static

Reverses a comparison operator.

Parameters
[in]typeComparison operator to reverse.
Returns
The correct comparison operator that equals type when the left and right sides are interchanged.

Variable Documentation

gmx_ana_selmethod_t sm_compare
Initial value:
= {
"cmp",
8 ,
nullptr,
nullptr,
nullptr,
nullptr,
{ nullptr, nullptr, 0, nullptr },
}
static void free_data_compare(void *data)
Frees the memory allocated for comparison expression evaluation.
Definition: sm_compare.cpp:473
One group of atoms.
Definition: selvalue.h:58
static void init_compare(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data)
Initializes data for comparison expression evaluation.
Definition: sm_compare.cpp:407
static void * init_data_compare(int npar, gmx_ana_selparam_t *param)
Allocates data for comparison expression evaluation.
Definition: sm_compare.cpp:267
static void evaluate_compare(const gmx::SelMethodEvalContext &context, gmx_ana_index_t *g, gmx_ana_selvalue_t *out, void *data)
Evaluates comparison expressions.
Definition: sm_compare.cpp:590
constexpr int asize(T(&)[N])
Calculates the number of elements in a static array at compile time.
Definition: arraysize.h:50
static gmx_ana_selparam_t smparams_compare[]
Parameters for comparison expression evaluation.
Definition: sm_compare.cpp:142

Selection method data for comparison expression evaluation.

Selection method data for comparison expression evaluation.

gmx_ana_selparam_t smparams_compare[]
static
Initial value:
= {
{ "int1", { INT_VALUE, -1, { nullptr } }, nullptr, 2 | 4 | 32 },
{ "real1", { REAL_VALUE, -1, { nullptr } }, nullptr, 2 | 4 | 32 },
{ "op", { STR_VALUE, 1, { nullptr } }, nullptr, 0 },
{ "int2", { INT_VALUE, -1, { nullptr } }, nullptr, 2 | 4 | 32 },
{ "real2", { REAL_VALUE, -1, { nullptr } }, nullptr, 2 | 4 | 32 },
}
One or more real values.
Definition: selvalue.h:55
One or more string values.
Definition: selvalue.h:56
One or more integer values.
Definition: selvalue.h:54

Parameters for comparison expression evaluation.