/* Initialization function */ int model_init(void *km) { /* Local variables */ intptr_t* pkim = *((intptr_t**) km); double* model_cutoff; int ier; /* store pointer to compute function in KIM object */ ier = KIM_API_set_method(pkim, "compute", 1, (func_ptr) &compute); if (KIM_STATUS_OK > ier) { KIM_API_report_error(__LINE__, __FILE__, "KIM_API_set_method", ier); return ier; } /* store model cutoff in KIM object */ model_cutoff = (double*) KIM_API_get_data(pkim, "cutoff", &ier); if (KIM_STATUS_OK > ier) { KIM_API_report_error(__LINE__, __FILE__, "KIM_API_get_data", ier); return ier; } *model_cutoff = MODEL_CUTOFF; /* cutoff distance in angstroms */ ier = KIM_STATUS_OK; return ier; }
/*************************************************************************** * * publsih cutoff * ***************************************************************************/ int publish_cutoff(void* pkim, double cutoff) { /* local variable */ int status; double* pcutoff; /* update cutoff */ pcutoff = KIM_API_get_data(pkim, "PARAM_FREE_cutoff", &status); if (KIM_STATUS_OK != status) { warning("Publish cutoff to KIM failed. The cutoff in the KIM Model is used.\n" "Possibly the KIM Model has no 'PARAM_FREE_cutoff'.\n\n"); } else { *pcutoff = cutoff; /* reinit KIM model */ status = KIM_API_model_reinit(pkim); if (KIM_STATUS_OK > status) { KIM_API_report_error(__LINE__, __FILE__, "KIM_API_model_reinit", status); return status; } } return KIM_STATUS_OK; }
/* Initialization function */ int MODEL_NAME_LC_STR_init_(void *km) { /* Local variables */ intptr_t* pkim = *((intptr_t**) km); double* model_cutoff; double* model_cutnorm; double* model_epsilon; double* model_sigma; double* model_Pcutoff; double* model_A; double* model_B; double* model_C; double* model_sigmasq; double* model_cutsq; int ier; /* store function pointers in KIM object */ KIM_API_setm_data(pkim, &ier, 3*4, "compute", 1, &compute, 1, "reinit", 1, &reinit, 1, "destroy", 1, &destroy, 1); /* store model cutoff in KIM object */ model_cutoff = (double*) KIM_API_get_data(pkim, "cutoff", &ier); if (KIM_STATUS_OK > ier) { KIM_API_report_error(__LINE__, __FILE__, "KIM_API_get_data", ier); return ier; } *model_cutoff = CUTOFF_VALUE_STR /* allocate memory */ model_sigma = (double*) malloc(1*sizeof(double)); if (NULL == model_sigma) { ier = KIM_STATUS_FAIL; KIM_API_report_error(__LINE__, __FILE__, "malloc", ier); return ier; } model_epsilon = (double*) malloc(1*sizeof(double)); if (NULL == model_epsilon) { ier = KIM_STATUS_FAIL; KIM_API_report_error(__LINE__, __FILE__, "malloc", ier); return ier; } model_Pcutoff = (double*) malloc(1*sizeof(double)); if (NULL == model_Pcutoff) { ier = KIM_STATUS_FAIL; KIM_API_report_error(__LINE__, __FILE__, "malloc", ier); return ier; } model_cutnorm = (double*) malloc(1*sizeof(double)); if (NULL == model_cutnorm) { ier = KIM_STATUS_FAIL; KIM_API_report_error(__LINE__, __FILE__, "malloc", ier); return ier; } model_A = (double*) malloc(1*sizeof(double)); if (NULL == model_A) { ier = KIM_STATUS_FAIL; KIM_API_report_error(__LINE__, __FILE__, "malloc", ier); return ier; } model_B = (double*) malloc(1*sizeof(double)); if (NULL == model_B) { ier = KIM_STATUS_FAIL; KIM_API_report_error(__LINE__, __FILE__, "malloc", ier); return ier; } model_C = (double*) malloc(1*sizeof(double)); if (NULL == model_C) { ier = KIM_STATUS_FAIL; KIM_API_report_error(__LINE__, __FILE__, "malloc", ier); return ier; } model_sigmasq = (double*) malloc(1*sizeof(double)); if (NULL == model_sigmasq) { ier = KIM_STATUS_FAIL; KIM_API_report_error(__LINE__, __FILE__, "malloc", ier); return ier; } model_cutsq = (double*) malloc(1*sizeof(double)); if (NULL == model_cutsq) { ier = KIM_STATUS_FAIL; KIM_API_report_error(__LINE__, __FILE__, "malloc", ier); return ier; } /* store parameters in KIM object */ KIM_API_setm_data(pkim, &ier, 9*4, "PARAM_FREE_sigma", 1, model_sigma, 1, "PARAM_FREE_epsilon", 1, model_epsilon, 1, "PARAM_FREE_cutoff", 1, model_Pcutoff, 1, "PARAM_FIXED_cutnorm", 1, model_cutnorm, 1, "PARAM_FIXED_A", 1, model_A, 1, "PARAM_FIXED_B", 1, model_B, 1, "PARAM_FIXED_C", 1, model_C, 1, "PARAM_FIXED_sigmasq", 1, model_sigmasq, 1, "PARAM_FIXED_cutsq", 1, model_cutsq, 1); if (KIM_STATUS_OK > ier) { KIM_API_report_error(__LINE__, __FILE__, "KIM_API_setm_data", ier); return ier; } /* set value of sigma */ *model_sigma = SIGMA_VALUE_STR /* set value of epsilon */ *model_epsilon = EPSILON_VALUE_STR /* set value of parameter cutoff */ *model_Pcutoff = *model_cutoff; /* set value of parameter cutnorm */ *model_cutnorm = (*model_cutoff)/(*model_sigma); /* set value of parameter A */ *model_A = 12.0*(*model_epsilon)*(-26.0 + 7.0*pow(*model_cutnorm,6))/ (pow(*model_cutnorm,14)*(*model_sigma)*(*model_sigma)); /* set value of parameter B */ *model_B = 96.0*(*model_epsilon)*(7.0 - 2.0*pow(*model_cutnorm,6))/ (pow(*model_cutnorm,13)*(*model_sigma)); /* set value of parameter C */ *model_C = 28.0*(*model_epsilon)*(-13.0 + 4.0*pow(*model_cutnorm,6))/ pow(*model_cutnorm,12); /* set value of parameter sigmasq */ *model_sigmasq = (*model_sigma)*(*model_sigma); /* set value of parameter cutsq */ *model_cutsq = (*model_cutoff)*(*model_cutoff); ier = KIM_STATUS_OK; return ier; }
int get_free_param_double(void* pkim, FreeParamType* FreeParam) { /*local vars*/ int status; int NumFreeParam; int maxStringLength; char* pstr; char buffer[128]; char name[64]; char type[16]; int NumFreeParamDouble; int i; /* get the maxStringLength of free parameters */ status = KIM_API_get_num_free_params(pkim, &NumFreeParam, &maxStringLength); if (KIM_STATUS_OK > status) { KIM_API_report_error(__LINE__, __FILE__, "KIM_API_get_num_free_params", status); return(status); } /* get the descriptor file, pointed by pstr. the type of data will be phrased from pstr*/ status = KIM_API_get_model_kim_str(g_kim.kim_model_name, &pstr); if (KIM_STATUS_OK > status) { KIM_API_report_error(__LINE__, __FILE__, "KIM_API_get_model_kim_str", status); return(status); } /* infinite loop to find PARAM_FREE_* of type `double' */ /* It's safe to do pstr = strstr(pstr+1,"PARAM_FREE") because the ``PARAM_FREE'' will never ever occur at the beginning of the ``descriptor.kim'' file */ FreeParam->name = NULL; NumFreeParamDouble = 0; while (1) { pstr = strstr(pstr+1,"PARAM_FREE"); if (pstr == NULL) { break; } else { snprintf(buffer, sizeof(buffer), "%s", pstr); sscanf(buffer, "%s%s", name, type); if (strcmp(type, "double") == 0) { NumFreeParamDouble++; FreeParam->name = (char**) Realloc(FreeParam->name, (NumFreeParamDouble)*sizeof(char*)); /*maxStringLength+1 to hold the `\0' at end*/ FreeParam->name[NumFreeParamDouble - 1] = (char*) Malloc((maxStringLength+1)*sizeof(char)); strcpy(FreeParam->name[NumFreeParamDouble - 1], name); } } } FreeParam->Nparam = NumFreeParamDouble; /* allocate memory for value */ FreeParam->value = (double**) Malloc(FreeParam->Nparam * sizeof(double*)); /* get the pointer to parameter */ for(i = 0; i < FreeParam->Nparam; i++ ) { FreeParam->value[i] = KIM_API_get_data(pkim, FreeParam->name[i], &status); if (KIM_STATUS_OK > status) { KIM_API_report_error(__LINE__, __FILE__, "KIM_API_get_data", status); return(status); } } /* allocate memory for rank */ FreeParam->rank = (int*) Malloc(FreeParam->Nparam * sizeof(int)); /* get rank */ for(i = 0; i < FreeParam->Nparam; i++) { FreeParam->rank[i] = KIM_API_get_rank(pkim, FreeParam->name[i], &status); if (KIM_STATUS_OK > status) { KIM_API_report_error(__LINE__, __FILE__, "KIM_API_get_rank", status); return(status); } } /* allocate memory for shape */ FreeParam->shape = (int**) Malloc(FreeParam->Nparam * sizeof(int*)); for (i = 0; i < FreeParam->Nparam; i++) { if (FreeParam->rank[i] != 0) { FreeParam->shape[i] = (int*) Malloc(FreeParam->rank[i] * sizeof(int)); } } /* get shape */ for(i = 0; i < FreeParam->Nparam; i++) { KIM_API_get_shape(pkim, FreeParam->name[i], FreeParam->shape[i], &status); if (KIM_STATUS_OK > status) { KIM_API_report_error(__LINE__, __FILE__, "KIM_API_get_shape", status); return(status); } } /* nestedvalue is not allocated here, give NULL pointer to it */ FreeParam->nestedvalue = NULL; /* free the memory of model kim str */ free(pstr); return KIM_STATUS_OK; }
int get_neigh(void* kimmdl, int *mode, int *request, int* part, int* numnei, int** nei1part, double** Rij) { /* local variables */ intptr_t* pkim = *((intptr_t**) kimmdl); int partToReturn; int status; int* numberOfParticles; int idx; /* index of first neighbor of each particle*/ NeighObjectType* nl; /* initialize numnei */ *numnei = 0; /* unpack neighbor list object */ numberOfParticles = (int*) KIM_API_get_data(pkim, "numberOfParticles", &status); if (KIM_STATUS_OK > status) { KIM_API_report_error(__LINE__, __FILE__,"get_data", status); } nl = (NeighObjectType*) KIM_API_get_data(pkim, "neighObject", &status); if (KIM_STATUS_OK > status) { KIM_API_report_error(__LINE__, __FILE__,"get_data", status); } /* check mode and request */ if (0 == *mode) { /* iterator mode */ if (0 == *request) { /* reset iterator */ (*nl).iteratorId = -1; return KIM_STATUS_NEIGH_ITER_INIT_OK; } else if (1 == *request) { /* increment iterator */ (*nl).iteratorId++; if ((*nl).iteratorId >= *numberOfParticles) { return KIM_STATUS_NEIGH_ITER_PAST_END; } else { partToReturn = (*nl).iteratorId; } } else { /* invalid request value */ KIM_API_report_error(__LINE__, __FILE__,"Invalid request in get_periodic_neigh", KIM_STATUS_NEIGH_INVALID_REQUEST); return KIM_STATUS_NEIGH_INVALID_REQUEST; } } else if (1 == *mode) { /* locator mode */ if ((*request >= *numberOfParticles) || (*request < 0)) { /* invalid id */ KIM_API_report_error(__LINE__, __FILE__,"Invalid part ID in get_periodic_neigh", KIM_STATUS_PARTICLE_INVALID_ID); return KIM_STATUS_PARTICLE_INVALID_ID; } else { partToReturn = *request; } } else { /* invalid mode */ KIM_API_report_error(__LINE__, __FILE__,"Invalid mode in get_periodic_neigh", KIM_STATUS_NEIGH_INVALID_MODE); return KIM_STATUS_NEIGH_INVALID_MODE; } /* index of the first neigh of each particle */ idx = (*nl).BeginIdx[partToReturn]; /* set the returned part */ *part = partToReturn; /* set the returned number of neighbors for the returned part */ *numnei = (*nl).NNeighbors[partToReturn]; /* set the location for the returned neighbor list */ *nei1part = &(*nl).neighborList[idx]; /* set the pointer to Rij to appropriate value */ *Rij = &(*nl).RijList[DIM*idx]; return KIM_STATUS_OK; }