## Wednesday, July 4, 2018

### Thoughts and observations from replacing a furnace with a split system AC and furnace in a manufactured home

Disclaimer!
I take no responsibility for anything that you do and do not consider anything in this post as advice. I am not a licensed HVAC technician. Before doing any HVAC projects refer to your local coding and permitting laws and consult a licensed professional. You may or may not be permitted to do any of this work yourself if you are not licensed. The goal of this post is to give you an idea of what it takes to do this sort of job and some things to keep in mind to make sure your contractor is doing a good job and perhaps save you some money, but this is NOT a DIY how-to guide.

Not too long ago the furnace in my manufactured home had a gas build up that resulted in a small explosion and a bending of the heat exchanger. Fortunately it did not cause a leak and we were able to shut off the gas for the season, it was 22 years old and it was time to replace it. The home also did not have air conditioning so it was a good time to put in a split system central air conditioning unit along with the new furnace. This post will run through the general process of removing the old furnace and the install of a new AC and furnace. The details of some steps are left vague as they were done by a contractor although I will mention all the major steps involved in the process. Pictures to come!

#### Tear-out the old furnace

Be sure that the electric power to your unit and gas flow are off. This typically involves switching your breaker and turning off your gas valve to your furnace and the home's main gas valve. A contractor will verify that these are off with a voltage detector and gas leak detector.

Removing the old furnace requires some elbow grease and patience. A crow bar and a drill are important tools here. In our case the furnace was located in a "closet" and was fastened securely to the flue and sealed to the floor with silicone. As such there was minimal open space on the sides of the unit- just a few inches. Ultimately the unit had to be removed slowly by disassembling it piece by piece until the empty frame could be lifted and hauled out. If your unit is not enclosed in a small space then you will have an easier time at this stage. You will likely need a truck or trailer to haul the waste material to the dump if your contractor does not do this for you. I ended up salvaging many sheet metal screws from the unit which have later been put to good use. You may also be able to get some cash from scrap metal or reuse some sheet metal. Once torn out you can take the time to clean the supply plenum or duct to which your system outflows and then seal it from dust while the project is underway.

#### Make concrete slab for condenser

We had a small concrete slab made for the AC condenser just outside of the house in a location that is ideally as close as possible to the AC coil and blower inside. In picking this location your contractor will likely need to make sure that drain lines and the refrigerant line set for the AC will have no major obstacles while keeping the distance short to reduce the energy loss of your system. It is important to use the appropriate concrete for small slabs, and it is a good idea to make it a bit larger than your condenser to protect it from soil and vegetation. Our slab was reinforced with steel mesh and lain over compacted angular gravel. As with any concrete work be sure to finish the surface and let it dry properly (not too fast) for maximum strength. Be sure that the slab forms and finished surface are level as well otherwise the condenser may not function properly.

#### Prepare connections and layout

The connection from your AC or furnace to your duct will vary, in our case the supply air flows into ducts that run beneath the home. From what I understand, this is common in manufactured homes. Other homes are designed based on climatic settings and architectural considerations and may have return air coming in from the bottom of the furnace/AC system and supply air leaving from the top of the system into ducts in the ceiling. In either case the connection will typically be a sheet metal plenum or some sheet metal ductwork. The condensate drains from the new furnace and AC will also need space if there was no prior drain, a PVC pipe with a trap installed will generally be threaded or glued to new high efficiency gas furnaces and all AC units to drain condensate water. In our case the drain runs beneath the floor joists and out the wall to drain above the ground. A refrigerant line set consists of two copper pipes, for return and supply flow, will need to run from the condenser outside on the slab that was created to the AC coil that is located downstream of your blower, In our case beneath the gas furnace. It is important that the copper pipes in the line set are not bent or have any serious kinks, therefore laying out the location of the line set path so that it does not contain sharp bends is important. Another thing to consider here is that line sets typically come in predetermined lengths if not specially ordered therefore you can save some money (and energy) by figuring out the shortest length that corresponds with one of these lengths (e.g. 25 ft) by determining the location for the condenser and connection path. Basically it is important to lay this out before you move on to the installation.

#### Install return air grill

