Global Namespace¶
Overview¶
// namespaces namespace rgpot; namespace rgpot::cache; namespace rgpot::types; namespace rgpot::types::adapt; namespace rgpot::types::adapt::capnp; namespace rgpot::types::adapt::eigen; namespace rgpot::types::adapt::xtensor; // typedefs typedef struct PotClient PotClient; // classes class AtomMatrix; class GenericPotImpl; class PotClient; // global functions void c_force_eam(int* natms, int ndim, double* box, double* R, double* F, double* U); PotClient* pot_client_init(const char* host, int32_t port); void pot_client_free(PotClient* client); int32_t pot_calculate(PotClient* client, int32_t natoms, const double* pos, const int32_t* atmnrs, const double* box, double* out_energy, double* out_forces); const char* pot_get_last_error(PotClient* client); PotClient* pot_client_init(const char* host, int32_t port); void pot_client_free(PotClient* client); int32_t pot_calculate(PotClient* client, int32_t natoms, const double* pos, const int32_t* atmnrs, const double* box, double* out_energy, double* out_forces); const char* pot_get_last_error(PotClient* client); int main(int argc, char* argv[]); // macros #define CATCH_AND_REPORT(client, default_ret)
Detailed Documentation¶
Typedefs¶
typedef struct PotClient PotClient
C API for the RPC potential client bridge.
This header provides a C-compatible interface to the distributed potential calculation client, allowing integration with Fortran or other languages with a C interface, e.g. Julia.
Opaque handle to the client context.
Global Functions¶
void c_force_eam(int* natms, int ndim, double* box, double* R, double* F, double* U)
C-linkage bridge to the Fortran EAM implementation.
Parameters:
natms |
Array containing counts of Cu and H atoms. |
ndim |
Total dimensions (3 * N). |
box |
Diagonal box vectors (assumes cubic). |
R |
Pointer to flat position array. |
F |
Pointer to output force array. |
U |
Pointer to output energy value. |
Returns:
Void.
PotClient* pot_client_init(const char* host, int32_t port)
Initializes the RPC client connection.
Constructs a string-based address from the host and port, then initializes a new capnp::EzRpcClient. The main capability is cast to the Potential interface defined in the schema.
Note
Returns nullptr if the connection cannot be established or if the address is malformed.
void pot_client_free(PotClient* client)
Frees all resources associated with the client.
Performs a standard delete on the client pointer. This triggers the PotClient destructor, which cleans up the unique_ptr and associated RPC state.
int32_t pot_calculate(PotClient* client, int32_t natoms, const double* pos, const int32_t* atmnrs, const double* box, double* out_energy, double* out_forces)
Executes a remote potential calculation.
This function performs the following steps:
Resets the
last_errorbuffer.Initializes a calculation request.
Maps the input pointers to
kj::arrayPtrviews to avoid unnecessary copying before serialization.Waits for the RPC promise to resolve.
Validates the size of the returned force array.
Copies the results into the provided output buffers.
Warning
The server must return a force array matching natoms * 3. If the sizes do not match, a non-zero error code is returned.
const char* pot_get_last_error(PotClient* client)
Retrieves the most recent error message.
Checks if a valid client handle is provided and if the last_error buffer contains data. If no error is recorded, an empty string is returned.
PotClient* pot_client_init(const char* host, int32_t port)
Initializes the RPC client connection.
Constructs a string-based address from the host and port, then initializes a new capnp::EzRpcClient. The main capability is cast to the Potential interface defined in the schema.
Note
Returns nullptr if the connection cannot be established or if the address is malformed.
Parameters:
host |
Target server hostname or IP address. |
port |
Network port of the potential server. |
Returns:
Pointer to the client context or NULL on failure.
See also:
pot_get_last_error
void pot_client_free(PotClient* client)
Frees all resources associated with the client.
Performs a standard delete on the client pointer. This triggers the PotClient destructor, which cleans up the unique_ptr and associated RPC state.
Parameters:
client |
The opaque client handle to release. |
Returns:
Void.
int32_t pot_calculate(PotClient* client, int32_t natoms, const double* pos, const int32_t* atmnrs, const double* box, double* out_energy, double* out_forces)
Executes a remote potential calculation.
The client must be successfully initialized.
This function performs the following steps:
Resets the
last_errorbuffer.Initializes a calculation request.
Maps the input pointers to
kj::arrayPtrviews to avoid unnecessary copying before serialization.Waits for the RPC promise to resolve.
Validates the size of the returned force array.
Copies the results into the provided output buffers.
Warning
The server must return a force array matching natoms * 3. If the sizes do not match, a non-zero error code is returned.
Parameters:
client |
The opaque client handle. |
natoms |
Total number of atoms in the system. |
pos |
Array of flattened atomic coordinates. |
atmnrs |
Array of atomic numbers. |
box |
Simulation cell vectors in row-major order. |
out_energy |
Pointer to store the calculated energy. |
out_forces |
Buffer to store the calculated forces. |
Returns:
0 on success, non-zero on failure.
const char* pot_get_last_error(PotClient* client)
Retrieves the most recent error message.
Checks if a valid client handle is provided and if the last_error buffer contains data. If no error is recorded, an empty string is returned.
Parameters:
client |
The opaque client handle. |
Returns:
String containing the error description.
int main(int argc, char* argv[])
The main entry point handles command-line arguments to specify the network port and the potential type. It instantiates the requested physics engine and blocks until the server is terminated.
Usage¶
````./potserv <port> <PotentialType>
Parameters:
argc |
Argument count. |
argv |
Argument vector. |
Returns:
0 on success, 1 on initialization failure.