Esempio n. 1
0
std::unique_ptr<FluidProperties> createFluidProperties(
    BaseLib::ConfigTree const& config)
{
    //! \ogs_file_param{material__fluid__density}
    auto const& rho_conf = config.getConfigSubtree("density");
    auto liquid_density = MaterialLib::Fluid::createFluidDensityModel(rho_conf);

    //! \ogs_file_param{material__fluid__viscosity}
    auto const& mu_conf = config.getConfigSubtree("viscosity");
    auto viscosity = MaterialLib::Fluid::createViscosityModel(mu_conf);
    const bool is_mu_density_dependent =
        (viscosity->getName().find("density dependent") != std::string::npos);

    bool is_cp_density_dependent = false;
    std::unique_ptr<MaterialLib::Fluid::FluidProperty> specific_heat_capacity =
        nullptr;
    auto heat_capacity__opt_conf =
        //! \ogs_file_param{material__fluid__specific_heat_capacity}
        config.getConfigSubtreeOptional("specific_heat_capacity");
    if (heat_capacity__opt_conf)
    {
        const auto& heat_capacity_conf = *heat_capacity__opt_conf;
        specific_heat_capacity =
            createSpecificFluidHeatCapacityModel(heat_capacity_conf);
        is_cp_density_dependent =
            (specific_heat_capacity->getName().find("density dependent") !=
             std::string::npos);
    }

    bool is_KT_density_dependent = false;
    std::unique_ptr<MaterialLib::Fluid::FluidProperty> thermal_conductivity =
        nullptr;
    auto const& thermal_conductivity_opt_conf =
        //! \ogs_file_param{material__fluid__thermal_conductivity}
        config.getConfigSubtreeOptional("thermal_conductivity");
    if (thermal_conductivity_opt_conf)
    {
        auto const& thermal_conductivity_conf = *thermal_conductivity_opt_conf;
        thermal_conductivity =
            MaterialLib::Fluid::createFluidThermalConductivityModel(
                thermal_conductivity_conf);
        is_KT_density_dependent =
            (specific_heat_capacity->getName().find("density dependent") !=
             std::string::npos);
    }

    if (is_mu_density_dependent || is_cp_density_dependent ||
        is_KT_density_dependent)
        return std::make_unique<
            MaterialLib::Fluid::FluidPropertiesWithDensityDependentModels>(
            std::move(liquid_density), std::move(viscosity),
            std::move(specific_heat_capacity), std::move(thermal_conductivity),
            is_mu_density_dependent, is_cp_density_dependent,
            is_KT_density_dependent);

    return std::make_unique<
        MaterialLib::Fluid::PrimaryVariableDependentFluidProperties>(
        std::move(liquid_density), std::move(viscosity),
        std::move(specific_heat_capacity), std::move(thermal_conductivity));
}
Esempio n. 2
0
ProjectData::ProjectData(BaseLib::ConfigTree const& project_config,
                         std::string const& project_directory,
                         std::string const& output_directory)
{
    std::string const geometry_file = BaseLib::copyPathToFileName(
        //! \ogs_file_param{prj__geometry}
        project_config.getConfigParameter<std::string>("geometry"),
        project_directory);
    detail::readGeometry(geometry_file, *_geoObjects);

    {
        //! \ogs_file_param{prj__mesh}
        auto const mesh_param = project_config.getConfigParameter("mesh");

        std::string const mesh_file = BaseLib::copyPathToFileName(
            mesh_param.getValue<std::string>(), project_directory);

        MeshLib::Mesh* const mesh = MeshLib::IO::readMeshFromFile(mesh_file);
        if (!mesh)
        {
            OGS_FATAL("Could not read mesh from \'%s\' file. No mesh added.",
                      mesh_file.c_str());
        }

        if (auto const axially_symmetric =
                //! \ogs_file_attr{prj__mesh__axially_symmetric}
            mesh_param.getConfigAttributeOptional<bool>("axially_symmetric"))
        {
            mesh->setAxiallySymmetric(*axially_symmetric);
        }
        _mesh_vec.push_back(mesh);
    }

    //! \ogs_file_param{prj__curves}
    parseCurves(project_config.getConfigSubtreeOptional("curves"));

    //! \ogs_file_param{prj__parameters}
    parseParameters(project_config.getConfigSubtree("parameters"));

    //! \ogs_file_param{prj__process_variables}
    parseProcessVariables(project_config.getConfigSubtree("process_variables"));

    //! \ogs_file_param{prj__processes}
    parseProcesses(project_config.getConfigSubtree("processes"),
                   project_directory, output_directory);

    //! \ogs_file_param{prj__linear_solvers}
    parseLinearSolvers(project_config.getConfigSubtree("linear_solvers"));

    //! \ogs_file_param{prj__nonlinear_solvers}
    parseNonlinearSolvers(project_config.getConfigSubtree("nonlinear_solvers"));

    //! \ogs_file_param{prj__time_loop}
    parseTimeLoop(project_config.getConfigSubtree("time_loop"),
                  output_directory);
}
void createSecondaryVariables(
    BaseLib::ConfigTree const& config,
    SecondaryVariableCollection& secondary_variables,
    NumLib::NamedFunctionCaller& named_function_caller)
{
    auto sec_vars_config =
        //! \ogs_file_param{prj__processes__process__secondary_variables}
        config.getConfigSubtreeOptional("secondary_variables");
    if (!sec_vars_config)
        return;

    for (
        auto sec_var_config :
        //! \ogs_file_param{prj__processes__process__secondary_variables__secondary_variable}
        sec_vars_config->getConfigSubtreeList("secondary_variable"))
    {
        auto const type =
            //! \ogs_file_attr{prj__processes__process__secondary_variables__secondary_variable__type}
            sec_var_config.getConfigAttribute<std::string>("type");

        auto const internal_name =
            //! \ogs_file_attr{prj__processes__process__secondary_variables__secondary_variable__internal_name}
            sec_var_config.getConfigAttribute<std::string>("internal_name");
        auto const output_name =
            //! \ogs_file_attr{prj__processes__process__secondary_variables__secondary_variable__output_name}
            sec_var_config.getConfigAttribute<std::string>("output_name");

        secondary_variables.addNameMapping(internal_name, output_name);

        if (type == "static")
        {
            // alright
        }
        else if (type == "dynamic")
        {
            auto const& sink_fct = internal_name;

            for (
                auto const plug :
                //! \ogs_file_param{prj__processes__process__secondary_variables__secondary_variable__plug}
                sec_var_config.getConfigParameterList("plug"))
            {
                auto const sink_arg =
                    //! \ogs_file_attr{prj__processes__process__secondary_variables__secondary_variable__plug__sink_arg}
                    plug.getConfigAttribute<std::string>("sink_arg");
                auto const source_fct =
                    //! \ogs_file_attr{prj__processes__process__secondary_variables__secondary_variable__plug__source_fct}
                    plug.getConfigAttribute<std::string>("source_fct");

                named_function_caller.plug(sink_fct, sink_arg, source_fct);
            }
        }
    }
}
std::unique_ptr<Process> createGroundwaterFlowProcess(
    MeshLib::Mesh& mesh,
    Process::NonlinearSolver& nonlinear_solver,
    std::unique_ptr<Process::TimeDiscretization>&& time_discretization,
    std::vector<ProcessVariable> const& variables,
    std::vector<std::unique_ptr<ParameterBase>> const& parameters,
    BaseLib::ConfigTree const& config)
{
    //! \ogs_file_param{process__type}
    config.checkConfigParameter("type", "GROUNDWATER_FLOW");

    DBUG("Create GroundwaterFlowProcess.");

    // Process variable.
    auto process_variables = findProcessVariables(
        variables, config,
        {//! \ogs_file_param_special{process__GROUNDWATER_FLOW__process_variables__process_variable}
         "process_variable"});

    // Hydraulic conductivity parameter.
    auto& hydraulic_conductivity = findParameter<double,
                                                 MeshLib::Element const&>(
        config,
        //! \ogs_file_param_special{process__GROUNDWATER_FLOW__hydraulic_conductivity}
        "hydraulic_conductivity",
        parameters);

    DBUG("Use \'%s\' as hydraulic conductivity parameter.",
         hydraulic_conductivity.name.c_str());

    GroundwaterFlowProcessData process_data{hydraulic_conductivity};

    SecondaryVariableCollection secondary_variables{
        //! \ogs_file_param{process__secondary_variables}
        config.getConfigSubtreeOptional("secondary_variables"),
        {//! \ogs_file_param_special{process__GROUNDWATER_FLOW__secondary_variables__darcy_velocity_x}
         "darcy_velocity_x",
         //! \ogs_file_param_special{process__GROUNDWATER_FLOW__secondary_variables__darcy_velocity_y}
         "darcy_velocity_y",
         //! \ogs_file_param_special{process__GROUNDWATER_FLOW__secondary_variables__darcy_velocity_z}
         "darcy_velocity_z"}};

    ProcessOutput
        //! \ogs_file_param{process__output}
        process_output{config.getConfigSubtree("output"), process_variables,
                       secondary_variables};

    return std::unique_ptr<Process>{new GroundwaterFlowProcess{
        mesh, nonlinear_solver, std::move(time_discretization),
        std::move(process_variables), std::move(process_data),
        std::move(secondary_variables), std::move(process_output)}};
}
Esempio n. 5
0
void EigenLinearSolver::setOption(BaseLib::ConfigTree const& option)
{
    ignoreOtherLinearSolvers(option, "eigen");
    //! \ogs_file_param{linear_solver__eigen}
    auto const ptSolver = option.getConfigSubtreeOptional("eigen");
    if (!ptSolver)
        return;

    if (auto solver_type =
            //! \ogs_file_param{linear_solver__eigen__solver_type}
            ptSolver->getConfigParameterOptional<std::string>("solver_type")) {
        _option.solver_type = _option.getSolverType(*solver_type);
    }
    if (auto precon_type =
            //! \ogs_file_param{linear_solver__eigen__precon_type}
            ptSolver->getConfigParameterOptional<std::string>("precon_type")) {
        _option.precon_type = _option.getPreconType(*precon_type);
    }
    if (auto error_tolerance =
            //! \ogs_file_param{linear_solver__eigen__error_tolerance}
            ptSolver->getConfigParameterOptional<double>("error_tolerance")) {
        _option.error_tolerance = *error_tolerance;
    }
    if (auto max_iteration_step =
            //! \ogs_file_param{linear_solver__eigen__max_iteration_step}
            ptSolver->getConfigParameterOptional<int>("max_iteration_step")) {
        _option.max_iterations = *max_iteration_step;
    }
    if (auto scaling =
            //! \ogs_file_param{linear_solver__eigen__scaling}
            ptSolver->getConfigParameterOptional<bool>("scaling")) {
#ifdef USE_EIGEN_UNSUPPORTED
        _option.scaling = *scaling;
#else
        OGS_FATAL(
            "The code is not compiled with the Eigen unsupported modules. "
            "scaling is not available.");
#endif
    }
}
Esempio n. 6
0
std::unique_ptr<Output> Output::
newInstance(const BaseLib::ConfigTree &config, std::string const& output_directory)
{
    auto const output_iteration_results =
        //! \ogs_file_param{prj__output__output_iteration_results}
        config.getConfigParameterOptional<bool>("output_iteration_results");

    std::unique_ptr<Output> out{new Output{
        BaseLib::joinPaths(output_directory,
                           //! \ogs_file_param{prj__output__prefix}
                           config.getConfigParameter<std::string>("prefix")),
        output_iteration_results ? *output_iteration_results : false}};

    //! \ogs_file_param{prj__output__timesteps}
    if (auto const timesteps = config.getConfigSubtreeOptional("timesteps"))
    {
        //! \ogs_file_param{prj__output__timesteps__pair}
        for (auto pair : timesteps->getConfigSubtreeList("pair"))
        {
            //! \ogs_file_param{prj__output__timesteps__pair__repeat}
            auto repeat     = pair.getConfigParameter<unsigned>("repeat");
            //! \ogs_file_param{prj__output__timesteps__pair__each_steps}
            auto each_steps = pair.getConfigParameter<unsigned>("each_steps");

            assert(repeat != 0 && each_steps != 0);
            out->_repeats_each_steps.emplace_back(repeat, each_steps);
        }

        if (out->_repeats_each_steps.empty()) {
            OGS_FATAL("You have not given any pair (<repeat/>, <each_steps/>) that defines"
                    " at which timesteps output shall be written. Aborting.");
        }
    }
    else
    {
        out->_repeats_each_steps.emplace_back(1, 1);
    }

    return out;
}
Esempio n. 7
0
ProcessVariable::ProcessVariable(
    BaseLib::ConfigTree const& config,
    MeshLib::Mesh& mesh,
    std::vector<std::unique_ptr<MeshLib::Mesh>> const& meshes,
    std::vector<std::unique_ptr<ParameterBase>> const& parameters)
    :  //! \ogs_file_param{prj__process_variables__process_variable__name}
      _name(config.getConfigParameter<std::string>("name")),
      _mesh(mesh),
      //! \ogs_file_param{prj__process_variables__process_variable__components}
      _n_components(config.getConfigParameter<int>("components")),
      //! \ogs_file_param{prj__process_variables__process_variable__order}
      _shapefunction_order(config.getConfigParameter<unsigned>("order")),
      _initial_condition(findParameter<double>(
          //! \ogs_file_param{prj__process_variables__process_variable__initial_condition}
          config.getConfigParameter<std::string>("initial_condition"),
          parameters, _n_components))
{
    DBUG("Constructing process variable %s", _name.c_str());

    if (_shapefunction_order < 1 || 2 < _shapefunction_order)
        OGS_FATAL("The given shape function order %d is not supported", _shapefunction_order);

    // Boundary conditions
    //! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions}
    if (auto bcs_config = config.getConfigSubtreeOptional("boundary_conditions"))
    {
        for (auto bc_config :
             //! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions__boundary_condition}
             bcs_config->getConfigSubtreeList("boundary_condition"))
        {
            auto const& mesh = findMeshInConfig(bc_config, meshes);
            auto component_id =
                //! \ogs_file_param{prj__process_variables__process_variable__boundary_conditions__boundary_condition__component}
                bc_config.getConfigParameterOptional<int>("component");

            if (!component_id && _n_components == 1)
                // default value for single component vars.
                component_id = 0;

            _bc_configs.emplace_back(std::move(bc_config), mesh, component_id);
        }
    } else {
        INFO("No boundary conditions found.");
    }

    // Source terms
    //! \ogs_file_param{prj__process_variables__process_variable__source_terms}
    if (auto sts_config = config.getConfigSubtreeOptional("source_terms"))
    {
        for (auto st_config :
             //! \ogs_file_param{prj__process_variables__process_variable__source_terms__source_term}
             sts_config->getConfigSubtreeList("source_term"))
        {
            MeshLib::Mesh const& mesh = findMeshInConfig(st_config, meshes);
            auto component_id =
                //! \ogs_file_param{prj__process_variables__process_variable__source_terms__source_term__component}
                st_config.getConfigParameterOptional<int>("component");

            if (!component_id && _n_components == 1)
                // default value for single component vars.
                component_id = 0;

            _source_term_configs.emplace_back(std::move(st_config), mesh,
                                              component_id);
        }
    } else {
        INFO("No source terms found.");
    }
}