Because of their superior mechanical, structural, and electronic properties, carbon nanomaterials (CNs) (e.g. graphene sheets and carbon nanotubes) are supposed to be base materials for nanoelectromechanical systems (NEMS). In the present work, we propose a structural optimization method of carbon nanomaterials by introducing topological defects, which consists of the molecular mechanics method, the free-form optimization method, the Phase-Field-Crystal (PFC) method, Voronoi tessellation, and molecular dynamics (MD) simulation. The C-C bonds of CNs are simulated as equivalent continuum beams by a combination of molecular and continuum mechanics, so the atomic structures of CNs can be treated as frame structures. We adopt the free-form optimization method for frames to determine the optimal shapes of CNs in stiffness maximization problem. For obtaining the stable atomic structures of the optimal shapes of CNs, topological defects are introduced in the optimal shapes of CNs using a combination of PFC method, Voronoi tessellation, and MD simulation. The numerical results show that the compliance of CNs can be significantly reduced according to the structural optimization method, which is helpful for designing CNs components in NEMS.