You may already have a return air plenum for your previous system. In our case we did not because the previous unit was a mobile home furnace that received combustion air from within the house from the front of the unit. We replaced this unit with a standard gas furnace that required a supply air connection of filtered air. What we did was install a return air grill in the non-load bearing wall behind the unit. This will later be attached to the return air intake on the furnace unit with a flexible insulated HVAC duct. The rectangular shaped grill needed to be attached to a circular duct therefore we manufactured a small box from sheet metal to couple these together. Any skilled contractor can manufacture custom ductwork to fit these situations on the spot. Here it is important to refer to your units air flow to determine that size of return air filter and corresponding ductwork to attach to the furnace. If your return air filter and connecting ducts are too small this may greatly reduce the efficiency of the HVAC system!

#### Install coil, furnace/blower, and flue

Connecting the new units will depend on your system, in this case our system is downward flowing so the AC coil goes on the bottom which connects to the supply ducts with the gas furnace and blower above. The top of the unit connects to the return air that was installed in the adjacent wall and has two PVC connections to the roof flue for combustion air. The installation of the bottom unit (coil in this case) will attach to the supply air duct. HVAC silicone caulk may be used to deal joined between units. After the AC and furnace are connected to the supply air and each other they will need to be connected to the ductwork that makes up your return air. In our case this was the 20 x 10" grill and insulated flexible duct. Be sure that any new ductwork is air tight on the return side to minimize dust entering the unit, small gaps in the flexible duct connections may be sealed with HVAC tape. Next the connections for the furnace combustion air need to be made, typically through a roof stack. If you need to run a new flue stack to the roof be sure that the contractor has experience and is able to correctly put flashing around the new flue without damaging the roof material. Otherwise you may be able to reuse the old flue stack by connecting into it from the bottom if you did not damage it when removing the original unit. As with the return air, it is critical to use the right size pipes (PVC in our case) for combustion air that the furnace needs from outside.

#### Run the refrigerant line set and drains

Now that all the units are in place it is time to connect the refrigerant line set to the coil and run condensate drains from the furnace and AC coil. The refrigerant line set runs from the AC coil to the location of the condenser slab, the location that it exits the home should be in line with the location of the connection on the condenser that you will put on the concrete slab later. Similarly, the layout for the line set should result in the connection coming into the home so that it does not need to be bent sharply and ends near the AC coil. Next the condensate drains from the furnace and coil need to run somewhere to drain, in our case they were connected using PVC pipe which ran beneath the sub floor where we placed a trap in the line and then ran out to the bottom of the siding in the skirting to drain a few inches from the foundation. The drain was attached to the bottom of the floor joists, it should not be left unsupported. Similarly for the line set, the high pressure in the system can cause the line set to move with the condenser pump activates and shuts off, therefore keep the line set away from any sharp surfaces that it may abrade into. Minimize damage in the homes siding by drilling the exit homes in strategic locations and use a small diameter bit to locate the spot before drilling the final large hole for the lines. The line set is insulated to keep energy loss to a minimum, the connection outside to the condenser should be as close as allowed to the home to also minimize energy loss. Any exposed part of the refrigerant line that flows cold fluid from the condenser should be wrapped in thick (e.g. 10 mil) HVAC line set tape. Lastly, seal with caulk or foam where the lines exit the home's exterior.

#### Electrical work for condenser, furnace, and brazing

A licensed electrician may need to add a dedicated circuit to your AC condenser if it is a new system as was my case, you may want to make sure they do it well by looking into the code yourself. For example they may be required to have a separate shutoff switch along the circuit. Also, they should mount the wiring with the correct outdoor conduit. Similarly for the furnace and thermostat- electrical connections need to be made. Next the line set needs to be connected to the AC coil and condenser. Typically this is done using brazing with a high temperature torch and flux. A good HVAC contractor, although still uncommon, will put a low pressure flow of nitrogen gas in the line set while brazing the connections in order to purge oxygen from inside the pipe. This practice greatly reduces oxidation that occurs inside the pipe that would otherwise leave behind carbon particles in the line that can potentially damage the AC system or reduce its efficiency or durability. Next the system will be pressurized with refrigerant fluid to a certain level or pressure depending on the system and check for leaks by any drops in pressure using a gauge attached to the condenser. At this point the blower and AC system can usually be turned on and tested as the only thing left to do is connect the gas to the furnace.

#### Gas connection for furnace

The furnace needs to be reconnected to the gas line using the same diameter iron gas line that the home uses or larger. We had a safety vale installed that replaced our old simple gas valve before it connects to the gas furnace. Be sure that the contractor installs a trap in the gas line to reduce debris and dust that may otherwise enter the furnace. The threaded iron pipe should be well tighten and utilize gas joint pipe compound, and finally tested for leaks. Congratulations!

