#!/usr/bin/python
# -*- coding: utf-8 -*-

#-------------------------------------------------------------------------------

# This file is part of Code_Saturne, a general-purpose CFD tool.
#
# Copyright (C) 1998-2013 EDF S.A.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA.

#-------------------------------------------------------------------------------

#===============================================================================
# Import required Python modules
#===============================================================================

import sys

# Trick so that one doesn't have to set the PYTHONPATH variable
sys.path.insert(0, '/usr/local/lib/python2.7/dist-packages/code_saturne')
sys.path.insert(1, '/opt/local/syrthes4.1.1-ubuntu/arch/Linux_x86_64/share/syrthes')

from cs_package import package
from cs_exec_environment import *
from cs_case import *
from cs_case_coupling import *

#===============================================================================
# User variable settings to specify a coupling computation environnement
#
# Variables set to 'None' will be determined automatically
#===============================================================================

casedir = '/home/libre/Documents/FM176/etape2'

# A coupling case is defined by a dictionnary, containing the following:

# Solver type ('Code_Saturne', 'SYRTHES', 'NEPTUNE_CFD' or 'Code_Aster')
# Domain directory name
# Run parameter setting file
# Number of processors (or None for automatic setting)
# Optional command line parameters. If not useful = None

# Define coupled domains
domains = [

    {'solver': 'Code_Saturne',
     'domain': 'fluid',
     'script': 'runcase',
     'n_procs_weight': None,
     'n_procs_min': 12,
     'n_procs_max': 12}

    ,
    {'solver': 'SYRTHES',
     'domain': 'solid',
     'script': 'solid.syd',
     'n_procs_weight': None,
     'n_procs_min': 3,
     'n_procs_max': 3,
     'opt' : '-v ens'}               # Additional SYRTHES options
                               # (ex.: postprocessing with '-v ens' or '-v med')

    ]

#-------------------------------------------------------------------------------

if __name__ == '__main__':

    # Run coupling case

    case = coupling(package(),
                    domains,
                    casedir)

    # Select run id
    # (usually date+time; defined automatically when preparing data, but we need
    # to set this so as to match an existing run when only running the solver or
    # saving results with previously prepared data)

    run_id = None

    # Execute script

    case.run(n_procs=None,
             run_id=run_id,
             prepare_data=True,
             run_solver=True,
             save_results=True)

