Companies including the venture arms of BP Plc and Chevron Corp. invested $40 million in a startup that aims to use the fossil fuel industry’s drilling experience to expand a technology that harvests low-carbon energy from heat below the earth’s surface.