#### Other tips

You might be able to save money by working with your contractor and permitting office and doing some of these steps yourself- maybe not. Either way you can also save by asking contractors if you can help search for the best units to buy from a HVAC wholesaler.

## Monday, October 10, 2016

### Python, regex, and SymPy to automate custom text conversions to LaTeX

blog_post_sympy_latex
In [1]:
"""
Author: John Volk
Date: 10/10/2016
"""
from __future__ import print_function
from sympy.parsing.sympy_parser import (parse_expr, standard_transformations, implicit_multiplication,\
implicit_application)
import numpy as np
import sympy
import re


# Python, regex, and SymPy to automate custom text conversions to LaTeX¶

This post includes examples on how to:

• Convert text equation in bad format for Python and SymPy

• Convert normal Python mathematical experssion into a suitable form for SymPy's LaTeX printer

• Use sympy to produce LaTeX output

• Create functions and data structures to make the process reusable and efficient to fit your needs

# Lets start with the following string that we assign to the variable text that represents a mathematical model but in poor printing form:¶

In [2]:
text = """
Ln(Y) = a0 + a1 LnQ + a2 LnQ^2 + a3 Sin(2 pi dtime) + a4 Cos(2 pi dtime)
+ a5 dtime + a6 dtime^2"""

text

Out[2]:
'\nLn(Y) = a0 + a1 LnQ + a2 LnQ^2 + a3 Sin(2 pi dtime) + a4 Cos(2 pi dtime)\n+ a5 dtime + a6 dtime^2'

# However, we want this expression to look like:¶

$\log{\left (Y \right )} = a_{0} + a_{1} \log{\left (Q \right )} + a_{2} \log{\left (Q^{2} \right )} + a_{3} \sin{\left (2 \pi dtime \right )} + a_{4} \cos{\left (2 \pi dtime \right )} + a_{5} dtime + a_{6} dtime^{2}$

# Observe the following differences between text and valid LateX:¶

• Some variables and functions are concatenated, i.e.: LnQ, correct latex would be \log{Q}

• Functions are not in proper latex form (e.g. Sin = \sin, Ln = \log, ...)

• Missing subscripts: a0 = a_0

• Newline characters need to be removed

• Some symbols need to be replaced: dtime = t

# Python's symbolic math pacakge SymPy can automate some of the transformations that we need, and SymPy has built in LaTeX printing capabilities.¶

If you are not familiar with SymPy you should take some time to familiarize yourself with it; it takes some time to get used to its syntax. Check out the well done documentation for Sympy here.

# First we need to convert the string (text) into valid SymPy input¶

• Valid sympy input includes valid python math expressions with added recognition of math operations. For example the following expression can be parsed by SymPy without error:

In [3]:
exp = "(x + 4) * (x + sin(x**3) + log(x + 5*x) + 3*x - sqrt(y))"
sympy.expand(exp)

Out[3]:
4*x**2 - x*sqrt(y) + x*log(x) + x*sin(x**3) + x*log(6) + 16*x - 4*sqrt(y) + 4*log(x) + 4*sin(x**3) + 4*log(6)

# To convert a valid SymPy expression like t above into LaTeX is easy:¶

In [4]:
print(sympy.latex(sympy.expand(exp)))

4 x^{2} - x \sqrt{y} + x \log{\left (x \right )} + x \sin{\left (x^{3} \right )} + x \log{\left (6 \right )} + 16 x - 4 \sqrt{y} + 4 \log{\left (x \right )} + 4 \sin{\left (x^{3} \right )} + 4 \log{\left (6 \right )}


# Which, when rendered as LaTeX is¶

$4 x^{2} - x \sqrt{y} + x \log{\left (x \right )} + x \sin{\left (x^{3} \right )} + x \log{\left (6 \right )} + 16 x - 4 \sqrt{y} + 4 \log{\left (x \right )} + 4 \sin{\left (x^{3} \right )} + 4 \log{\left (6 \right )}$

# Now back to our original text that we want to convert, we need to make some simple adjustments to make the string a valid SymPy expression¶

You have several options here, in this case I choose to use regular expressions (regex) to do basic string pattern substitutions. You will likely need to modify these operations or create alrenative regex to prepare your text. If you do not know regex you can probably get by without using basic Python string methods.

