Butter a 9-inch springform pan. Line the bottom and sides with parchment paper. For the tomato layer: In a 12-inch nonstick skillet, heat the olive oil over medium heat. Add the shallots and cook until softened, about 3 minutes. Add the garlic and cook until fragrant, about 30 seconds. Remove the pan from the heat and cool slightly. Stir in the tomatoes. Return the pan to the heat and add the red pepper flakes. Bring the mixture to a simmer and cook until most of the liquid has evaporated and the mixture has formed a chunky sauce, 15 to 20 minutes. Season with salt and pepper.
For the bechamel sauce: In a 1-quart saucepan, melt the butter over medium-low heat. Add the flour and whisk until smooth, 1 to 2 minutes. Gradually add the milk, whisking constantly to prevent lumps. Stir in the nutmeg and 1/4 teaspoon salt. Simmer over medium-low heat, whisking constantly, until the sauce is thick and smooth, about 8 minutes. Remove the pan from the heat.
For the pesto: In a food processor, combine the basil, Parmesan, pine nuts, garlic, 1/2 teaspoon salt and 1/4 teaspoon pepper. Pulse until finely chopped. With the machine running, gradually add the olive oil until the mixture forms a smooth paste. Stir the pesto into the bechamel sauce until smooth. Season with salt and pepper. Set aside to cool for 15 minutes.
For the polenta: In a large, heavy saucepan, bring 6 cups water and 1 tablespoon salt to a boil over medium-low heat. Gradually whisk in the cornmeal. Reduce the heat to low and cook, stirring constantly, until thickened and the cornmeal is tender, 10 to 15 minutes. Remove the pan from the heat and stir in the butter. To assemble the torta: Working quickly, spread half of the warm polenta in an even layer on the bottom of the prepared pan. Add the pesto mixture and spread on top of the polenta. Spoon the remaining polenta on top and smooth with a spatula. Spread the tomato mixture on top. Cool the torta at room temperature for 30 minutes. Cover with plastic wrap and refrigerate until the layers have set, about 4 hours. Remove the outer ring from the pan, then remove the parchment paper. Place the torta on a platter and cut into thin wedges. Serve with grilled bread. Cook's Note: To toast the pine nuts, arrange them in a single layer on a baking sheet. Bake in a 350 degrees F oven until lightly toasted, 6 to 8 minutes. Cool completely before using.
Recipe courtesy of Giada De Laurentiis