Compute closed line integral of electric field in circuit I have a circuit where resistor is parallel to capacitor, which is charged with voltage U. How to compute line integral around closed loop to get the result of Kirchhof second law - $U_{capacitor}+I\cdot R=0$?
For beginning I splited it in two parts, starting from the capacitor positive plate through resistor:
$$\oint \vec{E} \cdot d \vec{l} = \int_{+R-}\vec{E_{R}} \cdot d \vec{l} + 
\int_{-C+} \vec{E_C} \cdot d\vec{l}$$
Since intensity of resistor is with the same direction as current density $\vec{j}$:
$$\int_{+R-}\vec{E_{R}} \cdot d \vec{l} = \int_{+R-} \rho \cdot \vec{j} \cdot d \vec{l} = I \cdot R$$
When I do the same for capacitor I gain negative line integral, because the $E_{c}$ is opposite to $d \vec{l}$ when positive charge is moved from negative plate to the positive.
So in which part I have made a mistake?
 A: Here's a step-by-step analysis:
Assign potential $V=0$ to node "-", and potential $V_+$ to node "+".  $V_+$ could be either positive or negative, but I'll be assuming positive for definiteness.  Clearly, if you compute the line integral $\boldsymbol{E}$ around the circuit, you get a result of 0.  I'll use the direction of integration in your question to analyze the elements of that integral.  (You could take the opposite sense and get the same result.)


*

*Resistor.  Your integral across the resistor, from node "+" to node "-", is correct, with result $IR$.  If $V_+> 0$, the electric field will be parallel to $d \boldsymbol{l}$ and you find $I>0$, meaning current is flowing into the "+" node of the resistor, through the resistor, and out the "-" node.

*Capacitor, integrating from node "-" to node "+".  I'll assign the capacitor potential $U_{capacitor} = V_+$, so that the capacitor's "plus" plate (which could have either sign of charge and voltage) is connected to node "+".  Now, if $V_+=U_{capacitor}>0$ the electric field in the capacitor will point from the cap's "plus" plate to its "minus" plate, because $\boldsymbol{E} = - \boldsymbol{\nabla} U$ by definition (that is, $\boldsymbol{E}$ points from high $U$ to low $U$).  Then, in your integral, the electric field in the capacitor will be anti-parallel to $d \boldsymbol{l}$, and you get a negative result for this contribution: $-U_{capacitor}.  


Adding the two pieces, which must sum to 0, you get:
$$ -U_{capacitor} + IR = 0 \text{ , or}\\
U_{capacitor} = IR $$
Finally, by convention one takes $q$ to be the charge on the "plus" plate of the capacitor (here at node "+"), so that $q=C U_{capacitor}$.  Then $dq/dt$ represents the charge flowing into the capacitor's "+" node (through the part, and out the "-" node), which is the opposite of the resistor current:
$$ \frac{dq}{dt} = -I $$
Since $q= C U_{capacitor}$, the above loop equation can be re-written as:
$$ \frac{q}{C} = - \frac{dq}{dt} R \text{ , or} \\
\frac{q}{RC} + \frac{dq}{dt} = 0 $$
A: Choose the negative plate of the capacitor as ground, $V=0$. The usual convention is that the electric field lines are drawn in the direction that a positive test charge would move if placed in the field. Then $\int_{-C+} d\vec{l}\cdot \vec{E}_C > 0$ if I traverse the circuit from the negative plate to the positive plate of the capacitor.
A: So after long I found why the equality:
$$ U_{capacitor} + I\cdot R =0$$
Is somehow correct for calculating passed charge and current in time when the differential equation is solved. The point is that the circulation is calculated correct in way:
$$\oint_{R+C} \vec E \, d\vec l=\int_{+C-} \vec E_C\,d \vec l+\int_{-R+}\vec E_R\,d\vec l= [  \begin{array}f \vec E_C &\mbox{is with the same direction as  $d\vec l$}\\
\vec E_R &\mbox{since $\vec J = \sigma\,\vec E_R$ but current in chosen direction is opposite } 
 \end{array} ] =\\ =  \frac{q}{C} - I \cdot R$$
Which according to $\nabla \times \vec E =\vec{0}$ is $0$. If the problem is to get charge $q$ on capacitor at time t, the current is rewritten as $I = |\frac{dq}{dt}|$, but since q on capacitor decreases the $\frac{dq}{dt}<0$ so the result:
$$ \frac{q}{C} + \frac{dq}{dt}=0$$
Which becomes my question if the current direction is chosen to charge the capacitor.
