Commit 6a5902ec authored by Ryan S. Elliott's avatar Ryan S. Elliott
Browse files

Update kim_init to use KIM::Collections::GetItemType()

A bit of a cleaner solution.  Should be no visible change for users.
parent 010cb0ed
Loading
Loading
Loading
Loading
+63 −43
Original line number Diff line number Diff line
@@ -164,10 +164,26 @@ void KimInit::determine_model_type_and_units(char * model_name,
  KIM_TemperatureUnit temperatureUnit;
  KIM_TimeUnit timeUnit;
  int units_accepted;
  KIM_Model * kim_MO;
  KIM_Collections * kim_Coll;
  KIM_CollectionItemType itemType;

  int kim_error = KIM_Collections_Create(&kim_Coll);
  if (kim_error) {
    error->all(FLERR,"Unable to access KIM Collections to find Model.");
  }

  kim_error = KIM_Collections_GetItemType(kim_Coll, model_name, &itemType);
  if (kim_error) {
    error->all(FLERR,"KIM Model name not found.");
  }
  KIM_Collections_Destroy(&kim_Coll);

  if (KIM_CollectionItemType_Equal(itemType,
                                   KIM_COLLECTION_ITEM_TYPE_portableModel))
  {
    get_kim_unit_names(user_units, lengthUnit, energyUnit,
                       chargeUnit, temperatureUnit, timeUnit, error);
    KIM_Model * kim_MO;
    int kim_error = KIM_Model_Create(KIM_NUMBERING_zeroBased,
                                     lengthUnit,
                                     energyUnit,
@@ -178,7 +194,9 @@ void KimInit::determine_model_type_and_units(char * model_name,
                                     &units_accepted,
                                     &kim_MO);

  if (!kim_error) { // model is an MO
    if (kim_error)
      error->all(FLERR,"Unable to load KIM Simulator Model.");

    model_type = MO;
    KIM_Model_Destroy(&kim_MO);

@@ -213,11 +231,12 @@ void KimInit::determine_model_type_and_units(char * model_name,
      error->all(FLERR,"KIM Model does not support the requested unit system");
    }
  }

  else if (KIM_CollectionItemType_Equal(
               itemType, KIM_COLLECTION_ITEM_TYPE_simulatorModel)) {
    KIM_SimulatorModel * kim_SM;
    kim_error = KIM_SimulatorModel_Create(model_name, &kim_SM);
    if (kim_error)
    error->all(FLERR,"KIM model name not found");
      error->all(FLERR,"Unable to load KIM Simulator Model.");
    model_type = SM;

    int sim_fields;
@@ -246,6 +265,7 @@ void KimInit::determine_model_type_and_units(char * model_name,
      error->all(FLERR,mesg.c_str());
    }
  }
}


/* ---------------------------------------------------------------------- */