In [5]:
## Note, I removed the LHS and the equal sign from the equation- SymPy requires special syntac for equations
## further explanation below
text = """
a0 + a1 LnQ + a2 LnQ^2 + a3 Sin(2 pi dtime) + a4 Cos(2 pi dtime)
+ a5 dtime + a6 dtime^2"""

## Make a dictionary to map our strings to standard python math or symbols as needed
symbol_map = {
'^': '**',
'Ln': 'log ',
'Sin': 'sin ',
'Cos': 'cos ',
'dtime': 't'
}
## use the dictionary to compile a regex on the keys
## escape regex characters because ^ is one of the keys, (^ is a regex special character)
to_symbols = re.compile('|'.join(re.escape(key) for key in symbol_map.keys()))
# run through the text looking for keys (regex) and replacing them with the values from the dict
text = to_symbols.sub(lambda x: symbol_map[x.group()], text)

text

Out[5]:
'\na0 + a1 log Q + a2 log Q**2 + a3 sin (2 pi t) + a4 cos (2 pi t)\n+ a5 t + a6 t**2'
In [6]:
## remove new line characters from the text
text = re.sub('\n', ' ', text)
text

Out[6]:
' a0 + a1 log Q + a2 log Q**2 + a3 sin (2 pi t) + a4 cos (2 pi t) + a5 t + a6 t**2'
In [7]:
## regex to replace coefficients a0, a1, ... with their equivalents with subscripts e.g. a0 = a_0
text = re.sub(r"\s+a(\d)", r"a_\1", text)
text

Out[7]:
'a_0 +a_1 log Q +a_2 log Q**2 +a_3 sin (2 pi t) +a_4 cos (2 pi t) +a_5 t +a_6 t**2'

# The remaining issues are sufficiently difficult string manipulations, SymPy's Parser is perfect for the remaining conversions:¶

Instead of trying to figure out how to place asterisks everywhere that multiplication is implied and parenthesis where functions are implied, e.g. log Q**2 should be log(Q**2) we can use SymPy's Parser that is quite powerful.

We use implicit multiplication (self-explantory) and implicit application for function applications that are mising parenthesis, both of these are transformations provided by the SymPy Parser. Remember the parser will still follow mathematical order of operations (PEMDAS) when doing implicit application. The parser can handle additional cases as well such as function exponentiation. Check the handy examples at the documentation link above.

In [8]:
## get the transformations we need (imported above) and place into a tuple that is required for the parser
transformations = standard_transformations + (implicit_multiplication, implicit_application, )
## parse the text by applying implicit multiplication and implicit (math function) appplication
expr = parse_expr(text, transformations=transformations)

expr

Out[8]:
a_0 + a_1*log(Q) + a_2*log(Q**2) + a_3*sin(2*pi*t) + a_4*cos(2*pi*t) + a_5*t + a_6*t**2

# We're done, just print using SymPy's latex printer!¶

In [9]:
print(sympy.latex(expr))

a_{0} + a_{1} \log{\left (Q \right )} + a_{2} \log{\left (Q^{2} \right )} + a_{3} \sin{\left (2 \pi t \right )} + a_{4} \cos{\left (2 \pi t \right )} + a_{5} t + a_{6} t^{2}


# SymPly amazing!!¶

$a_{0} + a_{1} \log{\left (Q \right )} + a_{2} \log{\left (Q^{2} \right )} + a_{3} \sin{\left (2 \pi t \right )} + a_{4} \cos{\left (2 \pi t \right )} + a_{5} t + a_{6} t^{2}$

# Now let's put this all together into a function:¶

In [10]:
## global variables for the function
symbol_map = {
'^': '**',
'Ln': 'log ',
'Sin': 'sin ',
'Cos': 'cos ',
'dtime': 't'
}

transformations = standard_transformations + (implicit_multiplication, implicit_application, )
## the function
"""My custom string-to-LaTeX-ready SymPy expression translation function

Arguments:
bad_text (str): text that is in some bad format that requires string manipulation
including custom string modifications to math functions, symbols, and operators
defined by the global symbol_map dictionary (for substitutions), and the regexs
compiled herein. More advanced manipulations providied by SymPy are defined by
the global variable transformations are inputs to the SymPy parser
Returns:
expr (sympy expression): A SymPy expresion created by the SymPy expression parser
after first doing custom string modifications to math functions, symbols, and operators
"""

