Entries for 2018

  1. Portrait of Onur Solmaz
    Onur Solmaz · Post · /2018/10/18

    The Anatomy of a Block Stuffing Attack

    Block stuffing is a type of attack in blockchains where an attacker submits transactions that deliberately fill up the block’s gas limit and stall other transactions. To ensure inclusion of their transactions by miners, the attacker can choose to pay higher transaction fees. By controlling the amount of gas spent by their transactions, the attacker can influence the number of transactions that get to be included in the block.

    To control the amount of gas spent by the transaction, the attacker utilizes a special contract. There is a function in the contract which takes as input the amount of gas that the attacker wants to burn. The function runs meaningless instructions in a loop, and either returns or throws an error when the desired amount is burned.

    For example let’s say that the average gas price has been 5 Gwei in the last 10 blocks. In order to exert influence over the next block, the attacker needs to submit transactions with gas prices higher than that, say 100 Gwei. The higher the gas price, the higher the chance of inclusion by miners. The attacker can choose to divide the task of using 8,000,000 gas—current gas limit for blocks—into as many transactions as they want. This could be 80 transactions with 100,000 gas expenditure, or 4 transactions with 2,000,000 gas expenditure.

    Deciding on how to divide the task is a matter of maximizing the chance of inclusion, and depends on the factors outline below.

    Miners’ strategy for selecting transactions

    Miners want to maximize their profit by including transactions with highest fees. In the current PoW implementation of Ethereum, mining the block takes significantly more time than executing the transactions. So let’s assume all transactions in the pool are trivially executed as soon as they arrive and miners know the amount of gas each one uses.

    For miners, maximizing profit is an optimum packing problem. Miners want to choose a subset of the transaction pool that gives them maximum profit per block. Since there are at least tens of thousands of transactions in the pool at any given time, the problem can’t be solved by brute-forcing every combination. Miners use algorithms that test a feasible number of combinations and select the one giving the highest reward.

    A block stuffer’s main goal is to target the selection process by crafting a set of transactions that has the highest chance of being picked up by miners in a way that will deplete blocks’ gas limits. They can’t devise a 100% guaranteed strategy since each miner can use a different algorithm, but they can find a sweet spot by testing out the whole network.

    (In a PoS system, our assumptions would be wrong since executing transactions is not trivial compared to validating blocks. Validators would need to develop more complex strategies depending on the PoS implementation.)

    The transactions the attacker wants to stall:

    It could be so that the attacker wants to stall transactions with a specific contract. If the function calls to that contract use a distinctively high amount of gas, say between 300,000 and 500,000, then the attacker has to stuff the block in a way that targets that range.

    For example, the attacker can periodically submit $n$ transactions $\{T_1, T_2,\dots, T_{n-1}, T_n\}$ with very high prices where

    \[\sum\limits_{i=1}^{n} T_i^{\text{gas}} \approx 8,000,000.\]

    If the attacker is targeting transactions within a range of $(R_\text{lower}, R_\text{upper})$, they can choose the first $n-1$ transactions to deplete $8,000,000 - R_\text{upper}$ gas in short steps, and submit $T_n$ to deplete the remaining $R_\text{upper}$ gas with a relatively higher price. Note that the revenue from including a single transaction is

    \[\text{tx_fee} = \text{gas_price} \times \text{gas_usage}.\]

    As gas usage decreases, the probability of being picked up by miners decreases, so prices should increase to compensate.

    Example: Fomo3D

    Fomo3D is a gambling game where players buy keys from a contract and their money goes into a pot. At the beginning of each round, a time counter is initiated which starts counting back from 24 hours. Each bought key adds 30 seconds to the counter. When the counter hits 0, the last player to have bought a key wins the majority of the pot and the rest is distributed to others. The way the pot is distributed depends on the team that the winner belongs to.

    Key price increases with increasing key supply, which makes it harder and harder to buy a key and ensures the round will end after some point. In time, the stakes increase and the counter reduces to a minimum, like 2 minutes. At this point, the players pay both high gas and key prices to be “it” and win the game. Players program bots to buy keys for them, and winning becomes a matter of coding the right strategy. As you can understand from the subject, the first round was won through a block stuffing attack.

    On August 22 2018, the address 0xa16…f85 won 10,469 ETH from the first round by following the strategy I outlined above. The winner managed to be the last buyer in block 6191896 and managed to stall transactions with Fomo3D until block 6191909 for 175 seconds, ending the round. Some details:

    The user addresses above were scraped from the Ethereum transaction graph as being linked to a primary account which supplied them with funds. The contract addresses were scraped from 0-valued transactions sent from user addresses. These have a distance of 1, there may be other addresses involved with greater distances.

    Below are details of the last 4 blocks preceding the end of the round. The rows highlighted with yellow are transactions submitted by the attacker. The crossed out rows are failed transactions. All transactions by the attacker were submitted with a 501 Gwei gas price, and stuffing a single block costed around 4 ETH. The calls to buy keys generally spend around 300,000~500,000 gas, depending on which function was called. Below, you see the successfully stuffed block 6191906.

    Block 6191906
    Idx From To Hash ETH sent Gas Price
    [Gwei]
    Gas Limit Gas Used ETH spent
    on gas
    0 0xF03…1f2 0x18e…801 0xb97…8e4 0 501.0 4,200,000 4,200,000 2.1042
    1 0x87C…4eF 0x18e…801 0x96f…1b0 0 501.0 3,600,000 3,600,000 1.8036
    2 0xf6E…059 0x18e…801 0x897…2b3 0 501.0 200,000 200,000 0.1002
    Sum 0 1503.01 8,000,000 8,000,000 4.0080

    Block 6191907 was a close call for the winner, because their transactions picked up for the block did not amount up to 8,000,000 and the other transaction was a call to Fomo3D by an opponent to buy keys. Note that it has a gas price of 5559 Gwei, which means either the bot or person who submitted the transaction was presumably aware of the attack. The transaction failed due to low gas limit, presumably due to a miscalculation by the bot or the person.

    Block 6191907
    Idx From To Hash ETH sent Gas Price
    [Gwei]
    Gas Limit Gas Used ETH spent
    on gas
    0 0x32A…370 0xA62…Da1 0x5e7…be1 0.0056 5559.7 379,000 379,000 2.1071
    1 0xC6A…3E2 0x18e…801 0xb8b…40c 0 501.0 3,900,000 3,900,000 1.9539
    2 0xD27…642 0x18e…801 0xbcf…c62 0 501.0 3,300,000 3,300,000 1.6533
    3 0x00c…776 0x18e…801 0xf30…337 0 501.0 400,000 400,000 0.2004
    Sum 0.0056 7062.71 7,979,000 7,979,000 5.9147

    Transactions in block 6191908 belonged to the attacker except for one irrelevant transfer. This block is also considered successfully stuffed, since the 7,970,000 gas usage by the attacker leaves no space for a call to buy keys.

    Block 6191908
    Idx From To Hash ETH sent Gas Price
    [Gwei]
    Gas Limit Gas Used ETH spent
    on gas
    0 0xD27…642 0x18e…801 0x74a…9b1 0 501.0 3,300,000 3,300,000 1.6533
    1 0x7Dd…c4c 0x18e…801 0x48c…222 0 501.0 2,700,000 2,700,000 1.3527
    2 0x3C3…f27 0x18e…801 0x01b…4aa 0 501.0 1,800,000 1,800,000 0.9018
    3 0xa94…eb8 0x18e…801 0x776…d43 0 501.0 170,000 170,000 0.0851
    4 0xbFd…1b4 0x663…d31 0x3a6…ba1 0.05 100.0 21,000 21,000 0.0021
    Sum 0.05 2104.01 7,991,000 7,991,000 3.9950

    By block 6191909, the counter has struck zero—more like current UTC time surpassed the round end variable stored in the contract—and any call to Fomo3D would be the one to end the round and distribute the pot. And the first transaction in the block is—wait for it—a call to Fomo3D to buy keys by the opponent whose transaction failed a few blocks earlier, submitted with 5562 Gwei. So the guy basically paid 1.7 ETH to declare the attacker the winner!

    Block 6191909
    Idx From To Hash ETH sent Gas Price
    [Gwei]
    Gas Limit Gas Used ETH spent
    on gas
    0 0x32A…370 0xA62…Da1 0xa14…012 0.0056 5562.2 379,000 304,750 1.6950
    1 0xC96…590 0x18e…801 0xf47…9ca 0 501.0 2,200,000 37,633 0.0188
    2 0xb1D…aEF 0x18e…801 0xe4c…edb 0 501.0 1,400,000 37,633 0.0188
    3 0x18D…A9A 0x18e…801 0xf3a…995 0 501.0 800,000 37,633 0.0188

    Another thing to note is that the attacker probably crafted the spender contract to stop the attack when the round has ended, presumably to cut costs. So the 37,633 gas used by the contract are probably to call the Fomo3D contract to check round status. All these point out to the fact that the attacker is an experienced programmer who knows their way around Ethereum.

    Here, you can see the details of the 100 blocks preceding the end of the round, with the additional information of ABI calls and events fired in transactions.

    Since the end of the first round, 2 more rounds ended with attacks similar to this one. I didn’t analyze all of them because it’s too much for this post, but here are some details if you want to do it yourselves.

    Round Address winning the pot Winner’s last tx before the end of the round Block containing that tx Tx ending the round Block containing that tx Tx where winner withdraws prize Amount won [ETH] Contract used for block stuffing
    1 0xa169df5ed3363cfc4c92ac96c6c5f2a42fccbf85 0x7a06d9f11e650fbb2061b320442e26b4a704e1277547e943d73e5b67eb49c349 6191896 0xa143a1ee36e1065c3388440ef7e7b38ed41925ca4799c8a4d429fa3ee1966012 6191909 0xe08a519c03cb0aed0e04b33104112d65fa1d3a48cd3aeab65f047b2abce9d508 10,469 0x18e1b664c6a2e88b93c1b71f61cbf76a726b7801
    2 0x18a0451ea56fd4ff58f59837e9ec30f346ffdca5 0x0437885fa741f93acfdcda9f5a2e673bb16d26dd22dfc4890775efb8a94fb583 6391537 0x87bf726bc60540c6b91cc013b48024a5b8c1431e0847aadecf0e92c56f8f46fd 6391548 0x4da4052d2baffdc9c0b82d628b87d2c76368914e33799032c6966ee8a3c216a0 3,264 0x705203fc06027379681AEf47c08fe679bc4A58e1
    3 0xaf492045962428a15903625B1a9ECF438890eF92 0x88452b56e9aa58b70321ee8d5c9ac762a62509c98d9a29a4d64d6caae49ae757 6507761 0xe6a5a10ec91d12e3fec7e17b0dfbb983e00ffe93d61225735af2e1a8eabde003 6507774 0xd7e70fdf58aca40139246a324e871c84d988cfaff673c9e5f384315c91afa5e4 376 0xdcC655B2665A675B90ED2527354C18596276B0de

    A thing to note in the following rounds is that participation in the game and amount of pot gradually decreased, presumably owing to the fact that the way of beating the game has been systematized. Although anyone can attempt such an attack, knowing how it will be won takes the “fun” factor out of it.

    Credit: Although I’ve found previous instances of the term “block stuffing” online, Nic Carter is the first one to use it in this context.

  2. Portrait of Onur Solmaz
    Onur Solmaz · Post · /2018/08/03

    Mathematics of Bonding Curves

    A bonding curve is a financial instrument proposed by Simon de la Rouviere in his Medium articles. ETH is bonded in a smart contract to mint tokens, and unbonded to burn them. Every bonding and unbonding changes the price of the token according to a predefined formula. The “curves” represent the relationship between the price of a single token and the token supply. The result is an ETH-backed token that rewards early adopters.

    An example supply versus price graph. The area below the curve is equal to the amount of ETH $E$ that must be spent to increase the supply from $S_0$ to $S_1$, or that is going to be received when $S_1-S_0$ tokens are unbonded.

    Inside a transaction, the price paid/received per token is not constant and depends on the amount that is bonded or unbonded. This complicates the calculations.

    Let’s say for an initial supply of $S_0$, we want to bond $T$ tokens which are added to the new supply $S_1=S_0+T$. The ETH $E$ that must be spent for this bonding is defined as

    \[E = \int_{S_0}^{S_1} P\, dS\]

    which is illustrated in the figure above. If one wanted to unbond $T$ tokens, the upper limit for the integral would be $S_0$ and the lower $S_0-T$, with E corresponding to the amount of ETH received for the unbonding.

    Linear Curves

    A linear relationship for the bonding curves are defined as

    \[P(S) = P_0 + S I_p\]

    where $P_0$ is the initial price of the token and $I_p$ is the price increment per token.

    Bonding Tokens

    Let us have $E$ ETH which we want to bond tokens with. Substituting $P$ into the integral above with the limits $S_0\to S_0+T$, we obtain $E$ in terms of the tokens $T$ that we want to bond:

    \[E(S, T) = T P_0 + T I_p S + \frac{1}{2} T^2 I_p\]

    where $S$ is the supply before the bonding. Solving this for $T$, we obtain the tokens received in a bonding as a function of the supply and ETH spent:

    \[\boxed{T(S, E) = \frac{\sqrt{S^2I_p^2 + 2E I_p + 2 S P_0 I_p + P_0^2}-P_0}{I_p} - S.}\]

    Unbonding Tokens

    Let us have T tokens which we want to unbond for ETH. Unbonding $T$ tokens decreases the supply from $S_0$ to $S_0-T$, which we apply as limits for the above integral and obtain:

    \[\boxed{E(S, T) = T P_0 + T I_p S - \frac{1}{2} T^2 I_p.}\]

    Breaking Even in PoWH3D

    PoWH3D is one of the applications of bonding curves with a twist: 1/10th of every transaction is distributed among token holders as dividends. When you bond tokens with $E$ ETH, you receive $9/10 E$ worth of tokens and $1/10 E$ is distributed to everybody else in proportion to the amount they hold.

    This means you are at a loss when you bond P3D (the token used by PoWH3D). If you were to unbond immediately, you would only receive 81% of your money. Given the situation, one wonders when exactly one can break even with their investment. The activity in PoWH3D isn’t deterministic; nonetheless we can deduce sufficient but not necessary conditions for breaking even in PoWH3D.

    Sufficient Bonding

    Let us spend $E_1$ ETH to bond tokens at supply $S_0$. The following calculations are done with the assumption that the tokens received

    \[T_1 = T(S_0, 9E_1/10)\]

    are small enough to be neglected, that is $T_1 \ll S_0$ and $S_1 \approx S_0$. In other words, this only holds for non-whale bondings.

    Then let others spend $E_2$ ETH to bond tokens and raise the supply to $S_2$. The objective is to find an $E_2$ large enough to earn us dividends and make us break even when we unbond our tokens at $S_2$. We have

    \[S_2 = S_0 + T(S_0, E_2).\]

    Our new share of the P3D pool is $T_1/S_2$ and the dividends we earn from the bonding is equal to

    \[\frac{1}{10}\frac{T_1}{S_2}E_2.\]

    Then the condition for breaking even is

    \[\boxed{\frac{9}{10} E(S_2, T_1) + \frac{1}{10}\frac{T_1}{S_2}E_2 \geq E_1.}\]

    This inequality has a lengthy analytic solution which is impractical to typeset. The definition should be enough:

    \[E^{\text{suff}}_2(S_0, E_1) := \text{solve for $E_2$}\left\{\frac{9}{10} E(S_2, T_1) + \frac{1}{10}\frac{T_1}{S_2}E_2 = E_1\right\}\]

    and

    \[E_2 \geq E^{\text{suff}}_2.\]

    $E^{\text{suff}}_2$ can be obtained from the source of this page in JavaScript from the function sufficient_bonding. The function involves many power and square operations and may yield inexact results for too high values of $S_0$ or too small values off $E_1$, due to insufficient precision of the underlying math functions. For this reason, the calculator is disabled for sensitive input.

    $S_0$ versus $E^{\text{suff}}_2$ for $E_1 = 100$.

    The relationship between the initial supply and sufficient bonding is roughly quadratic, as seen from the graph above. This means that the difficulty of breaking even increases quadratically as more people bond into P3D. As interest in PoWH3D saturates, dividends received from the supply increase decreases quadratically.

    Logarithmic plot of $S_0$ versus $E^{\text{suff}}_2$ for changing values of $E_1$.

    The relationship is not exactly quadratic, as seen from the graph above. The function is sensitive to $E_1$ for small values of $S_0$.

    Sufficient Unbonding

    Let us spend $E_1$ ETH to bond tokens at supply $S_0$ and receive $T_1$ tokens.

    Then let others unbond $T_2$ P3D to lower the supply to $S_2$. The objective is to find a $T_2$ large enough to earn us dividends and make us break even when we unbond our tokens at $S_2$. We have

    \[S_2 = S_0 - T_2.\]

    Our new share of the P3D pool is $T_1/S_2$ and the dividends we earn from the bonding is equal to

    \[\frac{1}{10}\frac{T_1}{S_2} E(S_2, T_2)\]

    Then the condition for breaking even is

    \[\boxed{\frac{9}{10} E(S_2, T_1) + \frac{1}{10}\frac{T_1}{S_2} E(S_2, T_2) \geq E_1.}\]

    Similar to the previous section, we have

    \[T^{\text{suff}}_2(S_0, E_1) := \text{solve for $T_2$}\left\{\frac{9}{10} E(S_2, T_1) + \frac{1}{10}\frac{T_1}{S_2} E(S_2, T_2) = E_1\right\}\]

    and

    \[T_2 \geq T^{\text{suff}}_2.\]

    $T^{\text{suff}}_2$ can be obtained from the function sufficient_unbonding.

    $S_0$ versus $T^{\text{suff}}_2$ for $E_1 = 100$.

    The relationship between $S_0$ and $T^{\text{suff}}_2$ is linear and insensitive to $E_1$. Regardless of the ETH you invest, the amount of tokens that need to be unbonded to guarantee your break-even is roughly the same, depending on your entry point.

    Calculator

    Below is a calculator you can input $S_0$ and $E_1$ to calculate $E^{\text{suff}}_2$ and $T^{\text{suff}}_2$.

    $S_0$
    $E_1$
    $E^{\text{suff}}_2 $
    $T^{\text{suff}}_2 $

    For the default values above, we read this as:

    For 100 ETH worth of P3D bonded at 3,500,000 supply, either a bonding of ~31715 ETH or an unbonding of ~3336785 P3D made by other people is sufficient to break even.

    In order to follow these statistics, you can follow this site.

    Conclusion

    Bonding curve calculations can get complicated because the price paid per token depends on the amount of intended bonding/unbonding. With this work, I aimed to clarify the logic behind PoWH3D. Use the formulation and calculator at your own risk.

    The above conditions are only sufficient and not necessary to break even. As PoWH3D becomes more popular, it gets quadratically more difficult to break even from a supply increase. PoWH3D itself doesn’t generate any value or promise long-term returns for its holders. However every bond, unbond and transfer deliver dividends. According to its creators, P3D is intended to become the base token for a number of games that will be built upon PoWH3D, like FOMO3D.

  3. Portrait of Onur Solmaz
    Onur Solmaz · Post · /2018/04/24

    Lumped L2 Projection

    $ \newcommand{\rowsum}{\mathop{\rm rowsum}\nolimits} \newcommand{\nnode}{n} \newcommand{\suml}[2]{\sum\limits_{#1}^{#2}} $

    When utilizing Galerkin-type solutions for IBVPs, we often have to compute integrals using numerical methods such as Gauss quadrature. In such a solution, we solve for the values of a function at mesh nodes, whereas the integration takes place at the quadrature points. Depending on the case, we may need to compute the values of a function at mesh nodes, given their values at quadrature points, e.g. stress recovery for mechanical problems.

    There are many ways of achieving this, such as superconvergent patch recovery. In this post, I wanted to document a widely used solution which is easy to implement, and which is used in research oriented codebases such as FEAP.

    L2 Projection

    Given a function $u \in L^2(\Omega)$, its projection into a finite element space $V_h\subset L^2(\Omega)$ is defined through the following optimization problem:

    Find $u_h\in V_h$ such that

    \[\begin{equation} \Pi(u_h) := \frac{1}{2}\lVert u_h-u \rVert^2_{L^2(\Omega)} \quad\rightarrow\quad \text{min} \end{equation}\]

    There is a unique solution to the problem since $\Pi(\cdot)$ is convex. Taking its variation, we have \(\begin{equation} D \Pi(u_h) \cdot v_h = \langle u_h-u, v_h \rangle = 0 \end{equation}\)

    for all $v_h\in V_h$. Thus we have the following variational formulation

    Find $u_h\in V_h$ such that

    \[\begin{equation} \langle u_h,v_h\rangle = \langle u, v_h\rangle \end{equation}\]

    for all $v_h\in V_h$.

    Here,

    \[\begin{equation} \begin{alignedat}{3} m(u_h,v_h) &= \langle u_h,v_h\rangle && = \int_\Omega u_hv_h \,dx \quad\text{and} \\ b(v_h) &= \langle u, v_h\rangle && = \int_\Omega u v_h \,dx \end{alignedat} \end{equation}\]

    are our bilinear and linear forms respectively. Substituting FE discretizations $u_h = \sum_{J=1}^{\nnode} u^JN^J$ and $v_h = \sum_{I=1}^{\nnode} v^IN^I$, we have

    \[\begin{equation} \suml{J=1}{\nnode} M^{I\!J} u^J = b^I \label{eq:projectionsystem1} \end{equation}\]

    for $I=1,\dots,\nnode$, where the FE matrix and vector are defined as

    \[\begin{equation} \begin{alignedat}{3} M^{I\!J} &= m(N^J,N^I) &&= \int_\Omega N^JN^I \,dx \quad\text{and} \\ b^{I} &= b(N^I) &&= \int_\Omega u N^I \,dx \end{alignedat} \end{equation}\]

    Thus L2 projection requires the solution of a linear system

    \[\boldsymbol{M}\boldsymbol{u}=\boldsymbol{b}\]

    which depending on the algorithm used, can have a complexity of at least $O(n^2)$ and at most $O(n^3)$.

    Lumped L2 Projection

    The L2 projection requires the solution of a system which can be computationally expensive. It is possible to convert the matrix—called the mass matrix in literature—to a diagonal form through a procedure called lumping.

    The operator for row summation is defined as

    \[\begin{equation} \rowsum{(\cdot)}_i := \suml{j=1}{\nnode} (\cdot)_{ij} \end{equation}\]

    For the mass matrix, we have

    \[\begin{equation} \rowsum M^{I} = \suml{J=1}{\nnode} \int_\Omega N^JN^I \,dx = \int_\Omega N^I \,dx =: m^I \end{equation}\]

    since $\sum_{J=1}^{\nnode} N^J = 1$. Substituting the lumped mass matrix allows us to decouple the linear system of equations in \eqref{eq:projectionsystem1} and instead write

    \[\begin{equation} m^I u^I = b^I \end{equation}\]

    for $I=1,\dots,\nnode$. The lumped L2 projection is then as simple as

    \[\begin{equation} u^I = \frac{b^I}{m^I} = \frac{\displaystyle\int_\Omega u N^I\,dx}{\displaystyle\int_\Omega N^I \,dx} \end{equation}\]

    This results in a very efficient algorithm with $O(n)$ complexity.

    Conclusion

    Lumped L2 projection is a faster working approximation to L2 projection that is easy to implement for quick results. You can use it when developing a solution for an IBVP, and don’t want to wait too long when debugging, while not forgetting that it introduces some error.

  4. Portrait of Onur Solmaz
    Onur Solmaz · Post · /2018/04/13

    Disadvantages of Engineering Notation in Finite Elements

    Suppose we have the following stiffness matrix of linear elasticity:

    \[\begin{equation} A^{I\!J}_{ij} = \int_\Omega B^I_k \, C_{ikjl} \, B^J_l \,dv \label{eq:engnot1} \end{equation}\]

    where $\boldsymbol{B}^I = \nabla N^I$ are the gradients of the shape functions $N^I$ and $\mathbb{C}$ is the linear elasticity tensor (you see the contraction of their components in the equation).

    Despite being of the most explicit form, these types of indicial expressions are avoided in most texts on finite elements. There are two reasons for this:

    • Engineers are not taught the Einstein summation convention.
    • The presence of indices result in a seemingly cluttered expression.

    They avoid the indicial expression by reshaping it into matrix multiplications. In engineering notation, the left- and right-hand sides are reshaped as

    \[\begin{equation} A_{\alpha\beta} = \int_\Omega B_{\gamma\alpha}C_{\gamma\delta}B_{\delta\beta} \,dv \label{eq:engnot2} \end{equation}\]

    which allows us to write

    \[\begin{equation} \boldsymbol{A} = \int_\Omega \tilde{\boldsymbol{B}}^T\tilde{\boldsymbol{C}}\tilde{\boldsymbol{B}} \,dv \label{eq:engnot3} \end{equation}\]

    The matrices $\tilde{\boldsymbol{B}}$ and $\tilde{\boldsymbol{C}}$ are set on with tildes in order to differentiate them from the boldface symbols used in the previous sections. Here,

    • $\tilde{\boldsymbol{C}}$ is a matrix containing the unique components of the elasticity tensor $\mathbb{C}$, according to the Voigt notation. In this reshaping, only the minor symmetries are taken into account. If the dimension of the vectorial problem is $d$, then $\tilde{\boldsymbol{C}}$ is of the size $d(d+1)/2 \times d(d+1)/2$. For example, if the problem is 3 dimensional, $\tilde{\boldsymbol{C}}$ is of the size $6\times 6$:
    \[\begin{equation} [\tilde{\boldsymbol{C}}] = \begin{bmatrix} C_{1111} & C_{1122} & C_{1133} & C_{1112} & C_{1123} & C_{1113} \\ C_{2211} & C_{2222} & C_{2233} & C_{2212} & C_{2223} & C_{2213} \\ C_{3311} & C_{3322} & C_{3333} & C_{3312} & C_{3323} & C_{3313} \\ C_{1211} & C_{1222} & C_{1233} & C_{1212} & C_{1223} & C_{1213} \\ C_{2311} & C_{2322} & C_{2333} & C_{2312} & C_{2323} & C_{2313} \\ C_{1311} & C_{1322} & C_{1333} & C_{1312} & C_{1323} & C_{1313} \\ \end{bmatrix} \label{eq:engnotC} \end{equation}\]
    • $\tilde{\boldsymbol{B}}$ is a $nd\times d(d+1)/2$ matrix whose components are adjusted so that \eqref{eq:engnot2} is equivalent to \eqref{eq:engnot1}. It has the components of $\boldsymbol{B}^I$ for $I=1,\dots,n$ where $n$ is the number of basis functions. Since $\tilde{\boldsymbol{B}}$ is adjusted to account for the reshaping of $\mathbb{C}$, it has many zero components. A 3d example:
    \[\begin{equation} [\tilde{\boldsymbol{B}}] = \begin{bmatrix} B^1_1 & 0 & 0 & B^2_1 & 0 & 0 & \cdots & B^n_1 & 0 & 0 \\ 0 & B^1_2 & 0 & 0 & B^2_2 & 0 & \cdots & 0 & B^n_2 & 0 \\ 0 & 0 & B^1_3 & 0 & 0 & B^2_3 & \cdots & 0 & 0 & B^n_3 \\ B^1_2 & B^1_1 & 0 & B^2_2 & B^2_1 & 0 & \cdots & B^n_2 & B^n_1 & 0 \\ 0 & B^1_3 & B^1_2 & 0 & B^2_3 & B^2_2 & \cdots & 0 & B^n_3 & B^n_2 \\ B^1_3 & 0 & B^1_1 & B^2_3 & 0 & B^2_1 & \cdots & B^n_3 & 0 & B^n_1 \\ \end{bmatrix} \label{eq:engnotB} \end{equation}\]

    Although \eqref{eq:engnot3} looks nice on paper, it is much less optimal for implementation. Implementing it requires the implementation of \eqref{eq:engnotB}, which adds another layer of complexity to the algorithm. The same cannot be said for \eqref{eq:engnotC}, because using Voigt notation might be more efficient in inelastic problems. In the most complex problems, the most efficient method is to implement \eqref{eq:engnot1} in conjunction with Voigt notation.

    To prove the inefficiency of \eqref{eq:engnot3} we can readily compare it with \eqref{eq:engnot1} in terms of required number of iterations. Indices in \eqref{eq:engnot1} have the following ranges:

    \[\begin{equation} I,J = 1,\dots,n \quad\text{and}\quad i,j,k,l = 1,\dots,d \end{equation}\]

    so $n^2d^4$ iterations are required. Indices in \eqref{eq:engnot2} have the following ranges:

    \[\begin{equation} \alpha,\beta=1,\dots,nd \quad\text{and}\quad \gamma,\delta=1,\dots,d(d+1)/2 \end{equation}\]

    so

    \[\begin{equation} (nd)^2\left(\frac{d(d+1)}{2}\right)^2 = n^2d^4\frac{(d+1)^2}{4} \end{equation}\]

    iterations are required. So engineering notation requires $(d+1)^2/4$ times more equations than index notation. For $d=2$, engineering notation is $2.25$ times slower and for $d=3$ it is $4$ times slower. For example, calculation of a stiffness matrix for $n=8$ and $d=3$ requires $20736$ iterations for engineering notation, whereas it only requires $5184$ iterations for index notation.

    Although \eqref{eq:engnot3} seems less cluttered, what actually happens is that one trades off complexity in one expression for a much increased complexity in another one, in this case \eqref{eq:engnotB}. And to make it worse, it results in a slower algorithm.

    The only obstacle to the widespread adoption of index notation seems to be its lack in undergraduate engineering curricula. If engineers were taught the index notation and summation convention as well as the formal notation, such expressions would not be as confusing at first sight. A good place would be in elementary calculus and physics courses, where one heavily uses vector calculus.

  5. Portrait of Onur Solmaz
    Onur Solmaz · Post · /2018/04/01

    Variational Formulation of Elasticity

    $ \newcommand{\Ua}{\mathrm{a}} \newcommand{\Ub}{\mathrm{b}} \newcommand{\Uc}{\mathrm{c}} \newcommand{\Ud}{\mathrm{d}} \newcommand{\Ue}{\mathrm{e}} \newcommand{\Uf}{\mathrm{f}} \newcommand{\Ug}{\mathrm{g}} \newcommand{\Uh}{\mathrm{h}} \newcommand{\Ui}{\mathrm{i}} \newcommand{\Uj}{\mathrm{j}} \newcommand{\Uk}{\mathrm{k}} \newcommand{\Ul}{\mathrm{l}} \newcommand{\Um}{\mathrm{m}} \newcommand{\Un}{\mathrm{n}} \newcommand{\Uo}{\mathrm{o}} \newcommand{\Up}{\mathrm{p}} \newcommand{\Uq}{\mathrm{q}} \newcommand{\Ur}{\mathrm{r}} \newcommand{\Us}{\mathrm{s}} \newcommand{\Ut}{\mathrm{t}} \newcommand{\Uu}{\mathrm{u}} \newcommand{\Uv}{\mathrm{v}} \newcommand{\Uw}{\mathrm{w}} \newcommand{\Ux}{\mathrm{x}} \newcommand{\Uy}{\mathrm{y}} \newcommand{\Uz}{\mathrm{z}} \newcommand{\UA}{\mathrm{A}} \newcommand{\UB}{\mathrm{B}} \newcommand{\UC}{\mathrm{C}} \newcommand{\UD}{\mathrm{D}} \newcommand{\UE}{\mathrm{E}} \newcommand{\UF}{\mathrm{F}} \newcommand{\UG}{\mathrm{G}} \newcommand{\UH}{\mathrm{H}} \newcommand{\UI}{\mathrm{I}} \newcommand{\UJ}{\mathrm{J}} \newcommand{\UK}{\mathrm{K}} \newcommand{\UL}{\mathrm{L}} \newcommand{\UM}{\mathrm{M}} \newcommand{\UN}{\mathrm{N}} \newcommand{\UO}{\mathrm{O}} \newcommand{\UP}{\mathrm{P}} \newcommand{\UQ}{\mathrm{Q}} \newcommand{\UR}{\mathrm{R}} \newcommand{\US}{\mathrm{S}} \newcommand{\UT}{\mathrm{T}} \newcommand{\UU}{\mathrm{U}} \newcommand{\UV}{\mathrm{V}} \newcommand{\UW}{\mathrm{W}} \newcommand{\UX}{\mathrm{X}} \newcommand{\UY}{\mathrm{Y}} \newcommand{\UZ}{\mathrm{Z}} % \newcommand{\Uzero }{\mathrm{0}} \newcommand{\Uone }{\mathrm{1}} \newcommand{\Utwo }{\mathrm{2}} \newcommand{\Uthree}{\mathrm{3}} \newcommand{\Ufour }{\mathrm{4}} \newcommand{\Ufive }{\mathrm{5}} \newcommand{\Usix }{\mathrm{6}} \newcommand{\Useven}{\mathrm{7}} \newcommand{\Ueight}{\mathrm{8}} \newcommand{\Unine }{\mathrm{9}} % \newcommand{\Ja}{\mathit{a}} \newcommand{\Jb}{\mathit{b}} \newcommand{\Jc}{\mathit{c}} \newcommand{\Jd}{\mathit{d}} \newcommand{\Je}{\mathit{e}} \newcommand{\Jf}{\mathit{f}} \newcommand{\Jg}{\mathit{g}} \newcommand{\Jh}{\mathit{h}} \newcommand{\Ji}{\mathit{i}} \newcommand{\Jj}{\mathit{j}} \newcommand{\Jk}{\mathit{k}} \newcommand{\Jl}{\mathit{l}} \newcommand{\Jm}{\mathit{m}} \newcommand{\Jn}{\mathit{n}} \newcommand{\Jo}{\mathit{o}} \newcommand{\Jp}{\mathit{p}} \newcommand{\Jq}{\mathit{q}} \newcommand{\Jr}{\mathit{r}} \newcommand{\Js}{\mathit{s}} \newcommand{\Jt}{\mathit{t}} \newcommand{\Ju}{\mathit{u}} \newcommand{\Jv}{\mathit{v}} \newcommand{\Jw}{\mathit{w}} \newcommand{\Jx}{\mathit{x}} \newcommand{\Jy}{\mathit{y}} \newcommand{\Jz}{\mathit{z}} \newcommand{\JA}{\mathit{A}} \newcommand{\JB}{\mathit{B}} \newcommand{\JC}{\mathit{C}} \newcommand{\JD}{\mathit{D}} \newcommand{\JE}{\mathit{E}} \newcommand{\JF}{\mathit{F}} \newcommand{\JG}{\mathit{G}} \newcommand{\JH}{\mathit{H}} \newcommand{\JI}{\mathit{I}} \newcommand{\JJ}{\mathit{J}} \newcommand{\JK}{\mathit{K}} \newcommand{\JL}{\mathit{L}} \newcommand{\JM}{\mathit{M}} \newcommand{\JN}{\mathit{N}} \newcommand{\JO}{\mathit{O}} \newcommand{\JP}{\mathit{P}} \newcommand{\JQ}{\mathit{Q}} \newcommand{\JR}{\mathit{R}} \newcommand{\JS}{\mathit{S}} \newcommand{\JT}{\mathit{T}} \newcommand{\JU}{\mathit{U}} \newcommand{\JV}{\mathit{V}} \newcommand{\JW}{\mathit{W}} \newcommand{\JX}{\mathit{X}} \newcommand{\JY}{\mathit{Y}} \newcommand{\JZ}{\mathit{Z}} % \newcommand{\Jzero }{\mathit{0}} \newcommand{\Jone }{\mathit{1}} \newcommand{\Jtwo }{\mathit{2}} \newcommand{\Jthree}{\mathit{3}} \newcommand{\Jfour }{\mathit{4}} \newcommand{\Jfive }{\mathit{5}} \newcommand{\Jsix }{\mathit{6}} \newcommand{\Jseven}{\mathit{7}} \newcommand{\Jeight}{\mathit{8}} \newcommand{\Jnine }{\mathit{9}} % \newcommand{\BA}{\boldsymbol{A}} \newcommand{\BB}{\boldsymbol{B}} \newcommand{\BC}{\boldsymbol{C}} \newcommand{\BD}{\boldsymbol{D}} \newcommand{\BE}{\boldsymbol{E}} \newcommand{\BF}{\boldsymbol{F}} \newcommand{\BG}{\boldsymbol{G}} \newcommand{\BH}{\boldsymbol{H}} \newcommand{\BI}{\boldsymbol{I}} \newcommand{\BJ}{\boldsymbol{J}} \newcommand{\BK}{\boldsymbol{K}} \newcommand{\BL}{\boldsymbol{L}} \newcommand{\BM}{\boldsymbol{M}} \newcommand{\BN}{\boldsymbol{N}} \newcommand{\BO}{\boldsymbol{O}} \newcommand{\BP}{\boldsymbol{P}} \newcommand{\BQ}{\boldsymbol{Q}} \newcommand{\BR}{\boldsymbol{R}} \newcommand{\BS}{\boldsymbol{S}} \newcommand{\BT}{\boldsymbol{T}} \newcommand{\BU}{\boldsymbol{U}} \newcommand{\BV}{\boldsymbol{V}} \newcommand{\BW}{\boldsymbol{W}} \newcommand{\BX}{\boldsymbol{X}} \newcommand{\BY}{\boldsymbol{Y}} \newcommand{\BZ}{\boldsymbol{Z}} \newcommand{\Ba}{\boldsymbol{a}} \newcommand{\Bb}{\boldsymbol{b}} \newcommand{\Bc}{\boldsymbol{c}} \newcommand{\Bd}{\boldsymbol{d}} \newcommand{\Be}{\boldsymbol{e}} \newcommand{\Bf}{\boldsymbol{f}} \newcommand{\Bg}{\boldsymbol{g}} \newcommand{\Bh}{\boldsymbol{h}} \newcommand{\Bi}{\boldsymbol{i}} \newcommand{\Bj}{\boldsymbol{j}} \newcommand{\Bk}{\boldsymbol{k}} \newcommand{\Bl}{\boldsymbol{l}} \newcommand{\Bm}{\boldsymbol{m}} \newcommand{\Bn}{\boldsymbol{n}} \newcommand{\Bo}{\boldsymbol{o}} \newcommand{\Bp}{\boldsymbol{p}} \newcommand{\Bq}{\boldsymbol{q}} \newcommand{\Br}{\boldsymbol{r}} \newcommand{\Bs}{\boldsymbol{s}} \newcommand{\Bt}{\boldsymbol{t}} \newcommand{\Bu}{\boldsymbol{u}} \newcommand{\Bv}{\boldsymbol{v}} \newcommand{\Bw}{\boldsymbol{w}} \newcommand{\Bx}{\boldsymbol{x}} \newcommand{\By}{\boldsymbol{y}} \newcommand{\Bz}{\boldsymbol{z}} % \newcommand{\Bzero }{\boldsymbol{0}} \newcommand{\Bone }{\boldsymbol{1}} \newcommand{\Btwo }{\boldsymbol{2}} \newcommand{\Bthree}{\boldsymbol{3}} \newcommand{\Bfour }{\boldsymbol{4}} \newcommand{\Bfive }{\boldsymbol{5}} \newcommand{\Bsix }{\boldsymbol{6}} \newcommand{\Bseven}{\boldsymbol{7}} \newcommand{\Beight}{\boldsymbol{8}} \newcommand{\Bnine }{\boldsymbol{9}} % \newcommand{\Balpha }{\boldsymbol{\alpha} } \newcommand{\Bbeta }{\boldsymbol{\beta} } \newcommand{\Bgamma }{\boldsymbol{\gamma} } \newcommand{\Bdelta }{\boldsymbol{\delta} } \newcommand{\Bepsilon}{\boldsymbol{\epsilon} } \newcommand{\Bvareps }{\boldsymbol{\varepsilon} } \newcommand{\Bvarepsilon}{\boldsymbol{\varepsilon}} \newcommand{\Bzeta }{\boldsymbol{\zeta} } \newcommand{\Beta }{\boldsymbol{\eta} } \newcommand{\Btheta }{\boldsymbol{\theta} } \newcommand{\Bvarthe }{\boldsymbol{\vartheta} } \newcommand{\Biota }{\boldsymbol{\iota} } \newcommand{\Bkappa }{\boldsymbol{\kappa} } \newcommand{\Blambda }{\boldsymbol{\lambda} } \newcommand{\Bmu }{\boldsymbol{\mu} } \newcommand{\Bnu }{\boldsymbol{\nu} } \newcommand{\Bxi }{\boldsymbol{\xi} } \newcommand{\Bpi }{\boldsymbol{\pi} } \newcommand{\Brho }{\boldsymbol{\rho} } \newcommand{\Bvrho }{\boldsymbol{\varrho} } \newcommand{\Bsigma }{\boldsymbol{\sigma} } \newcommand{\Bvsigma }{\boldsymbol{\varsigma} } \newcommand{\Btau }{\boldsymbol{\tau} } \newcommand{\Bupsilon}{\boldsymbol{\upsilon} } \newcommand{\Bphi }{\boldsymbol{\phi} } \newcommand{\Bvarphi }{\boldsymbol{\varphi} } \newcommand{\Bchi }{\boldsymbol{\chi} } \newcommand{\Bpsi }{\boldsymbol{\psi} } \newcommand{\Bomega }{\boldsymbol{\omega} } \newcommand{\BGamma }{\boldsymbol{\Gamma} } \newcommand{\BDelta }{\boldsymbol{\Delta} } \newcommand{\BTheta }{\boldsymbol{\Theta} } \newcommand{\BLambda }{\boldsymbol{\Lambda} } \newcommand{\BXi }{\boldsymbol{\Xi} } \newcommand{\BPi }{\boldsymbol{\Pi} } \newcommand{\BSigma }{\boldsymbol{\Sigma} } \newcommand{\BUpsilon}{\boldsymbol{\Upsilon} } \newcommand{\BPhi }{\boldsymbol{\Phi} } \newcommand{\BPsi }{\boldsymbol{\Psi} } \newcommand{\BOmega }{\boldsymbol{\Omega} } % \newcommand{\IA}{\mathbb{A}} \newcommand{\IB}{\mathbb{B}} \newcommand{\IC}{\mathbb{C}} \newcommand{\ID}{\mathbb{D}} \newcommand{\IE}{\mathbb{E}} \newcommand{\IF}{\mathbb{F}} \newcommand{\IG}{\mathbb{G}} \newcommand{\IH}{\mathbb{H}} \newcommand{\II}{\mathbb{I}} \renewcommand{\IJ}{\mathbb{J}} \newcommand{\IK}{\mathbb{K}} \newcommand{\IL}{\mathbb{L}} \newcommand{\IM}{\mathbb{M}} \newcommand{\IN}{\mathbb{N}} \newcommand{\IO}{\mathbb{O}} \newcommand{\IP}{\mathbb{P}} \newcommand{\IQ}{\mathbb{Q}} \newcommand{\IR}{\mathbb{R}} \newcommand{\IS}{\mathbb{S}} \newcommand{\IT}{\mathbb{T}} \newcommand{\IU}{\mathbb{U}} \newcommand{\IV}{\mathbb{V}} \newcommand{\IW}{\mathbb{W}} \newcommand{\IX}{\mathbb{X}} \newcommand{\IY}{\mathbb{Y}} \newcommand{\IZ}{\mathbb{Z}} % \newcommand{\FA}{\mathsf{A}} \newcommand{\FB}{\mathsf{B}} \newcommand{\FC}{\mathsf{C}} \newcommand{\FD}{\mathsf{D}} \newcommand{\FE}{\mathsf{E}} \newcommand{\FF}{\mathsf{F}} \newcommand{\FG}{\mathsf{G}} \newcommand{\FH}{\mathsf{H}} \newcommand{\FI}{\mathsf{I}} \newcommand{\FJ}{\mathsf{J}} \newcommand{\FK}{\mathsf{K}} \newcommand{\FL}{\mathsf{L}} \newcommand{\FM}{\mathsf{M}} \newcommand{\FN}{\mathsf{N}} \newcommand{\FO}{\mathsf{O}} \newcommand{\FP}{\mathsf{P}} \newcommand{\FQ}{\mathsf{Q}} \newcommand{\FR}{\mathsf{R}} \newcommand{\FS}{\mathsf{S}} \newcommand{\FT}{\mathsf{T}} \newcommand{\FU}{\mathsf{U}} \newcommand{\FV}{\mathsf{V}} \newcommand{\FW}{\mathsf{W}} \newcommand{\FX}{\mathsf{X}} \newcommand{\FY}{\mathsf{Y}} \newcommand{\FZ}{\mathsf{Z}} \newcommand{\Fa}{\mathsf{a}} \newcommand{\Fb}{\mathsf{b}} \newcommand{\Fc}{\mathsf{c}} \newcommand{\Fd}{\mathsf{d}} \newcommand{\Fe}{\mathsf{e}} \newcommand{\Ff}{\mathsf{f}} \newcommand{\Fg}{\mathsf{g}} \newcommand{\Fh}{\mathsf{h}} \newcommand{\Fi}{\mathsf{i}} \newcommand{\Fj}{\mathsf{j}} \newcommand{\Fk}{\mathsf{k}} \newcommand{\Fl}{\mathsf{l}} \newcommand{\Fm}{\mathsf{m}} \newcommand{\Fn}{\mathsf{n}} \newcommand{\Fo}{\mathsf{o}} \newcommand{\Fp}{\mathsf{p}} \newcommand{\Fq}{\mathsf{q}} \newcommand{\Fr}{\mathsf{r}} \newcommand{\Fs}{\mathsf{s}} \newcommand{\Ft}{\mathsf{t}} \newcommand{\Fu}{\mathsf{u}} \newcommand{\Fv}{\mathsf{v}} \newcommand{\Fw}{\mathsf{w}} \newcommand{\Fx}{\mathsf{x}} \newcommand{\Fy}{\mathsf{y}} \newcommand{\Fz}{\mathsf{z}} % \newcommand{\Fzero }{\mathsf{0}} \newcommand{\Fone }{\mathsf{1}} \newcommand{\Ftwo }{\mathsf{2}} \newcommand{\Fthree}{\mathsf{3}} \newcommand{\Ffour }{\mathsf{4}} \newcommand{\Ffive }{\mathsf{5}} \newcommand{\Fsix }{\mathsf{6}} \newcommand{\Fseven}{\mathsf{7}} \newcommand{\Feight}{\mathsf{8}} \newcommand{\Fnine }{\mathsf{9}} % \newcommand{\CA}{\mathcal{A}} \newcommand{\CB}{\mathcal{B}} \newcommand{\CC}{\mathcal{C}} \newcommand{\CD}{\mathcal{D}} \newcommand{\CE}{\mathcal{E}} \newcommand{\CF}{\mathcal{F}} \newcommand{\CG}{\mathcal{G}} \newcommand{\CH}{\mathcal{H}} \newcommand{\CI}{\mathcal{I}} \newcommand{\CJ}{\mathcal{J}} \newcommand{\CK}{\mathcal{K}} \newcommand{\CL}{\mathcal{L}} \newcommand{\CM}{\mathcal{M}} \newcommand{\CN}{\mathcal{N}} \newcommand{\CO}{\mathcal{O}} \newcommand{\CP}{\mathcal{P}} \newcommand{\CQ}{\mathcal{Q}} \newcommand{\CR}{\mathcal{R}} \newcommand{\CS}{\mathcal{S}} \newcommand{\CT}{\mathcal{T}} \newcommand{\CU}{\mathcal{U}} \newcommand{\CV}{\mathcal{V}} \newcommand{\CW}{\mathcal{W}} \newcommand{\CX}{\mathcal{X}} \newcommand{\CY}{\mathcal{Y}} \newcommand{\CZ}{\mathcal{Z}} % \newcommand{\KA}{\mathfrak{A}} \newcommand{\KB}{\mathfrak{B}} \newcommand{\KC}{\mathfrak{C}} \newcommand{\KD}{\mathfrak{D}} \newcommand{\KE}{\mathfrak{E}} \newcommand{\KF}{\mathfrak{F}} \newcommand{\KG}{\mathfrak{G}} \newcommand{\KH}{\mathfrak{H}} \newcommand{\KI}{\mathfrak{I}} \newcommand{\KJ}{\mathfrak{J}} \newcommand{\KK}{\mathfrak{K}} \newcommand{\KL}{\mathfrak{L}} \newcommand{\KM}{\mathfrak{M}} \newcommand{\KN}{\mathfrak{N}} \newcommand{\KO}{\mathfrak{O}} \newcommand{\KP}{\mathfrak{P}} \newcommand{\KQ}{\mathfrak{Q}} \newcommand{\KR}{\mathfrak{R}} \newcommand{\KS}{\mathfrak{S}} \newcommand{\KT}{\mathfrak{T}} \newcommand{\KU}{\mathfrak{U}} \newcommand{\KV}{\mathfrak{V}} \newcommand{\KW}{\mathfrak{W}} \newcommand{\KX}{\mathfrak{X}} \newcommand{\KY}{\mathfrak{Y}} \newcommand{\KZ}{\mathfrak{Z}} \newcommand{\Ka}{\mathfrak{a}} \newcommand{\Kb}{\mathfrak{b}} \newcommand{\Kc}{\mathfrak{c}} \newcommand{\Kd}{\mathfrak{d}} \newcommand{\Ke}{\mathfrak{e}} \newcommand{\Kf}{\mathfrak{f}} \newcommand{\Kg}{\mathfrak{g}} \newcommand{\Kh}{\mathfrak{h}} \newcommand{\Ki}{\mathfrak{i}} \newcommand{\Kj}{\mathfrak{j}} \newcommand{\Kk}{\mathfrak{k}} \newcommand{\Kl}{\mathfrak{l}} \newcommand{\Km}{\mathfrak{m}} \newcommand{\Kn}{\mathfrak{n}} \newcommand{\Ko}{\mathfrak{o}} \newcommand{\Kp}{\mathfrak{p}} \newcommand{\Kq}{\mathfrak{q}} \newcommand{\Kr}{\mathfrak{r}} \newcommand{\Ks}{\mathfrak{s}} \newcommand{\Kt}{\mathfrak{t}} \newcommand{\Ku}{\mathfrak{u}} \newcommand{\Kv}{\mathfrak{v}} \newcommand{\Kw}{\mathfrak{w}} \newcommand{\Kx}{\mathfrak{x}} \newcommand{\Ky}{\mathfrak{y}} \newcommand{\Kz}{\mathfrak{z}} % \newcommand{\Kzero }{\mathfrak{0}} \newcommand{\Kone }{\mathfrak{1}} \newcommand{\Ktwo }{\mathfrak{2}} \newcommand{\Kthree}{\mathfrak{3}} \newcommand{\Kfour }{\mathfrak{4}} \newcommand{\Kfive }{\mathfrak{5}} \newcommand{\Ksix }{\mathfrak{6}} \newcommand{\Kseven}{\mathfrak{7}} \newcommand{\Keight}{\mathfrak{8}} \newcommand{\Knine }{\mathfrak{9}} % $

    $ \newcommand{\Lin}{\mathop{\rm Lin}\nolimits} \newcommand{\modop}{\mathop{\rm mod}\nolimits} \renewcommand{\div}{\mathop{\rm div}\nolimits} \newcommand{\Var}{\Delta} \newcommand{\evat}{\bigg|} \newcommand\varn[3]{D_{#2}#1\cdot #3} \newcommand{\dtp}{\cdot} \newcommand{\dyd}{\otimes} \newcommand{\tra}{^T} \newcommand{\del}{\partial} \newcommand{\dif}{d} \newcommand{\rbr}[1]{\left(#1\right)} \newcommand{\sbr}[1]{\left[#1\right]} \newcommand{\cbr}[1]{\left\{#1\right\}} \newcommand{\cbrn}[1]{\{#1\}} \newcommand{\abr}[1]{\left\langle #1 \right\rangle} \newcommand{\abrn}[1]{\langle #1 \rangle} \newcommand{\deriv}[2]{\frac{d #1}{d #2}} \newcommand{\dderiv}[2]{\frac{d^2 #1}{d {#2}^2}} \newcommand{\partd}[2]{\frac{\partial #1}{\partial #2}} \newcommand{\nnode}{n_n} \newcommand{\ndim}{n_d} \newcommand{\suml}[2]{\sum\limits_{#1}^{#2}} \newcommand{\Aelid}[2]{A^{#1}_{#2}} \newcommand{\dv}{\, dv} \newcommand{\dx}{\, dx} \newcommand{\ds}{\, ds} \newcommand{\da}{\, da} \newcommand{\dV}{\, dV} \newcommand{\dA}{\, dA} \newcommand{\eqand}{\quad\text{and}\quad} \newcommand{\eqor}{\quad\text{or}\quad} \newcommand{\eqwith}{\quad\text{and}\quad} \newcommand{\inv}{^{-1}} \newcommand{\veci}[1]{#1_1,\ldots,#1_n} \newcommand{\var}{\delta} \newcommand{\Var}{\Delta} \newcommand{\eps}{\epsilon} \newcommand{\ddt}{\frac{d}{dt}} \newcommand{\Norm}[1]{\left\lVert#1\right\rVert} \newcommand{\Abs}[1]{\left|#1\right|} \newcommand{\dabr}[1]{\left\langle\!\left\langle #1 \right\rangle\!\right\rangle} \newcommand{\dabrn}[1]{\langle\!\langle #1 \rangle\!\rangle} \newcommand{\idxsep}{\,} $

    $ \newcommand{\argmin}{\mathop{\rm argmin}\nolimits} \newcommand{\cof}{\mathop{\rm cof}\nolimits} \newcommand{\sym}{\mathop{\rm sym}\nolimits} \newcommand{\invtra}{^{-T}} \newcommand{\eps}{\epsilon} \newcommand{\var}{\Delta} \newcommand{\Vvphi}{\Delta\Bvarphi} \newcommand{\vvphi}{\delta\Bvarphi} \newcommand{\BFC}{\boldsymbol{\mathsf{C}}} \newcommand{\BFc}{\boldsymbol{\mathsf{c}}} \newcommand{\push}{\Bvarphi_\ast} \newcommand{\pull}{\Bvarphi^\ast} $

    There are many books that give an outline of hyperelasticity, but there are few that try to help the reader implement solutions, and even fewer that manage to do it in a concise manner. Peter Wriggers’ Nonlinear Finite Element Methods is a great reference for those who like to roll up their sleeves and get lost in theory. It helped me understand a lot about how solutions to hyperelastic and inelastic problems are implemented.

    One thing did not quite fit my taste though—it was very formal in the way that it didn’t give out indicial expressions. And if it wasn’t clear up until this point, I love indicial expressions, because they pack enough information to implement a solution in a single line. Almost all books skip these because they seem cluttered and the professors who wrote them think they’re trivial to derive. In fact, they are not. So below, I’ll try to derive indicial expressions for the update equations of hyperelasticity.

    In the case of a hyperelastic material, there exists a strain energy function

    \[\begin{equation} \Psi: \BF \mapsto \Psi(\BF) \end{equation}\]

    which describes the elastic energy stored in the solid, i.e. energy density per unit mass of the reference configuration. The total energy stored in $\CB$ is described by the the stored energy functional

    \[\begin{equation} E(\Bvarphi) := \int_\CB \Psi(\BF)\, \dif m = \int_\CB \rho_0 \Psi(\BF) \dV \end{equation}\]

    The loads acting on the body also form a potential:

    \[\begin{equation} L(\Bvarphi) := \int_\CB \rho_0\bar{\BGamma}\dtp\Bvarphi \dV + \int_{\del\CB_t} \bar{\BT}\dtp\Bvarphi \dA \end{equation}\]

    where $\bar{\BGamma}$ and $\bar{\BT}$ are the prescribed body forces per unit mass and surface tractions respectively, where $\BT=\BP\BN$ with Cauchy’s stress theorem.

    The potential energy of $\CB$ for deformation $\Bvarphi$ is defined as

    \[\begin{equation} \Pi(\Bvarphi) := E(\Bvarphi) - L(\Bvarphi) \end{equation}\]

    Thus the variational formulation reads

    Find $\Bvarphi\in V$ such that the functional

    \[\begin{equation} \Pi(\Bvarphi) = \int_\CB \rho_0\Psi(\BF) \dV - \int_\CB \rho_0\bar{\BGamma}\dtp\Bvarphi \dV - \int_{\del\CB_t} \bar{\BT}\dtp\Bvarphi \dA \end{equation}\]

    is minimized for $\Bvarphi=\bar{\Bvarphi}$ on $\del\CB_u$.

    The solution is one that minimizes the potential energy:

    \[\begin{equation} \Bvarphi^\ast = \argmin_{\Bvarphi\in V} \Pi(\Bvarphi) \end{equation}\]

    A stationary point for $\Pi$ means that its first variation vanishes: $\var\Pi=0$.

    \[\begin{equation} \begin{aligned} \var\Pi &= \varn{\Pi}{\Bvarphi}{\vvphi} =: G(\Bvarphi,\vvphi) \\ &= \int_\CB \rho_0\partd{\Psi}{\BF}: \nabla(\vvphi) \dV - \int_\CB \rho_0\bar{\BGamma}\dtp\vvphi \dV - \int_{\del\CB} \bar{\BT}\dtp\vvphi \dA \end{aligned} \end{equation}\]

    Using $\BP=\BF\BS$ and $\BP = \rho_0\del\Psi/\del\BF$,

    \[\begin{equation} \rho_0\partd{\Psi}{\BF}: \nabla(\vvphi) = \BF\BS:\nabla(\vvphi) = \BS:\BF\tra\nabla(\vvphi) \end{equation}\]

    The symmetric part of the term on the right hand side of the contraction is equal to the variation of the Green-Lagrange strain tensor:

    \[\begin{equation} \begin{aligned} \var\BE = \varn{\BE}{\Bvarphi}{\vvphi} &= \deriv{}{\eps} \frac{1}{2} [\nabla(\Bvarphi+\eps\vvphi)\tra\nabla(\Bvarphi+\eps\vvphi) - \BI]\evat_{\eps=0} \\ &= \frac{1}{2} [\nabla(\vvphi)\tra\BF + \BF\tra\nabla(\vvphi)] \end{aligned} \end{equation}\]

    Substituting, we obtain the semilinear form $G$ in terms of the second Piola-Kirchhoff stress tensor:

    \[\begin{equation} \boxed{ G(\Bvarphi,\vvphi) = \int_\CB \BS: \var\BE \dV - \int_\CB \rho_0\bar{\BGamma}\dtp\vvphi \dV - \int_{\del\CB} \bar{\BT}\dtp\vvphi \dA = 0 } \label{eq:lagrangianform1} \end{equation}\]

    We can write a Eulerian version of this form by pushing-forward the stresses and strains. The Almansi strain $\Be$ is the pull-back of the Green-Lagrange strain $\BE$ and vice versa:

    \[\begin{equation} \Be = \push(\BE) = \BF\invtra \BE \BF\inv \eqand \BE = \pull(\Be) = \BF\tra \BE \BF \end{equation}\]

    Commutative diagram for the pull-back and push-forward relationships of the Green-Lagrange and Almansi strain tensors.

    Thus we can deduce the variation of the Almansi strain

    \[\begin{equation} \begin{aligned} \var \Be = \BF\invtra \var\BE\BF\inv &= \frac{1}{2} [\nabla(\vvphi)\BF\inv+\BF\invtra \nabla(\vvphi)\tra] \\ &= \frac{1}{2} [\nabla_x(\vvphi)+ \nabla_x(\vvphi)\tra] \end{aligned} \end{equation}\]

    where we have used the identity

    \[\begin{equation} \nabla_X(\cdot)\BF\inv = \nabla_x(\cdot). \label{eq:defgradidentity1} \end{equation}\]

    The second Piola-Kirchhoff stress is the pull-back of the Kirchhoff stress $\Btau$:

    \[\begin{equation} \BS = \pull(\Btau) = \BF\inv\Btau\BF\invtra \end{equation}\]

    Then it is evident that

    \[\begin{equation} \BS:\var\BE = (\BF\inv\Btau\BF\invtra):(\BF\tra\var\Be\BF) = \Btau:\var\Be \end{equation}\]

    We can thus write the Eulerian version of \eqref{eq:lagrangianform1}:

    \[\begin{equation} \boxed{ G(\Bvarphi,\vvphi) = \int_\CB \Btau: \var\Be \dV - \int_\CB \rho_0\bar{\BGamma}\dtp\vvphi \dV - \int_{\del\CB} \bar{\BT}\dtp\vvphi \dA = 0 } \end{equation}\]

    Introducing the Cauchy stresses $\Bsigma=\Btau/J$, we can also transport the integrals to the current configuration

    \[\begin{equation} \boxed{ G(\Bvarphi,\vvphi) = \int_\CS \Bsigma:\var\Be \dv - \int_\CS \rho\bar{\Bgamma}\dtp\vvphi \dv - \int_{\del\CS_t} \bar{\Bt}\dtp\vvphi \da = 0 } \end{equation}\]

    Here, we substituted the following differential identities:

    \[\begin{equation} \rho_0\BGamma\dV = \rho\Bgamma\dv \end{equation}\]

    for the body forces, and

    \[\begin{equation} \BT\dA = \BP\BN \dA = \Bsigma J\BF\invtra\BN \dA = \Bsigma\Bn \da = \Bt \da \end{equation}\]

    for the surface tractions, where we used the Piola identity.

    Linearization of the Variational Formulation

    We linearize $G$:

    \[\begin{equation} \Lin G \evat_{\bar{\Bvarphi}} = G(\bar{\Bvarphi}, \vvphi) + \Var G \evat_{\bar{\Bvarphi}} = 0 \end{equation}\]

    Then we have the variational setting

    \[\begin{equation} a(\Vvphi,\vvphi)=b(\vvphi) \end{equation}\]

    where

    \[\begin{equation} a(\Vvphi,\vvphi) = \Var G \evat_{\bar{\Bvarphi}} \eqand b(\vvphi) = -G(\bar{\Bvarphi}, \vvphi) \end{equation}\]

    Commutative diagram of the linearized solution procedure. Each iteration brings the current iterate $\bar{\Bvarphi}$ closer to the optimum value $\Bvarphi^\ast$.

    Mappings between line elements belonging to the tangent spaces of the linearization.

    The variation $\Var G$ is calculated as

    \[\begin{equation} \Var G = \varn{G}{\Bvarphi}{\Vvphi} = \int_\CB [\Var\BS:\var\BE + \BS:\Var(\var\BE)] \dV \end{equation}\]

    Consecutive variations of the Green-Lagrange strain tensor is calculated as

    \[\begin{equation} \Var(\var\BE) = \varn{\var\BE}{\Bvarphi}{\Vvphi} = \frac{1}{2}[\nabla(\vvphi)\tra\nabla(\Vvphi) + \nabla(\Vvphi)\tra\nabla(\vvphi)] \end{equation}\]

    The term on the left is calculated as

    \[\begin{equation} \Var\BS = \varn{\BS}{\Bvarphi}{\Vvphi} = \partd{\BS}{\BC}:\Var\BC = 2 \partd{\BS}{\BC}:\Var\BE \end{equation}\]

    where we substitute the Lagrangian elasticity tensor

    \[\begin{equation} \BFC := 2 \partd{\BS}{\BC} = 4\rho_0 \frac{\del^2\Psi}{\del\BC\del\BC} \end{equation}\]

    and $\Var\BE$ is calculated in the same manner as $\var\BE$:

    \[\begin{equation} \Var\BE = \frac{1}{2} [\nabla(\Vvphi)\tra\BF + \BF\tra\nabla(\Vvphi)] \end{equation}\]

    Then the variational forms of the linearized setting are

    \[\begin{equation} \boxed{ \begin{aligned} a(\Vvphi,\vvphi) &= \int_\CB \var\bar{\BE}:\bar{\BFC}:\Var\bar{\BE} + \bar{\BS} : [\nabla(\vvphi)\tra\nabla(\Vvphi)] \dV \\ b(\vvphi) &= - \int_\CB \bar{\BS}: \var\bar{\BE} \dV + \int_\CB \rho_0\bar{\BGamma}\dtp\vvphi \dV + \int_{\del\CB} \bar{\BT}\dtp\vvphi \dA \end{aligned} } \end{equation}\]

    where the bars denote evaluation $\Bvarphi=\bar{\Bvarphi}$ of dependent variables.

    Eulerian Version of the Linearization

    We also have the following relationship between the Lagrangian and Eulerian elasticity tensors

    \[\begin{equation} c_{abcd} = F_{aA}F_{bB}F_{cC}F_{dD} C_{ABCD} \end{equation}\]

    Substituting Eulerian expansions, we obtain the following identity:

    \[\begin{equation} \begin{aligned} \var\BE:\BFC:\Var\BE &= (\BF\tra\var\Be\BF):\BFC:(\BF\tra\Var\Be\BF) \\ &=F_{aA}\var e_{ab} F_{bB} C_{ABCD} F_{cC}\Var e_{cd}F_{dD} \\ &=\var e_{ab} c_{abcd} \Var e_{cd} \\ &= \var\Be:\BFc:\Var\Be \end{aligned} \end{equation}\]

    Thus we have

    \[\begin{equation} \begin{aligned} \BS:[\nabla(\vvphi)\tra\nabla(\Vvphi)] &= [\BF\inv\Btau\BF\invtra] :[\nabla(\vvphi)\tra\nabla(\Vvphi)] \\ &= \Btau : [(\nabla(\vvphi)\BF\inv)\tra\nabla(\Vvphi)\BF\inv] \\ &= \Btau : [\nabla_x(\vvphi)\tra\nabla_x(\Vvphi)] \\ \end{aligned} \end{equation}\]

    With these results at hand, we can write the Eulerian version of our variational formulation:

    \[\begin{equation} \boxed{ \begin{aligned} a(\Vvphi,\vvphi) &= \int_\CB \var\bar{\Be}:\bar{\BFc}:\Var\bar{\Be} + \bar{\Btau} : [\nabla_{\bar{x}}(\vvphi)\tra\nabla_{\bar{x}}(\Vvphi)] \dV \\ b(\vvphi) &= - \int_\CB \bar{\Btau}:\var\bar{\Be} \dV + \int_\CB \rho_0\bar{\BGamma}\dtp\vvphi \dV + \int_{\del\CB} \bar{\BT}\dtp\vvphi \dA \end{aligned} } \end{equation}\]

    If we introduce the Cauchy stress tensor $\Bsigma$ and corresponding elasticity tensor $\BFc^\sigma = \BFc/J$, our variational formulation can be expressed completely in terms of Eulerian quantities:

    \[\begin{equation} \boxed{ \begin{aligned} a(\Vvphi,\vvphi) &= \int_{\bar{\CS}} \var\bar{\Be}:\bar{\BFc}^\sigma:\Var\bar{\Be} + \bar{\Bsigma} : [\nabla_{\bar{x}}(\vvphi)\tra\nabla_{\bar{x}}(\Vvphi)] \,\dif\bar{v} \\ b(\vvphi) &= - \int_{\bar{\CS}} \bar{\Bsigma}:\var\bar{\Be} \,\dif\bar{v} + \int_{\bar{\CS}} \rho\bar{\Bgamma}\dtp\vvphi \,\dif\bar{v} + \int_{\del\bar{\CS}_t} \bar{\Bt}\dtp\vvphi \,\dif\bar{a} \end{aligned} } \end{equation}\]

    We have the following relationships of the differential forms:

    \[\begin{equation} \dif \bar{v} = \bar{J}\dv \eqand \bar{\Bn} \,\dif \bar{a} = \cof \bar{\BF}\BN \dA \end{equation}\]

    where $\bar{\BF} = \nabla_X\bar{\Bvarphi}$ and $\bar{J} = \det\bar{\BF}$.

    Discretization of the Lagrangian Form

    We use the following FE discretization:

    \[\begin{equation} \Bvarphi_h = \suml{\gamma=1}{\nnode} \Bvarphi^\gamma N^\gamma = \suml{\gamma=1}{\nnode}\suml{a=1}{\ndim} \varphi_a^\gamma \Be_a N^\gamma \end{equation}\]

    where $\nnode$ is the number of element nodes and $\ndim$ is the number of spatial dimensions.

    We use the same discretization for $\vvphi$ and $\Vvphi$. Then the linear system at hand becomes

    \[\begin{equation} \suml{\delta=1}{\nnode}\suml{b=1}{\ndim}A_{ab}^{\gamma\delta} \Var\varphi_b^\delta = b_a^\gamma \end{equation}\]

    for $a=1,\dots,\ndim$ and $\gamma=1,\dots,\nnode$ where the $\BA$ and $\Bb$ are calculated from the variational forms as

    \[\begin{equation} \begin{aligned} A_{ab}^{\gamma\delta} &= a(\Be_bN^\delta, \Be_aN^\gamma) \\ b_a^\gamma &= b(\Be_aN^\gamma) \end{aligned} \end{equation}\]

    For detailed derivation, see the post Vectorial Finite Elements.

    For discretized gradients, we have the following relationship

    \[\begin{equation} \nabla_X(\Be_aN^\gamma) = (\Be_a\dyd\BB^\gamma) \end{equation}\]

    where $\BB^\gamma:= \nabla_X N^\gamma$. For the first term in $a$, we can get rid of the symmetries:

    \[\begin{equation} \begin{aligned} \sym&(\bar{\BF}\tra\nabla(\Be_aN^\gamma)):\bar{\BFC}: \sym(\bar{\BF}\tra\nabla(\Be_bN^\delta)) \\ &= (\bar{\BF}\tra(\Be_a\dyd\BB^\gamma)):\bar{\BFC}: (\bar{\BF}\tra(\Be_b\dyd\BB^\delta)) \\ &= \bar{F}_{aA}B^\gamma_B\bar{C}_{ABCD}\bar{F}_{bC}B^\delta_D \end{aligned} \end{equation}\]

    and for the second term, we have

    \[\begin{equation} \begin{aligned} \bar{\BS}:[\nabla(\Be_aN^\gamma)\tra \nabla(\Be_bN^\delta)] &= \bar{\BS}:[(\Be_a\dyd \BB^\gamma)\tra (\Be_b \dyd \BB^\delta)] \\ &= \bar{\BS}:[\BB^\gamma\dyd\BB^\delta] g_{ab} \\ &= B^\gamma_A \bar{S}_{AB}B^\delta_B g_{ab} \end{aligned} \end{equation}\]

    where $g_{ab}$ are the components of the Eulerian metric tensor.

    For the first term in $b$, we have

    \[\begin{equation} \bar{\BS} : \sym(\bar{\BF}\tra\nabla(\Be_aN^\gamma)) = \bar{\BS} : (\bar{\BF}\tra(\Be_a \dyd \BB^\gamma)) = \bar{S}_{AB} \bar{F}_{aA} B^\gamma_B \end{equation}\]

    Remaining terms can be calculated in a straightforward manner. We then have for $\BA$ and $\Bb$:

    \[\begin{equation} \boxed{ \begin{aligned} A_{ab}^{\gamma\delta} &= \int_\CB \bar{F}_{aA}B^\gamma_B\bar{C}_{ABCD}\bar{F}_{bC}B^\delta_D + B^\gamma_A \bar{S}_{AB}B^\delta_B g_{ab} \dV \\ b_a^\gamma &= -\int_\CB \bar{S}_{AB} \bar{F}_{aA} B^\gamma_B \dV + \int_\CB\rho_0\bar{\Gamma}_aN^\gamma \dV + \int_{\del\CB_t}\bar{T}_aN^\gamma \dA \end{aligned} } \end{equation}\]

    The lowercase indices in $\bar{\Bgamma}$ and $\bar{\BT}$ might be confusing, but in fact

    \[\begin{equation} \begin{aligned} \Gamma_a(\BX,t) &= \gamma_a(\Bx, t) \circ \Bvarphi(\BX,t) \\ T_a(\BX,t) &= t_a(\Bx, t) \circ \Bvarphi(\BX,t) \\ \end{aligned} \end{equation}\]

    The system is solved for $\Vvphi$ at each Newton iteration with the following update equation:

    \[\begin{equation} \Bvarphi \leftarrow \bar{\Bvarphi} + \Vvphi \label{eq:lagrangianupdate1} \end{equation}\]

    Discretization of the Eulerian Form

    Discretization of the Eulerian formulation parallels that of Lagrangian.

    \[\begin{gather} \boxed{ \begin{aligned} A_{ab}^{\gamma\delta} &= \int_\CB \bar{B}^\gamma_c \bar{c}_{acbd}\bar{B}^\delta_d + \bar{B}^\gamma_e \bar{\tau}_{ef}\bar{B}^\delta_f g_{ab} \dV \\ b_a^\gamma &= -\int_\CB \bar{\tau}_{ab} \bar{B}^\gamma_b \dV + \int_\CB\rho_0 \bar{\Gamma}_aN^\gamma \dV + \int_{\del\CB_t}\bar{T}_aN^\gamma \dA \end{aligned} } \\ \text{or} \nonumber \\ \boxed{ \begin{aligned} A_{ab}^{\gamma\delta} &= \int_{\bar{\CS}} \bar{B}^\gamma_c \bar{c}^\sigma_{acbd}\bar{B}^\delta_d + \bar{B}^\gamma_e \bar{\sigma}_{ef}\bar{B}^\delta_f g_{ab} \,\dif\bar{v} \\ b_a^\gamma &= -\int_{\bar{\CS}} \bar{\sigma}_{ab} \bar{B}^\gamma_b \,\dif\bar{v} + \int_{\bar{\CS}}\rho \bar{\gamma}_aN^\gamma \,\dif\bar{v} + \int_{\del\bar{\CS}_t}\bar{t}_aN^\gamma \,\dif\bar{a} \end{aligned} } \end{gather}\]

    Here, $\bar{\BB}^\gamma = \nabla_{\bar{x}} N^\gamma$ denote the spatial gradients of the shape functions. One way of calculating is $\bar{\BB}^\gamma = \bar{\BF}\invtra\BB^\gamma$, similar to \eqref{eq:defgradidentity1}.

    The update equation \eqref{eq:lagrangianupdate1} holds for the Eulerian version.

    Conclusion

    The equations above in boxes contain all the information needed to implement the nonlinear solution scheme of hyperelasticity.

  6. Portrait of Onur Solmaz
    Onur Solmaz · Post · /2018/01/24

    Discontinuous Divergence Theorem

    $ \newcommand{\Ua}{\mathrm{a}} \newcommand{\Ub}{\mathrm{b}} \newcommand{\Uc}{\mathrm{c}} \newcommand{\Ud}{\mathrm{d}} \newcommand{\Ue}{\mathrm{e}} \newcommand{\Uf}{\mathrm{f}} \newcommand{\Ug}{\mathrm{g}} \newcommand{\Uh}{\mathrm{h}} \newcommand{\Ui}{\mathrm{i}} \newcommand{\Uj}{\mathrm{j}} \newcommand{\Uk}{\mathrm{k}} \newcommand{\Ul}{\mathrm{l}} \newcommand{\Um}{\mathrm{m}} \newcommand{\Un}{\mathrm{n}} \newcommand{\Uo}{\mathrm{o}} \newcommand{\Up}{\mathrm{p}} \newcommand{\Uq}{\mathrm{q}} \newcommand{\Ur}{\mathrm{r}} \newcommand{\Us}{\mathrm{s}} \newcommand{\Ut}{\mathrm{t}} \newcommand{\Uu}{\mathrm{u}} \newcommand{\Uv}{\mathrm{v}} \newcommand{\Uw}{\mathrm{w}} \newcommand{\Ux}{\mathrm{x}} \newcommand{\Uy}{\mathrm{y}} \newcommand{\Uz}{\mathrm{z}} \newcommand{\UA}{\mathrm{A}} \newcommand{\UB}{\mathrm{B}} \newcommand{\UC}{\mathrm{C}} \newcommand{\UD}{\mathrm{D}} \newcommand{\UE}{\mathrm{E}} \newcommand{\UF}{\mathrm{F}} \newcommand{\UG}{\mathrm{G}} \newcommand{\UH}{\mathrm{H}} \newcommand{\UI}{\mathrm{I}} \newcommand{\UJ}{\mathrm{J}} \newcommand{\UK}{\mathrm{K}} \newcommand{\UL}{\mathrm{L}} \newcommand{\UM}{\mathrm{M}} \newcommand{\UN}{\mathrm{N}} \newcommand{\UO}{\mathrm{O}} \newcommand{\UP}{\mathrm{P}} \newcommand{\UQ}{\mathrm{Q}} \newcommand{\UR}{\mathrm{R}} \newcommand{\US}{\mathrm{S}} \newcommand{\UT}{\mathrm{T}} \newcommand{\UU}{\mathrm{U}} \newcommand{\UV}{\mathrm{V}} \newcommand{\UW}{\mathrm{W}} \newcommand{\UX}{\mathrm{X}} \newcommand{\UY}{\mathrm{Y}} \newcommand{\UZ}{\mathrm{Z}} % \newcommand{\Uzero }{\mathrm{0}} \newcommand{\Uone }{\mathrm{1}} \newcommand{\Utwo }{\mathrm{2}} \newcommand{\Uthree}{\mathrm{3}} \newcommand{\Ufour }{\mathrm{4}} \newcommand{\Ufive }{\mathrm{5}} \newcommand{\Usix }{\mathrm{6}} \newcommand{\Useven}{\mathrm{7}} \newcommand{\Ueight}{\mathrm{8}} \newcommand{\Unine }{\mathrm{9}} % \newcommand{\Ja}{\mathit{a}} \newcommand{\Jb}{\mathit{b}} \newcommand{\Jc}{\mathit{c}} \newcommand{\Jd}{\mathit{d}} \newcommand{\Je}{\mathit{e}} \newcommand{\Jf}{\mathit{f}} \newcommand{\Jg}{\mathit{g}} \newcommand{\Jh}{\mathit{h}} \newcommand{\Ji}{\mathit{i}} \newcommand{\Jj}{\mathit{j}} \newcommand{\Jk}{\mathit{k}} \newcommand{\Jl}{\mathit{l}} \newcommand{\Jm}{\mathit{m}} \newcommand{\Jn}{\mathit{n}} \newcommand{\Jo}{\mathit{o}} \newcommand{\Jp}{\mathit{p}} \newcommand{\Jq}{\mathit{q}} \newcommand{\Jr}{\mathit{r}} \newcommand{\Js}{\mathit{s}} \newcommand{\Jt}{\mathit{t}} \newcommand{\Ju}{\mathit{u}} \newcommand{\Jv}{\mathit{v}} \newcommand{\Jw}{\mathit{w}} \newcommand{\Jx}{\mathit{x}} \newcommand{\Jy}{\mathit{y}} \newcommand{\Jz}{\mathit{z}} \newcommand{\JA}{\mathit{A}} \newcommand{\JB}{\mathit{B}} \newcommand{\JC}{\mathit{C}} \newcommand{\JD}{\mathit{D}} \newcommand{\JE}{\mathit{E}} \newcommand{\JF}{\mathit{F}} \newcommand{\JG}{\mathit{G}} \newcommand{\JH}{\mathit{H}} \newcommand{\JI}{\mathit{I}} \newcommand{\JJ}{\mathit{J}} \newcommand{\JK}{\mathit{K}} \newcommand{\JL}{\mathit{L}} \newcommand{\JM}{\mathit{M}} \newcommand{\JN}{\mathit{N}} \newcommand{\JO}{\mathit{O}} \newcommand{\JP}{\mathit{P}} \newcommand{\JQ}{\mathit{Q}} \newcommand{\JR}{\mathit{R}} \newcommand{\JS}{\mathit{S}} \newcommand{\JT}{\mathit{T}} \newcommand{\JU}{\mathit{U}} \newcommand{\JV}{\mathit{V}} \newcommand{\JW}{\mathit{W}} \newcommand{\JX}{\mathit{X}} \newcommand{\JY}{\mathit{Y}} \newcommand{\JZ}{\mathit{Z}} % \newcommand{\Jzero }{\mathit{0}} \newcommand{\Jone }{\mathit{1}} \newcommand{\Jtwo }{\mathit{2}} \newcommand{\Jthree}{\mathit{3}} \newcommand{\Jfour }{\mathit{4}} \newcommand{\Jfive }{\mathit{5}} \newcommand{\Jsix }{\mathit{6}} \newcommand{\Jseven}{\mathit{7}} \newcommand{\Jeight}{\mathit{8}} \newcommand{\Jnine }{\mathit{9}} % \newcommand{\BA}{\boldsymbol{A}} \newcommand{\BB}{\boldsymbol{B}} \newcommand{\BC}{\boldsymbol{C}} \newcommand{\BD}{\boldsymbol{D}} \newcommand{\BE}{\boldsymbol{E}} \newcommand{\BF}{\boldsymbol{F}} \newcommand{\BG}{\boldsymbol{G}} \newcommand{\BH}{\boldsymbol{H}} \newcommand{\BI}{\boldsymbol{I}} \newcommand{\BJ}{\boldsymbol{J}} \newcommand{\BK}{\boldsymbol{K}} \newcommand{\BL}{\boldsymbol{L}} \newcommand{\BM}{\boldsymbol{M}} \newcommand{\BN}{\boldsymbol{N}} \newcommand{\BO}{\boldsymbol{O}} \newcommand{\BP}{\boldsymbol{P}} \newcommand{\BQ}{\boldsymbol{Q}} \newcommand{\BR}{\boldsymbol{R}} \newcommand{\BS}{\boldsymbol{S}} \newcommand{\BT}{\boldsymbol{T}} \newcommand{\BU}{\boldsymbol{U}} \newcommand{\BV}{\boldsymbol{V}} \newcommand{\BW}{\boldsymbol{W}} \newcommand{\BX}{\boldsymbol{X}} \newcommand{\BY}{\boldsymbol{Y}} \newcommand{\BZ}{\boldsymbol{Z}} \newcommand{\Ba}{\boldsymbol{a}} \newcommand{\Bb}{\boldsymbol{b}} \newcommand{\Bc}{\boldsymbol{c}} \newcommand{\Bd}{\boldsymbol{d}} \newcommand{\Be}{\boldsymbol{e}} \newcommand{\Bf}{\boldsymbol{f}} \newcommand{\Bg}{\boldsymbol{g}} \newcommand{\Bh}{\boldsymbol{h}} \newcommand{\Bi}{\boldsymbol{i}} \newcommand{\Bj}{\boldsymbol{j}} \newcommand{\Bk}{\boldsymbol{k}} \newcommand{\Bl}{\boldsymbol{l}} \newcommand{\Bm}{\boldsymbol{m}} \newcommand{\Bn}{\boldsymbol{n}} \newcommand{\Bo}{\boldsymbol{o}} \newcommand{\Bp}{\boldsymbol{p}} \newcommand{\Bq}{\boldsymbol{q}} \newcommand{\Br}{\boldsymbol{r}} \newcommand{\Bs}{\boldsymbol{s}} \newcommand{\Bt}{\boldsymbol{t}} \newcommand{\Bu}{\boldsymbol{u}} \newcommand{\Bv}{\boldsymbol{v}} \newcommand{\Bw}{\boldsymbol{w}} \newcommand{\Bx}{\boldsymbol{x}} \newcommand{\By}{\boldsymbol{y}} \newcommand{\Bz}{\boldsymbol{z}} % \newcommand{\Bzero }{\boldsymbol{0}} \newcommand{\Bone }{\boldsymbol{1}} \newcommand{\Btwo }{\boldsymbol{2}} \newcommand{\Bthree}{\boldsymbol{3}} \newcommand{\Bfour }{\boldsymbol{4}} \newcommand{\Bfive }{\boldsymbol{5}} \newcommand{\Bsix }{\boldsymbol{6}} \newcommand{\Bseven}{\boldsymbol{7}} \newcommand{\Beight}{\boldsymbol{8}} \newcommand{\Bnine }{\boldsymbol{9}} % \newcommand{\Balpha }{\boldsymbol{\alpha} } \newcommand{\Bbeta }{\boldsymbol{\beta} } \newcommand{\Bgamma }{\boldsymbol{\gamma} } \newcommand{\Bdelta }{\boldsymbol{\delta} } \newcommand{\Bepsilon}{\boldsymbol{\epsilon} } \newcommand{\Bvareps }{\boldsymbol{\varepsilon} } \newcommand{\Bvarepsilon}{\boldsymbol{\varepsilon}} \newcommand{\Bzeta }{\boldsymbol{\zeta} } \newcommand{\Beta }{\boldsymbol{\eta} } \newcommand{\Btheta }{\boldsymbol{\theta} } \newcommand{\Bvarthe }{\boldsymbol{\vartheta} } \newcommand{\Biota }{\boldsymbol{\iota} } \newcommand{\Bkappa }{\boldsymbol{\kappa} } \newcommand{\Blambda }{\boldsymbol{\lambda} } \newcommand{\Bmu }{\boldsymbol{\mu} } \newcommand{\Bnu }{\boldsymbol{\nu} } \newcommand{\Bxi }{\boldsymbol{\xi} } \newcommand{\Bpi }{\boldsymbol{\pi} } \newcommand{\Brho }{\boldsymbol{\rho} } \newcommand{\Bvrho }{\boldsymbol{\varrho} } \newcommand{\Bsigma }{\boldsymbol{\sigma} } \newcommand{\Bvsigma }{\boldsymbol{\varsigma} } \newcommand{\Btau }{\boldsymbol{\tau} } \newcommand{\Bupsilon}{\boldsymbol{\upsilon} } \newcommand{\Bphi }{\boldsymbol{\phi} } \newcommand{\Bvarphi }{\boldsymbol{\varphi} } \newcommand{\Bchi }{\boldsymbol{\chi} } \newcommand{\Bpsi }{\boldsymbol{\psi} } \newcommand{\Bomega }{\boldsymbol{\omega} } \newcommand{\BGamma }{\boldsymbol{\Gamma} } \newcommand{\BDelta }{\boldsymbol{\Delta} } \newcommand{\BTheta }{\boldsymbol{\Theta} } \newcommand{\BLambda }{\boldsymbol{\Lambda} } \newcommand{\BXi }{\boldsymbol{\Xi} } \newcommand{\BPi }{\boldsymbol{\Pi} } \newcommand{\BSigma }{\boldsymbol{\Sigma} } \newcommand{\BUpsilon}{\boldsymbol{\Upsilon} } \newcommand{\BPhi }{\boldsymbol{\Phi} } \newcommand{\BPsi }{\boldsymbol{\Psi} } \newcommand{\BOmega }{\boldsymbol{\Omega} } % \newcommand{\IA}{\mathbb{A}} \newcommand{\IB}{\mathbb{B}} \newcommand{\IC}{\mathbb{C}} \newcommand{\ID}{\mathbb{D}} \newcommand{\IE}{\mathbb{E}} \newcommand{\IF}{\mathbb{F}} \newcommand{\IG}{\mathbb{G}} \newcommand{\IH}{\mathbb{H}} \newcommand{\II}{\mathbb{I}} \renewcommand{\IJ}{\mathbb{J}} \newcommand{\IK}{\mathbb{K}} \newcommand{\IL}{\mathbb{L}} \newcommand{\IM}{\mathbb{M}} \newcommand{\IN}{\mathbb{N}} \newcommand{\IO}{\mathbb{O}} \newcommand{\IP}{\mathbb{P}} \newcommand{\IQ}{\mathbb{Q}} \newcommand{\IR}{\mathbb{R}} \newcommand{\IS}{\mathbb{S}} \newcommand{\IT}{\mathbb{T}} \newcommand{\IU}{\mathbb{U}} \newcommand{\IV}{\mathbb{V}} \newcommand{\IW}{\mathbb{W}} \newcommand{\IX}{\mathbb{X}} \newcommand{\IY}{\mathbb{Y}} \newcommand{\IZ}{\mathbb{Z}} % \newcommand{\FA}{\mathsf{A}} \newcommand{\FB}{\mathsf{B}} \newcommand{\FC}{\mathsf{C}} \newcommand{\FD}{\mathsf{D}} \newcommand{\FE}{\mathsf{E}} \newcommand{\FF}{\mathsf{F}} \newcommand{\FG}{\mathsf{G}} \newcommand{\FH}{\mathsf{H}} \newcommand{\FI}{\mathsf{I}} \newcommand{\FJ}{\mathsf{J}} \newcommand{\FK}{\mathsf{K}} \newcommand{\FL}{\mathsf{L}} \newcommand{\FM}{\mathsf{M}} \newcommand{\FN}{\mathsf{N}} \newcommand{\FO}{\mathsf{O}} \newcommand{\FP}{\mathsf{P}} \newcommand{\FQ}{\mathsf{Q}} \newcommand{\FR}{\mathsf{R}} \newcommand{\FS}{\mathsf{S}} \newcommand{\FT}{\mathsf{T}} \newcommand{\FU}{\mathsf{U}} \newcommand{\FV}{\mathsf{V}} \newcommand{\FW}{\mathsf{W}} \newcommand{\FX}{\mathsf{X}} \newcommand{\FY}{\mathsf{Y}} \newcommand{\FZ}{\mathsf{Z}} \newcommand{\Fa}{\mathsf{a}} \newcommand{\Fb}{\mathsf{b}} \newcommand{\Fc}{\mathsf{c}} \newcommand{\Fd}{\mathsf{d}} \newcommand{\Fe}{\mathsf{e}} \newcommand{\Ff}{\mathsf{f}} \newcommand{\Fg}{\mathsf{g}} \newcommand{\Fh}{\mathsf{h}} \newcommand{\Fi}{\mathsf{i}} \newcommand{\Fj}{\mathsf{j}} \newcommand{\Fk}{\mathsf{k}} \newcommand{\Fl}{\mathsf{l}} \newcommand{\Fm}{\mathsf{m}} \newcommand{\Fn}{\mathsf{n}} \newcommand{\Fo}{\mathsf{o}} \newcommand{\Fp}{\mathsf{p}} \newcommand{\Fq}{\mathsf{q}} \newcommand{\Fr}{\mathsf{r}} \newcommand{\Fs}{\mathsf{s}} \newcommand{\Ft}{\mathsf{t}} \newcommand{\Fu}{\mathsf{u}} \newcommand{\Fv}{\mathsf{v}} \newcommand{\Fw}{\mathsf{w}} \newcommand{\Fx}{\mathsf{x}} \newcommand{\Fy}{\mathsf{y}} \newcommand{\Fz}{\mathsf{z}} % \newcommand{\Fzero }{\mathsf{0}} \newcommand{\Fone }{\mathsf{1}} \newcommand{\Ftwo }{\mathsf{2}} \newcommand{\Fthree}{\mathsf{3}} \newcommand{\Ffour }{\mathsf{4}} \newcommand{\Ffive }{\mathsf{5}} \newcommand{\Fsix }{\mathsf{6}} \newcommand{\Fseven}{\mathsf{7}} \newcommand{\Feight}{\mathsf{8}} \newcommand{\Fnine }{\mathsf{9}} % \newcommand{\CA}{\mathcal{A}} \newcommand{\CB}{\mathcal{B}} \newcommand{\CC}{\mathcal{C}} \newcommand{\CD}{\mathcal{D}} \newcommand{\CE}{\mathcal{E}} \newcommand{\CF}{\mathcal{F}} \newcommand{\CG}{\mathcal{G}} \newcommand{\CH}{\mathcal{H}} \newcommand{\CI}{\mathcal{I}} \newcommand{\CJ}{\mathcal{J}} \newcommand{\CK}{\mathcal{K}} \newcommand{\CL}{\mathcal{L}} \newcommand{\CM}{\mathcal{M}} \newcommand{\CN}{\mathcal{N}} \newcommand{\CO}{\mathcal{O}} \newcommand{\CP}{\mathcal{P}} \newcommand{\CQ}{\mathcal{Q}} \newcommand{\CR}{\mathcal{R}} \newcommand{\CS}{\mathcal{S}} \newcommand{\CT}{\mathcal{T}} \newcommand{\CU}{\mathcal{U}} \newcommand{\CV}{\mathcal{V}} \newcommand{\CW}{\mathcal{W}} \newcommand{\CX}{\mathcal{X}} \newcommand{\CY}{\mathcal{Y}} \newcommand{\CZ}{\mathcal{Z}} % \newcommand{\KA}{\mathfrak{A}} \newcommand{\KB}{\mathfrak{B}} \newcommand{\KC}{\mathfrak{C}} \newcommand{\KD}{\mathfrak{D}} \newcommand{\KE}{\mathfrak{E}} \newcommand{\KF}{\mathfrak{F}} \newcommand{\KG}{\mathfrak{G}} \newcommand{\KH}{\mathfrak{H}} \newcommand{\KI}{\mathfrak{I}} \newcommand{\KJ}{\mathfrak{J}} \newcommand{\KK}{\mathfrak{K}} \newcommand{\KL}{\mathfrak{L}} \newcommand{\KM}{\mathfrak{M}} \newcommand{\KN}{\mathfrak{N}} \newcommand{\KO}{\mathfrak{O}} \newcommand{\KP}{\mathfrak{P}} \newcommand{\KQ}{\mathfrak{Q}} \newcommand{\KR}{\mathfrak{R}} \newcommand{\KS}{\mathfrak{S}} \newcommand{\KT}{\mathfrak{T}} \newcommand{\KU}{\mathfrak{U}} \newcommand{\KV}{\mathfrak{V}} \newcommand{\KW}{\mathfrak{W}} \newcommand{\KX}{\mathfrak{X}} \newcommand{\KY}{\mathfrak{Y}} \newcommand{\KZ}{\mathfrak{Z}} \newcommand{\Ka}{\mathfrak{a}} \newcommand{\Kb}{\mathfrak{b}} \newcommand{\Kc}{\mathfrak{c}} \newcommand{\Kd}{\mathfrak{d}} \newcommand{\Ke}{\mathfrak{e}} \newcommand{\Kf}{\mathfrak{f}} \newcommand{\Kg}{\mathfrak{g}} \newcommand{\Kh}{\mathfrak{h}} \newcommand{\Ki}{\mathfrak{i}} \newcommand{\Kj}{\mathfrak{j}} \newcommand{\Kk}{\mathfrak{k}} \newcommand{\Kl}{\mathfrak{l}} \newcommand{\Km}{\mathfrak{m}} \newcommand{\Kn}{\mathfrak{n}} \newcommand{\Ko}{\mathfrak{o}} \newcommand{\Kp}{\mathfrak{p}} \newcommand{\Kq}{\mathfrak{q}} \newcommand{\Kr}{\mathfrak{r}} \newcommand{\Ks}{\mathfrak{s}} \newcommand{\Kt}{\mathfrak{t}} \newcommand{\Ku}{\mathfrak{u}} \newcommand{\Kv}{\mathfrak{v}} \newcommand{\Kw}{\mathfrak{w}} \newcommand{\Kx}{\mathfrak{x}} \newcommand{\Ky}{\mathfrak{y}} \newcommand{\Kz}{\mathfrak{z}} % \newcommand{\Kzero }{\mathfrak{0}} \newcommand{\Kone }{\mathfrak{1}} \newcommand{\Ktwo }{\mathfrak{2}} \newcommand{\Kthree}{\mathfrak{3}} \newcommand{\Kfour }{\mathfrak{4}} \newcommand{\Kfive }{\mathfrak{5}} \newcommand{\Ksix }{\mathfrak{6}} \newcommand{\Kseven}{\mathfrak{7}} \newcommand{\Keight}{\mathfrak{8}} \newcommand{\Knine }{\mathfrak{9}} % $

    $ \newcommand{\div}{\mathop{\rm div}\nolimits} \newcommand{\llbracket}{[[} \newcommand{\rrbracket}{]]} $

    In lecture notes related to the Discontinuous Galerkin method, there is mention of a magic formula which AFAIK first appeared on a paper1 by Douglas Arnold (at least in this context).

    It has been proven and all, but it’s still called magic because its reasoning is not apparent at first glance. The magic formula is actually a superset of the divergence theorem, generalized to discontinuous fields. But to make that generalization, we need to abandon the standard formulation which starts by creating a triangular mesh, and consider arbitrary partitionings of a domain.

    A domain $\Omega$ is partitioned into parts $P^i$, $i=1,\dots,n$ as follows:

    \[\Omega=\bigcup_{i=1}^{n} P^i\] \[\mathcal{P} = \{P^1,\dots,P^{n}\}\]

    We call the set of parts $\mathcal{P}$ a partition of $\Omega$.

    Broken Hilbert Spaces

    We allow the vector field $\boldsymbol{u}$ to be discontinuous at boundaries $\partial P^i$ and continuous in $P^i$, $i=1,\dots,n$. To this end, we define the broken Hilbert space over partition $\mathcal{P}$

    \[\begin{equation} H^m(\mathcal{P}) := \{\boldsymbol{v}\in L^2(\Omega)^{n_d} \mid \forall P\in\mathcal{P}, \boldsymbol{v}|_P \in H^m(P)\} \end{equation}\]

    It can be seen that $H^m(\mathcal{P})\subseteq H^m(\Omega)$.

    Part Boundaries

    Topologically, a part may share boundary with $\Omega$, like $P^4$. In that case, the boundary of the part is divided into an interior boundary and exterior boundary:

    \[\begin{equation} \partial P_{\text{ext}}^i = \partial P^i \cap \partial\Omega \quad\text{and}\quad \partial P_{\text{int}}^i = \partial P^i \setminus \partial P_{\text{ext}}^i \end{equation}\]

    If a part has an exterior boundary, it is said to be an external part ($P^3$, $P^4$, $P^5$, $P^6$). If it does not have any exterior boundary, it is said to be an internal part.($P^1$, $P^2$).

    Divergence theorem over parts

    For a vector field $\boldsymbol{v}\in H^1(\mathcal{P})$, $i=1,\dots,n$, we can write the following integral as a sum and apply the divergence theorem afterward

    \[\begin{equation} \begin{aligned} \int_\Omega \div{\boldsymbol{v}} \,dV &= \sum\limits_{i=1}^{n}\int_{P^i}\div\boldsymbol{v} \,dV = \sum\limits_{i=1}^{n}\int_{\partial P^i} \boldsymbol{v}\cdot\boldsymbol{n} \,dA \\ &= \sum\limits_{i=1}^{n}\int_{\partial P_{\text{ext}}^i} \boldsymbol{v}\cdot\boldsymbol{n} \,dA +\sum\limits_{i=1}^{n}\int_{\partial P_{\text{int}}^i} \boldsymbol{v}\cdot\boldsymbol{n} \,dA \end{aligned} \end{equation}\]

    We define the portion $\Gamma^{ij}$ of the boundary that part $P^i$ shares with $P^j$ as the interface between $P^i$ and $P^j$.

    \[\begin{equation} \Gamma^{ij} = \partial P^i \cap \partial P^j \end{equation}\]

    If $P^i$ and $P^j$ are not neighbors, we simply have $\Gamma^{ij}=\emptyset$.

    Integrals over interior boundaries

    For opposing parts $P^i$ and $P^j$,

    we have different values of the function $\boldsymbol{v}^{ij} = \boldsymbol{v}|_{\Gamma^{ij}}$ and conjugate normal vectors at the interface $\Gamma^{ij}$:

    \[\begin{equation} \boldsymbol{v}^{ij}\neq\boldsymbol{v}^{ji} \quad\text{and}\quad \boldsymbol{n}^{ij} = -\boldsymbol{n}^{ji} \end{equation}\]

    Since

    \[\begin{equation} \partial P_{\text{int}}^i = \bigcup_{j=1}^{n} \Gamma^{ij} \quad \text{for}\quad i=1,\dots,n \end{equation}\]

    we can rearrange the integral over interior boundaries as

    \[\begin{equation} \sum\limits_{i=1}^{n}\int_{\partial P_{\text{int}}^i} \boldsymbol{v}\cdot\boldsymbol{n} \,dA = \sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}\int_{\Gamma^{ij}} \boldsymbol{v}^{ij}\cdot\boldsymbol{n}^{ij} \,dA \end{equation}\]

    The jump operator

    Integrals over the same interface can be grouped together:

    \[\begin{equation} \sum\limits_{i=1}^{n}\sum\limits_{j=1}^{n}\int_{\Gamma^{ij}} \boldsymbol{v}^{ij}\cdot\boldsymbol{n}^{ij} \,dA = \sum\limits_{i=1}^{n}\sum\limits_{j=i}^{n}\int_{\Gamma^{ij}\equiv\Gamma^{ji}} (\boldsymbol{v}^{ij}\cdot\boldsymbol{n}^{ij} + \boldsymbol{v}^{ji}\cdot\boldsymbol{n}^{ji}) \,dA \end{equation}\]

    Defining the jump of $\boldsymbol{v}$ across $\Gamma^{ij}$

    \[\begin{equation} \llbracket\boldsymbol{v}\rrbracket_{\Gamma^{ij}} = \boldsymbol{v}^{ij} - \boldsymbol{v}^{ji} \end{equation}\]

    The jump of a function measures its discontinuity across interfaces. We can write

    \[\begin{equation} \int_{\Gamma^{ij}} \llbracket\boldsymbol{v}\rrbracket_{\Gamma^{ij}}\cdot\boldsymbol{n}^{ij} \,dA = \int_{\Gamma^{ij}} (\boldsymbol{v}^{ij}\cdot\boldsymbol{n}^{ij} + \boldsymbol{v}^{ji}\cdot\boldsymbol{n}^{ji}) \,dA \end{equation}\]

    We may drop the superscripts where there is no confusion.

    Interfaces and external boundaries

    It is convenient to group the interfaces:

    \[\begin{equation} \boxed{ \mathcal{I} := \{\Gamma^{ij}\mid i=1,\dots,n; j=i,\dots,n\} } \end{equation}\]

    which allows us to write

    \[\begin{equation} \sum\limits_{i=1}^{n}\sum\limits_{j=i}^{n} \int_{\Gamma^{ij}} \llbracket\boldsymbol{v}\rrbracket\cdot\boldsymbol{n} \,dA = \sum\limits_{\Gamma\in\mathcal{I}} \int_{\Gamma} \llbracket\boldsymbol{v}\rrbracket\cdot\boldsymbol{n}\,dA \end{equation}\]

    It’s obvious that the union of part external boundaries equals the domain boundary:

    \[\begin{equation} \bigcup_{i=1}^{n} \partial P_{\text{ext}}^i = \partial \Omega \end{equation}\]

    which allows us to write

    \[\begin{equation} \sum\limits_{i=1}^{n}\int_{\partial P_{\text{ext}}^i} \boldsymbol{v}\cdot\boldsymbol{n} \,dA = \int_{\partial\Omega} \boldsymbol{v}\cdot\boldsymbol{n} \,dA \end{equation}\]

    With the results obtained, we put forward a generalized version of the divergence theorem: Let $\boldsymbol{v}\in H^1(\mathcal{P})$ be a vector field. Then we have

    \[\begin{equation} \boxed{ \int_\Omega \div\boldsymbol{v} \,dV = \int_{\partial\Omega} \boldsymbol{v}\cdot\boldsymbol{n} \,dA + \sum\limits_{\Gamma\in\mathcal{I}} \int_{\Gamma} \llbracket\boldsymbol{v}\rrbracket\cdot\boldsymbol{n} \,dA } \end{equation}\]

    Verbally, the integral of the divergence of a vector field over a domain $\Omega$ equals its integral over the domain boundary $\partial\Omega$, plus the integral of its jump over part interfaces $\mathcal{I}$.

    In the case of a continuous field, the jumps vanish and this reduces to the regular divergence theorem.

    The Magic Formula

    There are different versions of the magic formula for scalar, vector and tensor fields, and for different IBVPs. I won’t try to derive them all, but give an example: If we were substitute a linear mapping $\boldsymbol{A}\boldsymbol{v}$ instead of $\boldsymbol{v}$, we would have the jump $\llbracket \boldsymbol{A}\boldsymbol{v} \rrbracket$ on the right-hand side.

    We introduce the vector and tensor average operator \(\{\cdot\}\)

    \[\begin{equation} \{\boldsymbol{v}\}_{\Gamma^{ij}} = \frac{1}{2} (\boldsymbol{v}^{ij} + \boldsymbol{v}^{ji}) \quad\text{and}\quad \{\boldsymbol{A}\}_{\Gamma^{ij}} = \frac{1}{2} (\boldsymbol{A}^{ij} + \boldsymbol{A}^{ji}) \end{equation}\]

    and tensor jump operator $\llbracket\cdot\rrbracket$

    \[\begin{equation} \llbracket\boldsymbol{A}\rrbracket_{\Gamma^{ij}} = \boldsymbol{A}^{ij} - \boldsymbol{A}^{ji} \end{equation}\]

    We also note the boundary jump/average property which is used on the integral over $\partial\Omega$

    \[\begin{equation} \boxed{ \{\boldsymbol{v}\} = \llbracket\boldsymbol{v}\rrbracket = \boldsymbol{v} \quad \text{on}\quad\partial\Omega } \label{eq:property1} \end{equation}\]

    (This property is used implicitly in many places, and often causes confusion).

    These definitions allow us to write the identity

    \[\begin{equation} \boxed{ \llbracket\boldsymbol{A}\boldsymbol{v}\rrbracket = \llbracket\boldsymbol{A}\rrbracket\{\boldsymbol{v}\} + \{\boldsymbol{A}\}\llbracket\boldsymbol{v}\rrbracket } \end{equation}\]

    which is easily proven when expanded.

    The different versions of the magic formula are obtained by substituting the identities above—or their analogs—in the discontinuous divergence theorem.

    1. Douglas N. Arnold. An interior penalty finite element method with discontinuous elements. SIAM J. Numer. Anal., 19(4):742–760, 1982.