diff --git a/src/userInputParameters/load_BC_list.cc b/src/userInputParameters/load_BC_list.cc index bf423507f..13cc3b67b 100644 --- a/src/userInputParameters/load_BC_list.cc +++ b/src/userInputParameters/load_BC_list.cc @@ -1,24 +1,31 @@ +// ------------------------------------------------------------------------ +// Method to extract the list of boundary conditions from input parameters +// and store them in BC_list object +// ------------------------------------------------------------------------ + +#include + #include "../../include/userInputParameters.h" -// ========================================================================================== -// Method to extract the list of boundary conditions -// ========================================================================================== template void userInputParameters::load_BC_list(std::vector list_of_BCs) { - // Load the BC information from the strings into a varBCs object - // Move this to a new method and write a unit test for it!!!! - + // Loop over the list of boundary conditions specified in parameters + // and provided in the input list_of_BCs. Process the BCs and place + // them into the vector BC_list std::vector temp; - for (unsigned int i = 0; i < list_of_BCs.size(); i++) { + // Ensure all variables have BCs specified in parameters.prm + AssertThrow(!list_of_BCs[i].empty(), + dealii::ExcMessage(std::string("Boundary condition not specified."))); + varBCs newBC; temp = dealii::Utilities::split_string_list(list_of_BCs[i]); - // If there is only one BC listed, make another dim*2-1 copies of it so - // that the same BC is applied for all boundaries + // If there is only one BC listed, make another dim*2-1 copies of it so that + // the same BC is applied for all boundaries if (temp.size() == 1) { for (unsigned int boundary = 0; boundary < (dim * 2 - 1); boundary++) @@ -27,76 +34,64 @@ userInputParameters::load_BC_list(std::vector list_of_BCs) } } - // Load the BC for each boundary into 'newBC' - for (unsigned int i = 0; i < (2 * dim); i++) + // Load the BC for each boundary into 'newBC'. + for (unsigned int j = 0; j < (2 * dim); j++) { - if (boost::iequals(temp[i], "NATURAL")) + if (boost::iequals(temp[j], "NATURAL")) { newBC.var_BC_type.push_back(NATURAL); newBC.var_BC_val.push_back(0.0); } - else if (boost::iequals(temp[i], "PERIODIC")) + else if (boost::iequals(temp[j], "PERIODIC")) { newBC.var_BC_type.push_back(PERIODIC); newBC.var_BC_val.push_back(0.0); } - else if (boost::iequals(temp[i], "NON_UNIFORM_DIRICHLET")) + else if (boost::iequals(temp[j], "NON_UNIFORM_DIRICHLET")) { newBC.var_BC_type.push_back(NON_UNIFORM_DIRICHLET); newBC.var_BC_val.push_back(0.0); } - else if (boost::iequals(temp[i].substr(0, 9), "DIRICHLET")) + else if (boost::iequals(temp[j].substr(0, 9), "DIRICHLET")) { newBC.var_BC_type.push_back(DIRICHLET); - std::string dirichlet_val = temp[i].substr(10, temp[i].size()); + std::string dirichlet_val = temp[j].substr(10, temp[j].size()); dirichlet_val = dealii::Utilities::trim(dirichlet_val); newBC.var_BC_val.push_back( dealii::Utilities::string_to_double(dirichlet_val)); } - else if (boost::iequals(temp[i].substr(0, 7), "NEUMANN")) + else if (boost::iequals(temp[j].substr(0, 7), "NEUMANN")) { newBC.var_BC_type.push_back(NEUMANN); - std::string neumann_val = temp[i].substr(8, temp[i].size()); + std::string neumann_val = temp[j].substr(8, temp[j].size()); neumann_val = dealii::Utilities::trim(neumann_val); newBC.var_BC_val.push_back( dealii::Utilities::string_to_double(neumann_val)); } else { - std::cout << temp[i].substr(0, 8) << std::endl; + std::cout << temp[j].substr(0, 8) << std::endl; std::cout << "Error: Boundary conditions specified improperly." << std::endl; abort(); } + + // If periodic BCs are used, ensure they are applied on both sides of + // domain + if (j % 2 == 0) + { + AssertThrow(!((boost::iequals(temp[j], "PERIODIC") && + !boost::iequals(temp[j + 1], "PERIODIC")) || + (!boost::iequals(temp[j], "PERIODIC") && + boost::iequals(temp[j + 1], "PERIODIC"))), + dealii::ExcMessage( + std::string("Periodic boundary condition must be " + "specified on both sides of domain"))); + } } + // Append BCs for current field to total list BC_list.push_back(newBC); - - // Validate input using something like this: - // try{ - // if ((BC_type_dim1_min == "PERIODIC") && (BC_type_dim1_max != - // "PERIODIC")){ - // throw 0; - // } - // if ((BC_type_dim2_min == "PERIODIC") && (BC_type_dim2_max != - // "PERIODIC")){ - // throw 0; - // } - // if ((BC_type_dim3_min == "PERIODIC") && (BC_type_dim3_max != - // "PERIODIC")){ - // throw 0; - // } - // } - // catch (int e){ - // if (e == 0){ - // std::cout << "Error: For periodic BCs, both faces for a given - // direction must be set as periodic. " - // "Please check the BCs that are set in ICs_and_BCs.h." - // << std::endl; - // } - // abort(); - // } } } -// Template instantiations -#include "../../include/userInputParameters_template_instantiations.h" +#include "../../include/userInputParameters_template_instantiations.h" \ No newline at end of file