to_symbols = re.compile('|'.join(re.escape(key) for key in symbol_map.keys()))
expr = parse_expr(text, transformations=transformations)
return expr

In [11]:
## very handy, now we just have to convert to TeX and print
print(sympy.latex(translate(text)))

a_{0} + a_{1} \log{\left (Q \right )} + a_{2} \log{\left (Q^{2} \right )} + a_{3} \sin{\left (2 \pi t \right )} + a_{4} \cos{\left (2 \pi t \right )} + a_{5} t + a_{6} t^{2}


# What about the original text ? It was an equation with a left-hand-side:¶

• Parse both the LHS and RHS separately and combine with SymPy's Equation method

In [12]:
text = """
Ln(Y) = a0 + a1 LnQ + a2 LnQ^2 + a3 Sin(2 pi dtime) + a4 Cos(2 pi dtime)
+ a5 dtime + a6 dtime^2"""

# split on the equal sign
t1 = text.split('=')[0]
t2 = text.split('=')[1]

In [13]:
## Use sympy.Eq(LHS,RHS)
LHS = translate(t1)
RHS = translate(t2)
print(sympy.latex(sympy.Eq(LHS, RHS)))

\log{\left (Y \right )} = a_{0} + a_{1} \log{\left (Q \right )} + a_{2} \log{\left (Q^{2} \right )} + a_{3} \sin{\left (2 \pi t \right )} + a_{4} \cos{\left (2 \pi t \right )} + a_{5} t + a_{6} t^{2}


$\log{\left (Load \right )} = a_{0} + a_{1} \log{\left (Q \right )} + a_{2} \log{\left (Q^{2} \right )} + a_{3} \sin{\left (2 \pi t \right )} + a_{4} \cos{\left (2 \pi t \right )} + a_{5} t + a_{6} t^{2}$

# One quick example: let's plug in random values for the following variables:¶

$$\large{a_0, a_1, a_2, a_3, a_4, a_5, ~\text{and}~ a_6 }$$
In [14]:
## extract SymPy symbols from both sides of eqn
LHS_symbols = [str(x) for x in LHS.atoms(sympy.symbol.Symbol)]
RHS_symbols = [str(x) for x in RHS.atoms(sympy.symbol.Symbol)]

LHS_symbols

Out[14]:
['Y']
In [15]:
RHS_symbols

Out[15]:
['a_0', 'Q', 'a_5', 'a_6', 'a_2', 'a_3', 'a_1', 'a_4', 't']
In [16]:
## remove Q and t from the RHS list because we do not want to plug values in for them
RHS_symbols.pop(RHS_symbols.index('Q'))
RHS_symbols.pop(RHS_symbols.index('t'));

In [17]:
## create a dictionary assigning each symbol to random variables
plug_in_dict = {k: np.random.randint(10) for k in RHS_symbols }
print(plug_in_dict)

{'a_6': 4, 'a_5': 7, 'a_4': 5, 'a_3': 0, 'a_2': 1, 'a_1': 0, 'a_0': 6}

In [18]:
## now plug in our values and let sympy simplyfy! Note, the variables we changed only appear on the RHS
RHS.subs(plug_in_dict)

Out[18]:
4*t**2 + 7*t + log(Q**2) + 5*cos(2*pi*t) + 6

# Where:¶

a_6 = 4
a_5 = 7
a_4 = 5
a_3 = 0
a_2 = 1
a_1 = 0
a_0 = 6

In [19]:
print(sympy.latex(sympy.Eq(LHS, RHS.subs(plug_in_dict))))

\log{\left (Y \right )} = 4 t^{2} + 7 t + \log{\left (Q^{2} \right )} + 5 \cos{\left (2 \pi t \right )} + 6


$\log{\left (Y \right )} = 4 t^{2} + 7 t + \log{\left (Q^{2} \right )} + 5 \cos{\left (2 \pi t \right )} + 6$

# Remarks¶

I hope this was useful to anyone trying to use Python to batch process strings into mathematical expressions and LaTeX. In my case I needed to process many of these types of strings that were output from a computer code that fits regression models to input data. As you can see, if you work with mathematical expressions of any kind and already know basic Python, SymPy is undoubtedly useful. If you liked this or have experimented with your own implementations of Python, regex, and/or SymPy to do cool and useful things please share in the comments below.