'''
Created on 01-Apr-2021
@author: rishi_priyansh
'''

import random
import inspect
import traceback
from sympy import (symbols, Symbol)
import os

from xv.km.util import latex_fraction, latex_atom
from .....helper import BaseHelper

from xv.km.managers import BaseManager
from xv.km.kelements import KProblemTemplate
        
class GasStateManager(BaseManager):
    '''
    GasStateManager
    Example:
        ke = GasStateManager()
        ke.getRandomProblem()
        ke.getRandomProblem(problem_type = 0)
        ...
        
        ke.printProblem()
        ke.printAnswer()
        ke.printSolution()
        
        ke.printProblemTypes()
        
    '''    
    _OPR_TYPE_COUNT = 10
    
    def __new__(cls, *args, **kwargs):
        instance = super(GasStateManager, cls).__new__(cls, *args, **kwargs)
        for base_class in GasStateManager.__bases__:
            base_class.__init__(instance, *args, **kwargs)
        return instance
    
    def __init__(self, *args, **kwargs):
        pass



    def _init_problem_types(self, *args, **kwargs):
        self._append_problem_types([
            '_problem_2_1',
			'_problem_2_2',
			'_problem_2_3',
			'_problem_2_4',
			'_problem_2_5',
			'_problem_2_6',
			'_problem_2_7',
			'_problem_2_8',
			'_problem_2_9',
			'_problem_2_10',
			'_problem_2_11',
			'_problem_2_12',
			'_problem_2_13',
			'_problem_2_14',
			'_problem_2_15',
			'_problem_2_16',
			'_problem_2_17',
			'_problem_2_18',
			'_problem_2_19',
			'_problem_2_20',
			'_problem_2_21',
			'_problem_2_22',
			'_problem_2_23',
			'_problem_2_24',
			'_problem_2_25',
            ])
        pass
            
    def _problem_2_1(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        A vessel of volume $V=30$ l contains ideal gas at the temperature $0^{{\\circ}} \\mathrm{{C}}$. After a portion of the gas has been let out, the pressure in the vessel decreased by $\\Delta p=0.78$ atm (the temperature remaining constant). Find the mass of the released gas. The gas density under the normal conditions $\\rho=1.3 \\mathrm{{~g}} / \\mathrm{{l}}$.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        Let $m_1$ and $m_2$ be the masses of the gas in the vessel before and after the gas is released. Hence mass of the gas released,
        $\\Delta m=m_1-m_2$
        Now from ideal gas equation
        $\\displaystyle p_1 V=m_1 \\frac{{R}}{{M}} T_0 \\text {{ and }} p_2 V=m_2 \\frac{{R}}{{M}} T_0$
        as $V$ and $T$ are same before and after the relcase of the gas.
        $\\begin{{aligned}}
        &\\text{{so, }} \\qquad& \\left(p_1-p_2\\right) V & =\\left(m_1-m_2\\right) \\frac{{R}}{{M}} T_0=\\Delta m \\frac{{R}}{{M}} T_0 \\\\
        &\\text{{or, }} \\qquad& \\Delta m & =\\frac{{\\left(p_1-p_2\\right) V M}}{{R T_0}}=\\frac{{\\Delta p V M}}{{R T_0}} \\qquad (1)
        \\end{{aligned}}$
        We also know $\\displaystyle p=\\rho \\frac{{R}}{{M}} T$ so, $\\displaystyle \\frac{{M}}{{R T_0}}=\\frac{{\\rho}}{{p_0}} \\qquad (2)$
        (where $p_0=$ standard atmospheric pressure and $T_0=273 \\mathrm{{~K}}$ )
        From Eqs. (1) and (2) we get
        $\\displaystyle \\Delta m=\\rho V \\cdot \\frac{{\\Delta p}}{{p_0}}=1.3 \\times 30 \\times \\frac{{0.78}}{{1}}=30 \\mathrm{{~g}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_2(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        Two identical vessels are connected by a tube with a valve letting the gas pass from one vessel into the other if the pressure difference $\\Delta p \\geqslant 1.10 \\mathrm{{~atm}}$. Initially there was a vacuum in one vessel while the other contained ideal gas at a temperature $t_1=27^{{\\circ}} \\mathrm{{C}}$ and pressure $p_1=1.00 \\mathrm{{~atm}}$. Then both vessels were heated to a temperature $t_2=107^{{\\circ}} \\mathrm{{C}}$. Up to what value will the pressure in the first vessel (which had vacuum initially) increase?
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        Let $m_1$ be the mass of the gas enclosed.
        Then, $p_1 V=v_1 R T_1$
        When heated, some gas, passes into the evacuated vessel till prēssure difference becomes $\\Delta p$. Let $p_1^{{\\prime}}$ and $p_2^{{\\prime}}$ be the pressure on the two sides of the valve. Then $p_1^{{\\prime}} V=v_1^{{\\prime}} R T_2$ and
        $\\displaystyle p_2^{{\\prime}} V=v_2^{{\\prime}} R T_2=\\left(v_1-v_1^{{\\prime}}\\right) R T_2$
        $\\displaystyle p_2^{{\\prime}} V=\\left(\\frac{{p_1 V}}{{R T_1}}-\\frac{{p_1^{{\\prime}} V}}{{R T_2}}\\right) \\quad \\text {{ or }} \\quad p_2^{{\\prime}}=\\left(\\frac{{p_1}}{{T_1}}-\\frac{{p_1^{{\\prime}}}}{{T_2}}\\right) T_2$
        But, $p_1^{{\\prime}}-p_2^{{\\prime}}=\\Delta p$
        $\\begin{{aligned}}
        &\\text{{So, }}\\qquad &p_2^{{\\prime}} & =\\left(\\frac{{p_1}}{{T_1}}-\\frac{{p_2^{{\\prime}}+\\Delta p}}{{T_2}}\\right) T_2 \\\\
        &&& =\\frac{{p_1 T_2}}{{T_1}}-p_2^{{\\prime}}-\\Delta p \\\\
        &\\text{{or, }}\\qquad &p_2^{{\\prime}} & =\\frac{{1}}{{2}}\\left(\\frac{{p_1 T_2}}{{T_1}}-\\Delta p\\right)=0.08 \\mathrm{{~atm}}
        \\end{{aligned}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_3(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        A vessel of volume $V=20$ l contains a mixture of hydrogen and helium at a temperature $t=20^{{\\circ}} \\mathrm{{C}}$ and pressure $p=2.0 \\mathrm{{~atm}}$. The mass of the mixture is equal to $m=5.0 \\mathrm{{~g}}$. Find the ratio of the mass of hydrogen to that of helium in the given mixture.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        Let the mixture contain $v_1$ and $v_2$ moles of $H_2$ and $H_e$ respectively. If molecular weights of $H_2$ and $H_e$ are $M_1$ and $M_2$, then respective masses in the mixture are equal to
        $\\displaystyle m_1=v_1 M_1 \\text {{ and }} m_2=v_2 M_2$
        Therefore, for the total mass of the mixture we get,
        $m=m_1+m_2 \\text {{ or }} m=v_1 M_1+v_2 M_2 \\qquad (1)$
        Also, if $v$ is the total number of moles of the mixture in the vessels, then we know,
        $\\displaystyle v=v_1+v_2 \\qquad (2)$
        Solving (1) and (2) for $v_1$ and $v_2$, we get,
        $\\displaystyle v_1=\\frac{{\\left(v M_2-m\\right)}}{{M_2-M_1}}, \\quad v_2=\\frac{{m-v M_1}}{{M_2-M_1}}$
        Therefore, we get $\\displaystyle m_1=M_1 \\cdot \\frac{{\\left(v M_2-m\\right)}}{{M_2-M_1}}$ and $m_2=M_2 \\frac{{\\left(m-v M_1\\right)}}{{M_2-M_1}}$
        or, $\\displaystyle \\frac{{m_1}}{{m_2}}=\\frac{{M_1}}{{M_2}} \\frac{{\\left(v M_2-m\\right)}}{{\\left(m-v M_1\\right)}}$
        One can also express the above result in terms of the effective molecular weight $M$ of the mixture, defined as,
        $\\displaystyle M=\\frac{{m}}{{v}}=m \\frac{{R T}}{{p V}}$
        Thus, $\\displaystyle \\frac{{m_1}}{{m_2}}=\\frac{{M_1}}{{M_2}} \\cdot \\frac{{M_2-M}}{{M-M_1}}=\\frac{{1-M / M_2}}{{M / M_1-1}}$
        Using the data and table, we get :
        $\\displaystyle M=3.0 \\mathrm{{~g}} \\text {{ and, }} \\frac{{m_1}}{{m_2}}=0.50$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_4(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        A vessel contains a mixture of nitrogen $\\left(m_1=7.0 \\mathrm{{~g}}\\right)$ and carbon dioxide $\\left(m_2=11 \\mathrm{{~g}}\\right)$ at a temperature $T=290 \\mathrm{{~K}}$ and pressure $p_0=1.0 \\mathrm{{~atm}}$. Find the density of this mixture, assuming the gases to be ideal.

        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        We know, for the mixture, $\\mathrm{{N}}_2$ and $\\mathrm{{CO}}_2$ (being regarded as ideal gases, their mixture too behaves like an ideal gas)
        $p V=v R T, \\text {{ so }} p_0 V=v R T$
        where, $v$ is the total number of moles of the gases (mixture) present and $V$ is the volume of the vessel. If $v_1$ and $v_2$ are number of moles of $\\mathrm{{N}}_2$ and $\\mathrm{{CO}}_2$ respectively present in the mixture, then
        $v=v_1+v_2$
        Now number of moles of $\\mathrm{{N}}_2$ and $\\mathrm{{CO}}_2$ is, by definition, given by
        $\\displaystyle v_1=\\frac{{m_1}}{{M_1}} \\text {{ and, }} \\quad v_2=\\frac{{m_2}}{{M_2}}$
        where, $m_1$ is the mass of $N_2$ (Moleculer weight $=M_1$ ) in the mixture and $m_2$ is the mass of $\\mathrm{{CO}}_2$ (Molecular weight $=M_2$ ) in the mixture.
        Therefore density of the mixture is given by
        $\\begin{{gathered}}
        \\rho=\\frac{{m_1+m_2}}{{V}}=\\frac{{m_1+m_2}}{{\\left(v R T / P_0\\right)}} \\\\
        =\\frac{{p_0}}{{R T}} \\cdot \\frac{{m_1+m_2}}{{v_1+v_2}}=\\frac{{p_0\\left(m_1+m_2\\right) M_1 M_2}}{{R T\\left(m_1 M_2+m_2 M_1\\right)}} \\\\
        =1 \\cdot 5 \\mathrm{{~kg}} / \\mathrm{{m}}^3 \\text {{ on substitution }}
        \\end{{gathered}}$
        """ 
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_5(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        A vessel of volume $V=7.5 \\mathrm{{l}}$ contains a mixture of ideal gases at a temperature $T=300 \\mathrm{{~K}}: v_1=0.10$ mole of oxygen, $v_2=0.20$ mole of nitrogen, and $v_3=0.30$ mole of carbon dioxide. Assuming the gases to be ideal, find:
        (a) the pressure of the mixture;
        (b) the mean molar mass $M$ of the given mixture which enters its equation of state $p V=(m / M) R T$, where $m$ is the mass of the mixture.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        (a) The mixture contains $v_1, v_2$ and $v_3$ moles of $\\mathrm{{O}}_2, \\mathrm{{~N}}_2$ and $\\mathrm{{CO}}_2$ respectively. Then the total number of moles of the mixture
        $v=v_1+v_2+v_3$
        We know, ideal gas equation for the mixture
        $\\displaystyle p V=v R T \\text {{ or }} p=\\frac{{v R T}}{{V}}$
        or, $\\displaystyle p=\\frac{{\\left(v_1+v_2+v_3\\right) R T}}{{V}}=1.968 \\text {{ atm on substitution }}$
        (b) Mass of oxygen $\\left(O_2\\right)$ present in the mixture : $m_1=v_1 M_1$
        Mass of nitrogen $\\left(N_2\\right)$ present in the mixture : $m_2=v_2 M_2$
        Mass of carbon dioxide $\\left(\\mathrm{{CO}}_2\\right)$ present in the mixture : $m_3=v_3 M_3$
        So, mass of the mixture
        $m=m_1+m_2+m_3=v_1 M_1+v_2 M_2+v_3 M_3$
        Moleculer mass of the mixture $\\displaystyle : M=\\frac{{\\text {{ mass of the mixture }}}}{{\\text {{ total number of moles }}}}$
        $\\displaystyle =\\frac{{v_1 M_1+v_2 M_2+v_3 M_3}}{{v_1+v_2+v_3}}=36 \\cdot 7 \\mathrm{{~g}} / \\mathrm{{mol}} . \\text {{ on substitution }}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_6(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        A vertical cylinder closed from both ends is equipped with an easily moving piston dividing the volume into two parts, each containing one mole of air. In equilibrium at $T_0=300 \\mathrm{{~K}}$ the volume of the upper part is $\\eta=4.0$ times greater than that of the lower part. At what temperature will the ratio of these volumes be equal to $\\eta^{{\\prime}}=3.0 ?$

        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        Let $p_1$ and $p_2$ be the pressure in the upper and lower part of the cylinder respectively at temperature $T_0$. At the equilibrium position for the piston :
        $p_1 S+m g=p_2 S$ or, $\\displaystyle p_1+\\frac{{m g}}{{S}}=p_2$ ( $m$ is the mass of the piston.)
        But $p_1=\\frac{{R T_0}}{{\\eta V_0}}$ (where $V_0$ is the initial volume of the lower part)
        So, $\\displaystyle \\frac{{R T_o}}{{\\eta V_0}}+\\frac{{m g}}{{S}}=\\frac{{R T_0}}{{V_0}} \\text {{ or, }} \\quad \\frac{{m g}}{{S}}=\\frac{{R T_0}}{{V_0}}\\left(1-\\frac{{1}}{{\\eta}}\\right) \\qquad (1)$
        Let $T$ be the sought temperature and at this temperature the volume of the lower part becomes $V^{{\\prime}}$, then according to the problem the volume of the upper part becomes $\\eta^{{\\prime}} V^{{\\prime}}$
        Hence, $\\displaystyle \\frac{{m g}}{{S}}=\\frac{{R T}}{{V^{{\\prime}}}}\\left(1-\\frac{{1}}{{\\eta^{{\\prime}}}}\\right) \\qquad (2)$
        From (1) and (2).
        $\\displaystyle \\frac{{R T_0}}{{V_0}}\\left(1-\\frac{{1}}{{\\eta}}\\right)=\\frac{{R T}}{{V^{{\\prime}}}}\\left(1-\\frac{{1}}{{\\eta^{{\\prime}}}}\\right) \\text {{ or, }} T=\\frac{{T_0\\left(1-\\frac{{1}}{{\\eta}}\\right) V^{{\\prime}}}}{{V_0\\left(1-\\frac{{1}}{{\\eta^{{\\prime}}}}\\right)}}$
        As, the total volume must be constant,
        $\\displaystyle V_0(1+\\eta)=V^{{\\prime}}\\left(1+\\eta^{{\\prime}}\\right) \\text {{ or, }} V^{{\\prime}}=\\frac{{V_0(1+\\eta)}}{{\\left(1+\\eta^{{\\prime}}\\right)}}$
        Putting the value of $V^{{\\prime}}$ in Eq. (3), we get
        $\\displaystyle \\begin{{aligned}}
        T & =\\frac{{T_0\\left(1-\\frac{{1}}{{\\eta}}\\right) V_0 \\frac{{(1+\\eta)}}{{\\left(1+\\eta^{{\\prime}}\\right)}}}}{{V_0\\left(1-\\frac{{1}}{{\\eta^{{\\prime}}}}\\right)}} \\\\
        & =\\frac{{T_0\\left(\\eta^2-1\\right) \\eta^{{\\prime}}}}{{\\left(\\eta^{{\\prime 2}}-1\\right) \\eta}}=0.42 \\mathrm{{k}} \\mathrm{{K}}
        \\end{{aligned}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_7(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        A vessel of volume $V$ is evacuated by means of a piston air pump. One piston stroke captures the volume $\\Delta V$. How many strokes are needed to reduce the pressure in the vessel $\\eta$ times? The process is assumed to be isothermal, and the gas ideal.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        Let $\\rho_1$ be the density after the first stroke. The the mass remains constant
        $\\displaystyle V \\rho=(V+\\Delta V) \\rho_1, \\quad \\text {{ or, }} \\quad \\rho_1=\\frac{{V \\rho}}{{(V+\\Delta V)}}$
        Similarly, if $\\rho_2$ is the density after second stroke
        $\\displaystyle V \\rho_1=(V+\\Delta V) \\rho_2 \\text {{ or, }} \\rho_2=\\left(\\frac{{V}}{{V+\\Delta V}}\\right) \\rho_1=\\left(\\frac{{V}}{{V+\\Delta V}}\\right)^2 \\rho_0$
        In this way after $n$th stroke.
        $\\displaystyle \\rho_n=\\left(\\frac{{V}}{{V+\\Delta V}}\\right)^n \\rho_0$
        Since pressure $\\alpha$ density,
        $\\displaystyle p_n=\\left(\\frac{{V}}{{V+\\Delta V}}\\right)^n p_0 \\quad \\text {{ (because temperature is constant.) }}$
        It is required by $\\displaystyle \\frac{{p_n}}{{p_0}}$ to be $\\displaystyle \\frac{{1}}{{\\eta}}$
        so, $\\displaystyle \\frac{{1}}{{\\eta}}=\\left(\\frac{{V}}{{V+\\Delta V}}\\right)^n \\text {{ or, }} \\quad \\eta=\\left(\\frac{{V+\\Delta V}}{{V}}\\right)^n$
        Hence $\\displaystyle n=\\frac{{\\ln \\eta}}{{\\ln \\left(1+\\frac{{\\Delta V}}{{V}}\\right)}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_8(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        Find the pressure of air in a vessel being evacuated as a function of evacuation time $t$. The vessel volume is $V$, the initial pressure is $p_0$. The process is assumed to be isothermal, and the evacuation rate equal to $C$ and independent of pressure.
        Note. The evacuation rate is the gas volume being evacuated per unit time, with that volume being measured under the gas pressure attained by that moment.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        From the ideal gas equation $\\displaystyle p=\\frac{{m}}{{M}} \\frac{{R T}}{{V}}$
        $\\displaystyle \\frac{{d p}}{{d t}}=\\frac{{R T}}{{M V}} \\frac{{d m}}{{d t}} \\qquad (1)$
        In each stroke, volume $v$ of the gas is ejected, where $v$ is given by
        $\\displaystyle v=\\frac{{V}}{{m_N}}\\left[m_{{N-1}}-m_N\\right]$
        In case of continuous ejection, if $\\left(m_{{N-1}}\\right)$ corresponds to mass of gas in the vessel at time $t$, then $m_N$ is the mass at time $t+\\Delta t$, where $\\Delta t$, is the time in which volume $v$ of the gas has come out. The rate of evacuation is therefore $\\displaystyle \\frac{{v}}{{\\Delta t}}$ i.e.
        $\\displaystyle C=\\frac{{v}}{{\\Delta t}}=-\\frac{{V}}{{m(t+\\Delta t)}} \\cdot \\frac{{m(t+\\Delta t)-m(t)}}{{\\Delta t}}$
        In the limit $\\Delta t-0$, we get
        $\\displaystyle C=\\frac{{V}}{{m}} \\frac{{d m}}{{d t}}\\qquad (2)$
        From (1) and (2)
        $\\displaystyle \\frac{{d p}}{{d t}}=-\\frac{{C}}{{V}} \\frac{{m R T}}{{M V}}=-\\frac{{C}}{{V}} p \\quad \\text {{ or }} \\quad \\frac{{d p}}{{p}}=-\\frac{{C}}{{V}} d t$
        Integrating $\\displaystyle \\int_p^{{p_0}} \\frac{{d p}}{{p}}=-\\frac{{C}}{{V}} \\int_t^0 d t$ or $\\ln \\frac{{p}}{{p_0}}=-\\frac{{C}}{{V}} t$
        Thus $p=p_0 e^{{-c t / V}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_9(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        A chamber of volume $V=871$ is evacuated by a pump whose evacuation rate (see Note to the foregoing problem) equals $C=$ $=10 \\mathrm{{l}} / \\mathrm{{s}}$. How soon will the pressure in the chamber decrease by $\\eta=1000$ times?

        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        Let $\\rho$ be the instantaneous density, then instantaneous mass $=V_\\rho$. In a short interval $d t$ the volume is increased by $C d t$.
        So, $\\quad V \\rho=(V+C d t)(\\rho+d \\rho)$
        (because mass remains constant in a short interval $d t$ )
        so, $\\displaystyle \\frac{{d \\rho}}{{\\rho}}=-\\frac{{C}}{{V}} d t$
        Since pressure $\\alpha$ density $\\frac{{d p}}{{p}}=-\\frac{{C}}{{V}} d t$
        or $\\displaystyle \\int_{{p_1}}^{{p_2}}-\\frac{{d p}}{{p}}=\\frac{{C}}{{V}} t$
        or $\\displaystyle t=\\frac{{V}}{{C}} \\ln \\frac{{p_1}}{{p_2}}=\\frac{{V}}{{C}} \\ln \\frac{{1}}{{\\eta}} 1 \\cdot 0 \\min$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_10(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        A smooth vertical tube having two different sections is open from both ends and equipped with two pistons of different areas (Fig. 2.1). Each piston slides within a respective tube section. One mole of ideal gas is enclosed between the pistons tied with a non-stretchable thread. The crosssectional area of the upper piston is $\\Delta S=10 \\mathrm{{~cm}}^2$ greater than that of the lower one. The combined mass of the two pistons is equal to $m=5.0 \\mathrm{{~kg}}$. The outside air pressure is $p_0=1.0 \\mathrm{{~atm}}$. By how many kelvins must the gas between the pistons be heated to shift the pistons through $l=5.0 \\mathrm{{~cm}}$ ?
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        file_name = 'problems-in-general-physics-fig-2-1.png'
        file_path = self._init_file_path(file_name)        
        problemTemplate.add_problem(file_path, 'image/jpg')
        
        soln_s = f"""
        The physical system consists of one mole of gas confined in the smooth vertical tube. Let $m_1$ and $m_2$ be the masses of upper and lower pistons and $S_1$ and $S_2$ are their respective areas.
        For the lower piston
        $p S_2+m_2 g=p_0 S_2+T,$
        or, $T=\\left(p-p_0\\right) S_2+m_2 g \\qquad (1)$
        Similarly for the upper piston
        $p_0 S_1+T+m_1 g=p S_1$
        or, $T=\\left(p-p_0\\right) S_1-m_1 g \\qquad (2)$
        From (1) and (2)
        $\\left(p-p_0\\right)\\left(S_1-S_2\\right)=\\left(m_1+m_2\\right) \\xi$
        or, $\\left(p-p_0\\right) \\Delta S=m g$
        so, $\\displaystyle \\quad p=\\frac{{m g}}{{\\Delta S}}+p_0=$ constant
        From the gas law, $p V=v R T$
        $p \\Delta V=\\vee R \\Delta T$ (because $p$ is constant)
        So, $\\displaystyle \\left(p_0+\\frac{{m g}}{{\\Delta S}}\\right) \\Delta S l=R \\Delta T,$
        Hence, $\\displaystyle \\Delta T=\\frac{{1}}{{R}}\\left(p_0 \\Delta S+m g\\right) l=0.9 \\mathrm{{~K}}$

        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_11(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        Find the maximum attainable temperature of ideal gas in each of the following processes:
        (a) $p=p_0-\\alpha V^2$ ;
        (b) $p=p_0 \\mathrm{{e}}^{{-\\beta v}}$,
        where $p_0, \\alpha$ and $\\beta$ are positive constants, and $V$ is the volume of one mole of gas.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        (a)
        $\\begin{{aligned}}
        & p=p_0-\\alpha V^2=p_0-\\alpha\\left(\\frac{{R T}}{{p}}\\right)^2 \\\\
        & \\text {{(as, }} V=R T / p \\text {{ for one mole of gas) }} \\\\
        & \\text {{Thus, }} \\quad T=\\frac{{1}}{{R \\sqrt{{\\alpha}}}} p \\sqrt{{p_0-p}}=\\frac{{1}}{{R \\sqrt{{\\alpha}}}} \\sqrt{{p_0 p^2-p^3}} \\\\
        \\end{{aligned}}$
        For $\\displaystyle \\mathrm{{T}}_{{\\max }}, \\quad \\frac{{d}}{{d p}}\\left(p_0 p^2-p^3\\right)$ must be zero
        which yields, $\\displaystyle \\quad p=\\frac{{2}}{{3}} p_0$
        Hence, $\\displaystyle \\quad T_{{\\max }}=\\frac{{1}}{{R \\sqrt{{\\alpha}}}} \\cdot \\frac{{2}}{{3}} p_0 \\sqrt{{p_0-\\frac{{2}}{{3}} p_0}}=\\frac{{2}}{{3}}\\left(\\frac{{p_0}}{{R}}\\right) \\sqrt{{\\frac{{p_0}}{{3 \\alpha}}}}$
        (b) $\\displaystyle p=p_0 e^{{-\\beta V}}=p_0 e^{{-\\beta R T / P}}$
        so $\\displaystyle \\frac{{\\beta R T}}{{p}}=\\ln \\frac{{p_0}}{{p}}, \\text {{ and }} T=\\frac{{p}}{{\\beta R}} \\ln \\frac{{p_0}}{{p}}$
        For $T_{{\\max }}$ the condition is $\\frac{{d T}}{{d p}}=0$, which yields
        $\\displaystyle p=\\frac{{p_0}}{{e}}$
        Hence using this value of $p$ in Eq. (1), we get
        $\\displaystyle T_{{\\max }}=\\frac{{p_o}}{{e \\beta R}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_12(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        Find the minimum attainable pressure of ideal gas in the process $T=T_0+\\alpha V^2$, where $T_0$ and $\\alpha$ are positive constants, and $V$ is the volume of one mole of gas. Draw the approximate $p$ vs $V$ plot of this process.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        $\\displaystyle T=T_0+\\alpha V^2=T_0+\\alpha \\frac{{R^2 T^2}}{{p^2}}$
        (as, $V=R T / p$ for one mole of gas)
        So, $p=\\sqrt{{\\alpha}} R T\\left(T-T_0\\right)^{{1 / 2}} \\qquad (1)$
        $\\begin{{aligned}}
        \\text{{For }} \\qquad p_{{\\min }}, \\frac{{d p}}{{d T}} & =0, \\text {{ which gives }} \\\\
        T & =2 T_0 \\qquad (2)
        \\end{{aligned}}$
        From (1) and (2), we get,
        $p_{{\\min }}=\\sqrt{{\\alpha}} R 2 T_0\\left(2 T_0-T_0\\right)^{{-1 / 2}}=2 R \\sqrt{{\\alpha T_0}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_13(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        A tall cylindrical vessel with gaseous nitrogen is located in a uniform gravitational field in which the free-fall acceleration is equal to $g$. The temperature of the nitrogen varies along the height $h$ so that its density is the same throughout the volume. Find the temperature gradient $d T / d h$.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        Consider a thin layer at a height $h$ and thickness $d h$. Let $p$ and $d p+p$ be the pressure on the two sides of the layer. The mass of the layer is $S d h \\rho$. Equating vertical downward force to the upward force acting on the layer.
        $S d h \\rho g+(p+d p) S=p S$
        So, $\\displaystyle \\frac{{d p}}{{d h}}=-\\rho g$
        But, $\\displaystyle p=\\frac{{\\rho}}{{M}} R T$, we have $d p=\\frac{{\\rho R}}{{M}} d T$,
        So, $\\displaystyle \\quad \\frac{{d T}}{{d h}}=-\\frac{{g M}}{{R}}=-34 \\mathrm{{~K}} / \\mathrm{{km}}$
        That means, temperature of air drops by $34^{{\\circ}} \\mathrm{{C}}$ at a height of $1 \\mathrm{{~km}}$ above bottom.
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_14(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        Suppose the pressure $p$ and the density $\\rho$ of air are related as $p / \\rho^n=$ const regardless of height ( $n$ is a constant here). Find the corresponding temperature gradient.

        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        We have, $\\displaystyle \\frac{{d p}}{{d h}}=-\\rho g($ See 2.13$)$
        But, from $p=C \\rho^n$ (where $C$ is, $a$ const) $\\displaystyle \\frac{{d p}}{{d \\rho}}=C n \\rho^{{n-1}}$
        We have from gas low $p=\\rho \\frac{{R}}{{M}} T$, so using (2)
        $\\displaystyle C \\rho^n=\\rho \\frac{{R}}{{M}} \\cdot T, \\quad \\text {{ or }} \\quad T=\\frac{{M}}{{R}} C \\rho^{{n-1}}$
        $\\begin{{aligned}}
        &\\text{{Thus }} \\qquad \\frac{{d T}}{{d \\rho}}=\\frac{{M}}{{R}} \\cdot C(n-1) \\rho^{{n-2}} \\\\
        &\\text{{But, }} \\qquad \\frac{{d T}}{{d h}}=\\frac{{d T}}{{d \\rho}} \\cdot \\frac{{d \\rho}}{{d p}} \\cdot \\frac{{d p}}{{d h}}
        \\end{{aligned}}$
        So, $\\displaystyle \\quad \\frac{{d T}}{{d h}}=\\frac{{M}}{{R}} C(n-1) \\rho^{{n-2}} \\frac{{1}}{{C n \\rho^{{n-1}}}}(-\\rho g)=\\frac{{-M g(n-1)}}{{n R}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_15(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        Let us assume that air is under standard conditions close to the Earth's surface. Presuming that the temperature and the molar mass of air are independent of height, find the air pressure at the height 5.0 km over the surface and in a mine at the depth 5.0 km below the surface. 
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        We have, $d p=-\\rho g d h$ and from gas law $\\rho=\\frac{{M}}{{R T}} p$
        Thus $\\frac{{d p}}{{p}}=-\\frac{{M g}}{{R T}} d h$
        Integrating, we get
        $\\int_{{p_{{0}}}}^{{p}} \\frac{{d p}}{{p}}=-\\frac{{M g}}{{R T}} \\int_{{0}}^{{h}} d h \\text {{ or, }} \\ln \\frac{{p}}{{p_{{0}}}}=-\\frac{{M g}}{{R T}} h$
        (where $p_{{0}}$ is the pressure at the surface of the Earth.)
        $p=p_{{0}} e^{{-M g h / R T}}$
        [Under standard condition, $p_{{0}}=1 \\mathrm{{~atm}}, T=273 \\mathrm{{~K}}$
        Pressure at a height of $5 \\mathrm{{~atm}}=1 \\times e^{{-28 \\times 9.81 \\times 5000 / 8314 \\times 273}}=0.5 \\mathrm{{~atm}}$
        Pressure in a mine at a depth of $\\left.5 \\mathrm{{~km}}=1 \\times e^{{-28 \\times 9.81 \\times(-5000) / 8314 \\times 273}}=2 \\mathrm{{~atm}} .\\right]$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_16(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        Assuming the temperature and the molar mass of air, as well as the free-fall acceleration, to be independent of the height, find the difference in heights at which the air densities at the temperature 0C differ
        (a) e times;
        (b) $\\eta$ = 1.0%.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        We bave $d p=-\\rho g d h$ but from gas law $p=\\frac{{\\rho}}{{M}} R T$,
        Thus $d p=\\frac{{d \\rho}}{{M}} R T$ at const. temperature
        So, $\\frac{{d \\rho}}{{\\rho}}=\\frac{{g M}}{{R T}} d h$
        Integrating within limits $\\int_{{p_{{0}}}}^{{\\rho}} \\frac{{d \\rho}}{{\\rho}}=\\int_{{0}}^{{h}} \\frac{{g M}}{{R T}} d h$
        or, $\\ln \\frac{{\\rho}}{{\\rho_{{0}}}}=-\\frac{{g M}}{{R T}} h
        $So, $\\rho=\\rho_{{0}} e^{{-M g h / R T}}$ and $h=-\\frac{{R T}}{{M g}} \\ln \\frac{{\\rho}}{{\\rho_{{0}}}}$
        (a) Given $T=273^{{\\circ}} \\mathrm{{K}}, \\frac{{\\rho_{{0}}}}{{\\rho}}=e$
        Thus $h=-\\frac{{R T}}{{M g}} \\ln e^{{-1}}=8 \\mathrm{{~km}}$.
        (b) $T=273^{{\\circ}} \\mathrm{{K}}$ and
        $\\frac{{\\rho_{{0}}-\\rho}}{{\\rho_{{0}}}}=0.01 \\text {{ or }} \\frac{{\\rho}}{{\\rho_{{0}}}}=0.99$
        Thus $h=-\\frac{{R T}}{{M g}} \\ln \\frac{{\\rho}}{{\\rho_{{0}}}}=0.09 \\mathrm{{~km}} \\text {{ on substitution }}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_17(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        An ideal gas of molar mass M is contained in a tall vertical cylindrical vessel whose base area is S and height h. The temperature of the gas is T, its pressure on the bottom base is $p_0$. Assuming the temperature and the free-fall acceleration g to be independent of the height, find the mass of gas in the vessel.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        From the Barometric formula, we have
        $p=p_{{0}} e^{{-M g h / R T}}$
        and from gas law
        $\\rho=\\frac{{p M}}{{R T}}$
        So, at constant temperature from these two Eqs.
        $\\rho=\\frac{{M p_{{0}}}}{{R T}} e^{{-M_{{g}} h / R T}}=\\rho_{{0}} e^{{-M_{{g}} h R T}} \\qquad (1)$
        Eq. (1) shows that density varies with height in the same manner as pressure. Let us consider the mass element of the gas contained in the coltumn.
        $d m=\\rho(S d h)=\\frac{{M p_{{0}}}}{{R T}} e^{{-M g h / R T}} S d h$
        Hence the sought mass,
        $m=\\frac{{M p_{{0}} S}}{{R T}} \\int_{{0}}^{{h}} e^{{-M g h R T}} d h=\\frac{{p_{{0}} S}}{{g}}\\left(1-e^{{-M g h R T}}\\right)$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_18(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        An ideal gas of molar mass M is contained in a very tall vertical cylindrical vessel in the uniform gravitational field in which the free-fall acceleration equals g. Assuming the gas temperature to be the same and equal to T, find the height at which the centre of gravity of the gas is located.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        As the gravitational field is constant the centre of gravity and the centre of mass are same. The location of C.M.
        $h =\\frac{{\\int_{{0}}^{{\\infty}} h d m}}{{\\int_{{0}}^{{\\infty}} d m}} = \\frac{{\\int_{{0}}^{{\\infty}}  h \\rho d h}}{{\\int_{{0}}^{{\\infty}} \\rho d h}}$
        But from Barometric formula and gas law $\\rho=\\rho_{{0}} e^{{-M g h / R T}}$
        So, $\\displaystyle h=\\frac{{\\int_{{0}}^{{\\alpha}}h\\left(e^{{-M g h / R T}}\\right) d h}}{{\\int_{{0}}^{{\\alpha}}\\left(e^{{-M g h / R T}}\\right) d h}} = \\frac{{RT}}{{Mg}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_19(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        An ideal gas of molar mass $M$ is located in the uniform gravitational field in which the free-fall acceleration is equal to $g$. Find the gas pressure as a function of height $h$, if $p=p_{{0}}$ at $h=0$, and the temperature varies with height as
        (a) $T=T_{{0}}(1-a h) ;$ 
        (b) $T=T_{{0}}(1+a h)$ where $a$ is a positive constant.
        
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        (a) We know that the variation of pressure with height of a fluid is given by :
        $d p=-\\rho g d h$
        But from gas law $\\quad p=\\frac{{\\rho}}{{M}} R T$ or, $\\rho=\\frac{{p M}}{{R T}}$
        From these two Eqs.
        $d p=-\\frac{{p M g}}{{R T}} d h\\text {{(1)}}$
        or, $\\frac{{d p}}{{p}}=\\frac{{-M g d h}}{{R T_{{0}}(1-a h)}}$
        $\\begin{{gathered}}
        \\text{{Integrating, }}\\qquad \\int_{{p_{{0}}}}^{{p}} \\frac{{d p}}{{p}}=\\frac{{-M g}}{{R T_{{0}}}} \\int_{{0}}^{{h}} \\frac{{d h}}{{(1-a h)}}, \\text {{ we get }} \\\\
        \\ln \\frac{{p}}{{p_{{0}}}}=\\ln (1-a h)^{{M g / a R T_{{0}}}} \\\\
        \\text{{Hence, }}\\qquad p=p_{{0}}(1-a h)^{{M g / a R T_{{0}}}} \\text {{ Obvionsly }} h<\\frac{{1}}{{a}}
        \\end{{gathered}}$
        (b) Proceed up to Eq. (1) of part (a), and then put $T=T_{{0}}(1+a h)$ and proceed further in the same fashion to get
        $p=\\frac{{p_{{0}}}}{{(1+a h)^{{M g / a R T_{{0}}}}}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_20(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        A horizontal cylinder closed from one end is rotated with a constant angular velocity $\\omega$ about a vertical axis passing through the open end of the cylinder. The outside air pressure is equal to $p_0$, the temperature to $T$, and the molar mass of air to $M$. Find the air pressure as a function of the distance $r$ from the rotation axis. The molar mass is assumed to be independent of $r$.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        Let us consider the mass element of the gas (thin layer) in the cylinder at a distance $r$ from its open end as shown in the figure.
        Using Newton's second law for the element
        $\\begin{{gathered}}
        F_n=m w_n: \\\\
        (p+d p) S-p S=(\\rho S d r) \\omega^2 r
        \\end{{gathered}}$
        or, $\\displaystyle \\quad d p=\\rho \\omega^2 r d r=\\frac{{p M}}{{R T}} \\omega^2 r d r$
        $\\begin{{aligned}}
        &\\text {{So, }}&  \\frac{{d p}}{{p}}=\\frac{{M \\omega^2}}{{R T}} r d r &\\text {{ or, }} \\int_{{p_0}}^p \\frac{{d p}}{{p}}=\\frac{{M \\omega^2}}{{R T}} \\int_0^r r d r, \\\\
        &\\text {{Thus, }}&  \\ln \\frac{{p}}{{p_0}}=\\frac{{M \\omega^2}}{{2 R T}} r^2 &\\text {{ or, }} p=p_0 e^{{M \\omega^2 r^2 / 2 R T}}
        \\end{{aligned}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_21(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        Under what pressure will carbon dioxide have the density $\\rho=500 \\mathrm{{~g}} / \\mathrm{{l}}$ at the temperature $T=300 \\mathrm{{~K}}$ ? Carry out the calculations both for an ideal and for a Van der Waals gas.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        For an ideal gas law
        $\\displaystyle p=\\frac{{\\rho}}{{M}} R T$
        So, $\\displaystyle \\quad p=0.082 \\times 300 \\times \\frac{{500}}{{44}}$ atms $=279.5$ atmosphere
        For Vander Waal gas Eq.
        $\\begin{{aligned}}
        &\\left(p+\\frac{{v^2 a}}{{V^2}}\\right)(V-v b)=v R T, \\quad \\text {{ where }} V=v V_M \\\\
        & \\text {{ or, }} \\quad p  =\\frac{{v R T}}{{V-v b}}-\\frac{{a v^2}}{{V^2}}=\\frac{{m R T / M}}{{V-\\frac{{m b}}{{M}}}}-\\frac{{a m^2}}{{V^2 M^2}}\\\\
        &-\\frac{{\\rho R T}}{{M-\\rho b}}-\\frac{{a \\rho^2}}{{M^2}}=79.2 \\mathrm{{~atm}}
        \\end{{aligned}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_22(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        One mole of nitrogen is contained in a vessel of volume $V=$ $=1.00$ 1. Find:
        (a) the temperature of the nitrogen at which the pressure can be calculated from an ideal gas law with an error $\\eta=10 \\%$ (as compared with the pressure calculated from the Van der Waals equation of state);
        (b) the gas pressure at this temperature.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        (a) $\\displaystyle p=\\left[\\frac{{R T}}{{V_M-b}}-\\frac{{a}}{{V_M^2}}\\right](1+\\eta)=\\frac{{R T}}{{V_M}}$
        (The pressure is less for a Vander Waal gas than for an ideal gas)
        or, $\\displaystyle \\frac{{a(1+\\eta)}}{{V_M^2}}=R T\\left[\\frac{{-1}}{{V_M}}+\\frac{{1+\\eta}}{{V_M-b}}\\right]=R T \\frac{{\\eta V_M+b}}{{V_M\\left(V_M-b\\right)}}$
        or, $\\displaystyle \\quad T=\\frac{{a(1+\\eta)\\left(V_M-b\\right)}}{{R V_M\\left(\\eta V_M+b\\right)}}$, (here $V_M$ is the molar volume.)
        $\\displaystyle =\\frac{{1.35 \\times 1.1 \\times(1-0.039)}}{{0.082 \\times(0.139)}} \\approx 125 \\mathrm{{~K}}$
        (b) The corresponding pressure is
        $\\begin{{aligned}}
        p & =\\frac{{R T}}{{V_M-b}}-\\frac{{a}}{{V_M^2}}=\\frac{{a(1+\\eta)}}{{V_M\\left(\\eta V_M+b\\right)}}-\\frac{{a}}{{V_M^2}} \\\\
        & =\\frac{{a}}{{V_M^2}} \\frac{{\\left(V_M+\\eta V_M-\\eta V_M-b\\right)}}{{\\left(\\eta V_M+b\\right)}}=\\frac{{a}}{{V_M^2}} \\frac{{\\left(V_M-b\\right)}}{{\\left(V_M+b\\right)}} \\\\
        & =\\frac{{1.35}}{{1}} \\times \\frac{{0.961}}{{0.139}} \\approx 9.3 \\mathrm{{~atm}}
        \\end{{aligned}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_23(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        One mole of a certain gas is contained in a vessel of volume $V=0.250 \\mathrm{{l}}$. At a temperature $T_1=300 \\mathrm{{~K}}$ the gas pressure is $p_1==90 \\mathrm{{~atm}}$, and at a temperature $T_2=350 \\mathrm{{~K}}$ the pressure is $p_2=$ $=110$ atm. Find the Van der Waals parameters for this gas.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        $\\displaystyle p_1=R T_1 \\frac{{1}}{{V-b}}-\\frac{{a}}{{V^2}}, p_2=R T_2 \\frac{{1}}{{V-b}}-\\frac{{a}}{{V^2}}$
        So, $\\displaystyle p_2-p_1=\\frac{{R\\left(T_2-T_1\\right)}}{{V-b}}$
        or, $\\displaystyle V-b=\\frac{{R\\left(T_2-T_1\\right)}}{{p_2-p_1}} \\text {{ or, }} b=V-\\frac{{R\\left(T_2-T_1\\right)}}{{p_2-p_1}}$
        Also,
        $\\begin{{gathered}}
        p_1=T_1 \\frac{{p_2-p_1}}{{T_2-T_1}}-\\frac{{a}}{{V^2}}, \\\\
        \\frac{{a}}{{V^2}}=\\frac{{T_1\\left(p_2-p_1\\right)}}{{T_2-T_1}}-p_1=\\frac{{T_1 p_2-p_1 T_2}}{{T_2-T_1}}
        \\end{{gathered}}$
        or, $\\displaystyle a=V^2 \\frac{{T_1 p_2-p_1 T_2}}{{T_2-T_1}}$
        Using $T_1=300 \\mathrm{{~K}}, p_1=90 \\mathrm{{atms}}, T_2=350 \\mathrm{{~K}}, p_2=110 \\mathrm{{~atm}}, V=0.250$ litre $a=1.87 \\mathrm{{~atm}}$. litre $^2 / \\mathrm{{mole}}^2, b=0.045$ litre $/ \\mathrm{{mole}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_24(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        Find the isothermal compressibility $x$ of a Van der Waals gas as a function of volume $V$ at temperature $T$.
        Note. By definition, $x=-\\frac{{1}}{{V}} \\frac{{\\partial V}}{{\\partial p}}$.

        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        $\\begin{{aligned}}
        & p=\\frac{{R T}}{{V-b}}-\\frac{{a}}{{V^2}}-V\\left(\\frac{{\\partial p}}{{\\partial V}}\\right)_T=\\frac{{R T V}}{{(V-b)^2}}-\\frac{{2 a}}{{V^2}} \\\\
        & \\text {{ or, }} \\qquad \\kappa=\\frac{{-1}}{{V}}\\left(\\frac{{\\partial V}}{{\\partial p}}\\right)_T \\\\
        & =\\left[\\frac{{R T V^3-2 a(V-b)^2}}{{V^2(V-b)^2}}\\right]^{{-1}}=\\frac{{V^2(V-b)}}{{\\left[R T V^3-2 a(V-b)^2\\right]}} \\\\
        \\end{{aligned}}$
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _problem_2_25(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        Making use of the result obtained in the foregoing problem, find at what temperature the isothermal compressibility $x$ of a Van der Waals gas is greater than that of an ideal gas. Examine the case when the molar volume is much greater than the parameter $b$.
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        For an ideal gas $\\displaystyle \\kappa_0=\\frac{{V}}{{R T}}$
        $\\begin{{aligned}}
        & \\text {{Now }}& \\kappa&=\\frac{{(V-b)^2}}{{R T V}}\\left\\{{1-\\frac{{2 a(V-b)^2}}{{R T V^3}}\\right\\}}^{{-1}}=\\kappa_0\\left(1-\\frac{{b}}{{V}}\\right)^2\\left\\{{1-\\frac{{2 a}}{{R T V}}\\left(1-\\frac{{b}}{{V}}\\right)^2\\right\\}}^{{-1}} \\\\
        &&& =\\kappa_0\\left\\{{1-\\frac{{2 b}}{{V}}+\\frac{{2 a}}{{R T V}}\\right\\}} \\text {{, to leading order in }} a, b \\\\
        & \\text {{Now }} \\quad& &\\kappa > \\kappa_0 \\text {{ if }} \\frac{{2 a}}{{R T V}}>\\frac{{2 b}}{{V}} \\text {{ or }} T<\\frac{{a}}{{b R}}
        \\end{{aligned}}$
        If $a, b$ do not vary much with temperature, then the effect at high temperature is clearly determined by $b$ and its effect is repulsive so compressibility is less.
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate

    def _sample(self, *args, **kwargs):
        problemTemplate = KProblemTemplate()
        problemTemplate.problem_type = kwargs.get('problem_type')

        problem_s = f"""
        """
        problemTemplate.add_problem(problem_s.strip(), 'text/html')
        
        soln_s = f"""
        """
        problemTemplate.add_solution(soln_s.strip(), 'text/html')
        
        answer_s = f"""
        """
        problemTemplate.add_answer(answer_s.strip(), 'text/html')
        
        return problemTemplate
    
    def _init_file_path(self, file_name):
        import pathlib
        from xv.util import locatePath
        rootFolder = pathlib.Path(__file__).parent.absolute()
        file_path = locatePath(file_name, 
                               parent_depth = 6,
                               rootFolder = rootFolder,
                               part_match = False,
                               search_type = 'file',
                               verbose = self.verbose,
                               )
        return os.path.join(rootFolder, file_path)
    
