=head1 NAME

CFX5::Simulation::Configuration::Remeshing::Remesh::Validation - Validation module for remeshing

=head1 SYNOPSIS

Functions for validation step of the remesh process

$Id$

=cut

package CFX5::Simulation::Configuration::Remeshing::Remesh::Validation ;

use strict ;

use vars qw($CVSVersion);
$CVSVersion='$Id$ ';

use Exporter ; 
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
@ISA=qw(Exporter);
@EXPORT_OK=qw(Validate);
%EXPORT_TAGS = (
  'all' => [qw(Validate)],  
);

use CFX5::Output qw(:all error_text);
use CFX5::PkgLoader qw(cfx5_require);

#
################################################################################
# Validate - High level validation routine
################################################################################
#
sub Validate {
  my ($self) = @_ ; 

#
#===============================================================================
# Setup
#===============================================================================
#   
  my $rundir = $self->Get("RunDir") ; 
  if (!defined $rundir) {
    _error "Validate: Run directory not available" ;
    return 0; 
  }
  
  #
  # Enter the run directory so that all validation is relative to it
  $rundir->enter() ;
#
#===============================================================================
#  ICEM CFD Replay
#===============================================================================
#   
  if ($self->Get("Option") eq "ICEM CFD Replay") {
    my $fileName ;

    #
    # Ensure the required environment variable is setup
    my $ICEM_ACN = $self->Get("Parent")->icem_install_root() ;
    unless (defined $ICEM_ACN) {
      _error "Validation: ICEM CFD installation not found.  ".
             "Please install and/or set the ICEM_ACN environment variable appropriately." ;
      return 0; 
    }
    
    #
    # Enter the run directory so that all validation is relative to it
    my $rv = 1; 
    $rundir->enter() ;

    # Ensure geometry file exists
    $fileName = $self->Get("Geometry File") ;
    if (! -e $fileName) {
       _error "Validate: Required file not available: ".$fileName ;
      $rv = 0 ; 
    }

    # Ensure user's cleaned mesh file exists
    $fileName = $self->Get("Mesh Replay File") ;
    if (! -e $fileName) {
       _error "Validate: Required file not available: ".$fileName ;
      $rv = 0 ; 
    }
    
    $rundir->leave() ;
    
    return $rv unless $rv;  
  }
#
#===============================================================================
#  User Defined
#===============================================================================
#   
  elsif ($self->Get("Option") eq "User Defined") {
#
# Nothing to do here
#  
  }
#
#===============================================================================
#  Unhandled Option
#===============================================================================
#   
  else {
    _error "Validate: Invalid Remesh Option found" ;
    return 0 ; 
  }

#
#===============================================================================
# Closure
#===============================================================================
#   

  1 ;
}

1 ;
