% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/MCIS_helpers.R
\name{build_gsys}
\alias{build_gsys}
\title{Build a smooth system limit-state function (g_sys)}
\usage{
build_gsys(
  sys_input,
  sys_structure = "serial",
  smooth_kappa = 20,
  debug.level = 0
)
}
\arguments{
\item{sys_input}{List of \code{SYS_LSF} objects defining the component
limit-state functions of the system.}

\item{sys_structure}{System aggregation structure.
Supported options are
\describe{
  \item{\code{"serial"}}{System fails if any component fails.}
  \item{\code{"parallel"}}{System fails only if all components fail.}
  \item{\code{function(g_vals)}}{Custom aggregation function applied
  to the vector of component limit-state values.}
}}

\item{smooth_kappa}{Positive numeric value controlling the smoothness
of the aggregation. Larger values approach the exact \code{min}
or \code{max} operator.}

\item{debug.level}{Optional verbosity level for diagnostic output.}
}
\value{
A list containing:
\describe{
  \item{\code{g_sys}}{Callable system limit-state function
  \code{function(x)} operating on the global variable vector.}

  \item{\code{distr_flat}}{Flattened list of marginal distribution
  objects corresponding to all variables in the system.}

  \item{\code{var_map}}{List mapping each limit-state function to the
  indices of its variables in the global vector.}

  \item{\code{n_vars}}{Total number of basic variables in the system.}

  \item{\code{n_lsfs}}{Number of limit-state functions.}
}
}
\description{
Constructs a **global system limit-state function** from a list of
individual limit-state functions (`SYS_LSF` objects). The resulting
function aggregates all component limit states using a **smooth
approximation** of the minimum or maximum operator.
}
\details{
The smooth aggregation improves numerical stability and differentiability,
which is beneficial for gradient-based reliability methods such as
FORM, SORM, and importance sampling algorithms.

For a serial system the aggregation is

\deqn{
g_{\kappa}(x) =
-\frac{1}{\kappa}\log
\left(
\sum_{i=1}^{m} \exp(-\kappa g_i(x))
\right)
}

which approximates

\deqn{
\min_i g_i(x).
}

For a parallel system the aggregation is

\deqn{
g_{\kappa}(x) =
\frac{1}{\kappa}\log
\left(
\sum_{i=1}^{m} \exp(\kappa g_i(x))
\right)
}

which approximates

\deqn{
\max_i g_i(x).
}

The approximation becomes exact for
\eqn{\kappa \rightarrow \infty}.

In addition to the system function, this helper also constructs a
**flattened list of marginal distributions** and a **variable index map**
that links the global variable vector to the variables of each
individual limit-state function.


This function is primarily used internally by reliability algorithms
that operate on a **single limit-state function**, such as
importance sampling or crude Monte Carlo simulation.

By constructing a smooth global limit-state function, the system
reliability problem can be treated as a standard single-LSF problem,
enabling the reuse of algorithms originally developed for
component reliability.
}
\seealso{
\code{smooth_min}, \code{smooth_max},
\code{\link{MC_IS}}, \code{\link{SYS_LSF}}
}
\author{
(C) 2021-2026 K. Nille-Hauf, T. Feiri, M. Ricker, T. Lux -
Hochschule Biberach (until 2022),
TU Dortmund University - Chair of Structural Concrete (since 2023)
}
\keyword{internal}
