Package Owntools

@author: Alexandre Sac–Morane alexandre.sac-morane@uclouvain.be

This file contains the different functions used in the simulation.

Expand source code
# -*- coding: utf-8 -*-
"""
@author: Alexandre Sac--Morane
alexandre.sac-morane@uclouvain.be

This file contains the different functions used in the simulation.
"""

#-------------------------------------------------------------------------------
#Librairy
#-------------------------------------------------------------------------------

from pathlib import Path
import os
import math

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

def index_to_str(j):
  '''
  An integer is converted to a float with 3 components

    Input :
        a number (a float)
    Output :
        a string with 3 components (a string)
  '''
  if j < 10:
      j_str = '00'+str(j)
  elif 10 <= j and j < 100:
      j_str = '0'+str(j)
  else :
      j_str = str(j)
  return j_str

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

def Sort_Files(dict_algorithm):
     '''
     Sort files generated by MOOSE to different directories

        Input :
            an algorithm dictionnary (a dict)
        Output :
            Nothing but files are sorted
     '''

     os.rename(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_out.e','Output/'+dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_out.e')
     os.rename(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'.i','Input/'+dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'.i')
     j = 0
     j_str = index_to_str(j)
     filepath = Path(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'.pvtu')
     while filepath.exists():
         for i_proc in range(dict_algorithm['np_proc']):
            os.rename(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'_'+str(i_proc)+'.vtu','Output/Ite_'+str(dict_algorithm['i_PFDEM'])+'/'+dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'_'+str(i_proc)+'.vtu')
         os.rename(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'.pvtu','Output/Ite_'+str(dict_algorithm['i_PFDEM'])+'/'+dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'.pvtu')
         j = j + 1
         j_str = index_to_str(j)
         filepath = Path(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'.pvtu')

     return index_to_str(j-1)

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

def Extract_solute_at_p(dict_sample,ij_p):
    '''
    Extract the value of the solute concentration at a given point.

     Input :
         a sample dictionnary (a dict)
         a coordinate of the point (a tuple of int)
     Output :
         the value of the solute concentration (a float)
    '''
    return dict_sample['solute_M'][-1-ij_p[0]][ij_p[1]]

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

def Cosine_Profile(R,r,w):
    '''
    Compute the phase field variable at some point.

    A cosine profile is assumed (see https://mooseframework.inl.gov/source/ics/SmoothCircleIC.html).

    Input :
        the radius R of the grain in the direction (a float)
        the distance r between the current point and the center (a float)
        the width w of the interface (a float)
    Output :
        the value of the phase field variable (a float)
    '''
    #inside the grain
    if r<R-w/2:
        return 1
    #outside the grain
    elif r>R+w/2:
        return 0
    #inside the interface
    else :
        return 0.5*(1 + math.cos(math.pi*(r-R+w/2)/w))

Sub-modules

Owntools.Compute

@author: Alexandre Sac–Morane alexandre.sac-morane@uclouvain.be …

Owntools.PFtoDEM_Multi

@author: Alexandre Sac–Morane alexandre.sac-morane@uclouvain.be …

Owntools.Plot

@author: Alexandre Sac–Morane alexandre.sac-morane@uclouvain.be …

Owntools.Save

@author: Alexandre Sac–Morane alexandre.sac-morane@uclouvain.be …

Owntools.Write

@author: Alexandre Sac–Morane alexandre.sac-morane@uclouvain.be …

Functions

def Cosine_Profile(R, r, w)

Compute the phase field variable at some point.

A cosine profile is assumed (see https://mooseframework.inl.gov/source/ics/SmoothCircleIC.html).

Input : the radius R of the grain in the direction (a float) the distance r between the current point and the center (a float) the width w of the interface (a float) Output : the value of the phase field variable (a float)

Expand source code
def Cosine_Profile(R,r,w):
    '''
    Compute the phase field variable at some point.

    A cosine profile is assumed (see https://mooseframework.inl.gov/source/ics/SmoothCircleIC.html).

    Input :
        the radius R of the grain in the direction (a float)
        the distance r between the current point and the center (a float)
        the width w of the interface (a float)
    Output :
        the value of the phase field variable (a float)
    '''
    #inside the grain
    if r<R-w/2:
        return 1
    #outside the grain
    elif r>R+w/2:
        return 0
    #inside the interface
    else :
        return 0.5*(1 + math.cos(math.pi*(r-R+w/2)/w))
def Extract_solute_at_p(dict_sample, ij_p)

Extract the value of the solute concentration at a given point.

Input : a sample dictionnary (a dict) a coordinate of the point (a tuple of int) Output : the value of the solute concentration (a float)

Expand source code
def Extract_solute_at_p(dict_sample,ij_p):
    '''
    Extract the value of the solute concentration at a given point.

     Input :
         a sample dictionnary (a dict)
         a coordinate of the point (a tuple of int)
     Output :
         the value of the solute concentration (a float)
    '''
    return dict_sample['solute_M'][-1-ij_p[0]][ij_p[1]]
def Sort_Files(dict_algorithm)

Sort files generated by MOOSE to different directories

Input : an algorithm dictionnary (a dict) Output : Nothing but files are sorted

Expand source code
def Sort_Files(dict_algorithm):
     '''
     Sort files generated by MOOSE to different directories

        Input :
            an algorithm dictionnary (a dict)
        Output :
            Nothing but files are sorted
     '''

     os.rename(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_out.e','Output/'+dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_out.e')
     os.rename(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'.i','Input/'+dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'.i')
     j = 0
     j_str = index_to_str(j)
     filepath = Path(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'.pvtu')
     while filepath.exists():
         for i_proc in range(dict_algorithm['np_proc']):
            os.rename(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'_'+str(i_proc)+'.vtu','Output/Ite_'+str(dict_algorithm['i_PFDEM'])+'/'+dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'_'+str(i_proc)+'.vtu')
         os.rename(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'.pvtu','Output/Ite_'+str(dict_algorithm['i_PFDEM'])+'/'+dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'.pvtu')
         j = j + 1
         j_str = index_to_str(j)
         filepath = Path(dict_algorithm['namefile']+'_'+str(dict_algorithm['i_PFDEM'])+'_other_'+j_str+'.pvtu')

     return index_to_str(j-1)
def index_to_str(j)

An integer is converted to a float with 3 components

Input : a number (a float) Output : a string with 3 components (a string)

Expand source code
def index_to_str(j):
  '''
  An integer is converted to a float with 3 components

    Input :
        a number (a float)
    Output :
        a string with 3 components (a string)
  '''
  if j < 10:
      j_str = '00'+str(j)
  elif 10 <= j and j < 100:
      j_str = '0'+str(j)
  else :
      j_str = str(j)
  return j_str