ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
basic_funcs.cpp File Reference
#include "basic_funcs.h"
#include <iostream>
#include "source_base/constants.h"
#include "source_base/formatter.h"
Include dependency graph for basic_funcs.cpp:

Functions

double maxval_abs_2d (const std::vector< ModuleBase::Vector3< double > > &array)
 Find the maximum absolute value across all atoms and components.
std::pair< int, int > maxloc_abs_2d (const std::vector< ModuleBase::Vector3< double > > &array)
 Find the maximum absolute value and its (atom, component) index.
template<typename T>
T sum_2d (const std::vector< ModuleBase::Vector3< T > > &array)
 Sum of all elements across all atoms and components.
template int sum_2d< int > (const std::vector< ModuleBase::Vector3< int > > &array)
template double sum_2d< double > (const std::vector< ModuleBase::Vector3< double > > &array)
void scalar_multiply_2d (const std::vector< ModuleBase::Vector3< double > > &array, double scalar, std::vector< ModuleBase::Vector3< double > > &result)
 Element-wise scalar multiplication: result = scalar * array.
void add_scalar_multiply_2d (const std::vector< ModuleBase::Vector3< double > > &array_1, const std::vector< ModuleBase::Vector3< double > > &array_2, double scalar, std::vector< ModuleBase::Vector3< double > > &result)
 Element-wise fused multiply-add: result = array_1 + scalar * array_2.
void subtract_2d (const std::vector< ModuleBase::Vector3< double > > &array_1, const std::vector< ModuleBase::Vector3< double > > &array_2, std::vector< ModuleBase::Vector3< double > > &result)
 Element-wise subtraction: result = array_1 - array_2.
void fill_scalar_2d (double scalar, std::vector< ModuleBase::Vector3< double > > &result)
 Fill all elements with a scalar value.
void where_fill_scalar_2d (const std::vector< ModuleBase::Vector3< int > > &array_mask, int mask, double scalar, std::vector< ModuleBase::Vector3< double > > &result)
 Conditional fill: if mask[iat][ic] == value, set result[iat][ic] = scalar.
void where_fill_scalar_else_2d (const std::vector< ModuleBase::Vector3< int > > &array_mask, int mask, double scalar, const std::vector< ModuleBase::Vector3< double > > &rest, std::vector< ModuleBase::Vector3< double > > &result)
 Conditional fill with else branch: if mask == value, set scalar; otherwise copy from rest.
void print_2d (const std::string info, const std::vector< ModuleBase::Vector3< double > > &array, const int nspin, const double unit_convert, std::ostream &ofs)
 Formatted print of a 2D array.

Function Documentation

◆ add_scalar_multiply_2d()

void add_scalar_multiply_2d ( const std::vector< ModuleBase::Vector3< double > > & array_1,
const std::vector< ModuleBase::Vector3< double > > & array_2,
double scalar,
std::vector< ModuleBase::Vector3< double > > & result )

Element-wise fused multiply-add: result = array_1 + scalar * array_2.

Here is the caller graph for this function:

◆ fill_scalar_2d()

void fill_scalar_2d ( double scalar,
std::vector< ModuleBase::Vector3< double > > & result )

Fill all elements with a scalar value.

Here is the caller graph for this function:

◆ maxloc_abs_2d()

std::pair< int, int > maxloc_abs_2d ( const std::vector< ModuleBase::Vector3< double > > & array)

Find the maximum absolute value and its (atom, component) index.

Returns
pair<iat, ic> of the element with maximum absolute value
Here is the caller graph for this function:

◆ maxval_abs_2d()

double maxval_abs_2d ( const std::vector< ModuleBase::Vector3< double > > & array)

Find the maximum absolute value across all atoms and components.

Returns
max(|array[iat][ic]|) for all iat, ic
Here is the caller graph for this function:

◆ print_2d()

void print_2d ( const std::string info,
const std::vector< ModuleBase::Vector3< double > > & array,
const int nspin,
const double unit_convert = 1.0,
std::ostream & ofs = std::cout )

Formatted print of a 2D array.

Parameters
infoHeader string
arrayData to print
nspinSpin type: 2=z-only, 4=xyz
unit_convertMultiplicative factor (e.g., Ry_to_eV for unit conversion)
ofsOutput stream (default: stdout)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ scalar_multiply_2d()

void scalar_multiply_2d ( const std::vector< ModuleBase::Vector3< double > > & array,
double scalar,
std::vector< ModuleBase::Vector3< double > > & result )

Element-wise scalar multiplication: result = scalar * array.

Here is the caller graph for this function:

◆ subtract_2d()

void subtract_2d ( const std::vector< ModuleBase::Vector3< double > > & array_1,
const std::vector< ModuleBase::Vector3< double > > & array_2,
std::vector< ModuleBase::Vector3< double > > & result )

Element-wise subtraction: result = array_1 - array_2.

Here is the caller graph for this function:

◆ sum_2d()

template<typename T>
T sum_2d ( const std::vector< ModuleBase::Vector3< T > > & array)

Sum of all elements across all atoms and components.

Template Parameters
TNumeric type (int or double)
Returns
sum(array[iat][ic]) for all iat, ic
Here is the caller graph for this function:

◆ sum_2d< double >()

template double sum_2d< double > ( const std::vector< ModuleBase::Vector3< double > > & array)

◆ sum_2d< int >()

template int sum_2d< int > ( const std::vector< ModuleBase::Vector3< int > > & array)

◆ where_fill_scalar_2d()

void where_fill_scalar_2d ( const std::vector< ModuleBase::Vector3< int > > & array_mask,
int mask,
double scalar,
std::vector< ModuleBase::Vector3< double > > & result )

Conditional fill: if mask[iat][ic] == value, set result[iat][ic] = scalar.

Used to mask unconstrained components to zero: where_fill_scalar_2d(constrain_, 0, 0.0, delta_spin) sets delta_spin[ia][ic] = 0 where constrain[ia][ic] == 0.

Here is the caller graph for this function:

◆ where_fill_scalar_else_2d()

void where_fill_scalar_else_2d ( const std::vector< ModuleBase::Vector3< int > > & array_mask,
int mask,
double scalar,
const std::vector< ModuleBase::Vector3< double > > & rest,
std::vector< ModuleBase::Vector3< double > > & result )

Conditional fill with else branch: if mask == value, set scalar; otherwise copy from rest.

Used to create masked copies: where_fill_scalar_else_2d(constrain_, 0, 0.0, lambda_, initial_lambda) sets initial_lambda[ia][ic] = 0 if unconstrained, else lambda_[ia][ic].

Here is the caller graph for this function: