Is there a function for drupal that can identity if a certain page and its children are being viewed?
You could use Menu Trail By Path module. 


  Menu Trail By Path sets the active-trail on menu items according to
  the current url.


For example if you are at yoursite.com/blog/category1/article1
Menu Items with these paths will get the active-trail class on them and expand accordingly.