Construct a function $f\in C^{\infty}_{0}(\mathbb{R}^2)$ The question request that :
Let $A=[-1,1]\times[-1,1]$, B be a open ball centered at the origin with radius 2. Construct a function $f\in C^{\infty}_{0}(\mathbb{R}^2)$ such that $f(x)=1$ for $x\in A$, $f(x)=0$ for $x\in B^{c}$, and $0<f<1$ on $B\setminus A$.
I attempted to mimic what I learned in constructing a bump function by considering $f(x)=e^{-x^2}$. But then I ran into a trouble that the required function is not radial symmetry. Can anyone give some hints for solving this question? By the way, is there a general method for constructing a smooth function of compact support for arbitrary spaces? 
 A: Let $A_\epsilon = [-1-\epsilon, 1+\epsilon] \times [-1-\epsilon, 1+\epsilon]$ and let $\psi_\epsilon \in C_c^\infty(\mathbb R)$ such that $\psi_\epsilon(x) = 0$ for $|x|>\epsilon$ and $\int \psi_\epsilon = 1$.
Now just take $\epsilon$ small enough for $A_{2\epsilon} \subset B$ and let $f = \chi_{A_\epsilon} * (\psi_\epsilon \otimes \psi_\epsilon)$.
A: Take $A_1$, $A_2$ two disjoint closed sets. Assume that we found $\phi_1$,$\phi_2$ smooth on $\mathbb{R}^2$ , $\phi_i\ge 0$, $\phi_i^{-1}(0)=A_i$, $i=1,2$. Then we can take 
$$f=\frac{\phi_2}{\phi_1+\phi_2}$$
To construct $\phi_1$, $\phi_2$ for our sets, use 
$$\chi(t)=\begin{cases} \exp({-\frac{1}{t}} )&\text{ for } t>0 \\
                        0 &\text{ for } t\le0 \end{cases} $$
Then $$\phi_1(x_1,x_2)= 1 - (1-\chi(1-x_1^2))(1-\chi(1-x_2^2))=\\
= \chi(1-x_1^2)+\chi(1-x_2^2)-\chi(1-x_1^2)\chi(1-x_2^2)\\
\phi_2(x)= \chi(4-\|x\|^2)$$
So 
$$f(x_1,x_2)= \frac{\chi(4-\|x\|^2)}{\chi(1-x_1^2)+\chi(1-x_2^2)-\chi(1-x_1^2)\chi(1-x_2^2)+\chi(4-\|x\|^2)}$$
A: Let $g\in C^\infty(\mathbb R)$ satisfy $g=1$ on $[-1,1]$ and $0<g<1$ everywhere else. Note that $g(x)g(y)=1$ on $ [-1,1]^2$ and $0<g(x)g(y)<1$ everwhere else.
Writing $z=(x,y),$ choose $h\in C^\infty(\mathbb R^2)$ that satisfies $h(z)=1$ for $0\le |z| \le \sqrt 2,$ $h(z)=0$ for $|z| \ge 2,$ and $0<h(z)<1$ in between. Note that $h=1$ on on $ [-1,1]^2.$
The function $f(x,y)= g(x)g(y)h(z)$ then does the job.
