<commit_before># -*- coding: utf-8 -*-
#@author: <EMAIL>
#@author: <EMAIL>
#@author: <EMAIL>
import yaml
import os.path
from . import geometry
import sys
from . import output
from ..util import condition
from . import vis
from . import dic
import numpy as np

## Class handeling the input of the yaml file and storing the values
class PD_deck():

    ## Constructor
    # Reads the configuration in the yaml file and stores the values
    # @param inputFile The path to the yaml file with the configuration
    def __init__(self,inputFile):
            if not os.path.exists(inputFile):
                print ("Error: Could not find " + inputFile)
                sys.exit(1)
            else:
                with open(inputFile,'r') as f:
                    ## Container of the tags parsed from the yaml file
                    self.doc = yaml.load(f)
                    ## Safety factor for the computation of the radius
                    self.safety_factor = 1.001
                    ## Number of threads
                    self.num_threads = 1

                    if not "Discretization" in self.doc:
                        print ("Error: Specific a Discretization tag in your yaml")
                        sys.exit(1)
                    else:
                        if not "Dim" in self.doc["Discretization"]:
                            print ("Error: No Dim tag found")
                            sys.exit(1)
                        else:
                            ## Dimension of the problem
                            self.dim = int(self.doc["Discretization"]["Dim"])
                            if self.dim == 2:
                                if not "Type" in self.doc["Discretization"]:
                                    print ("Error: No Type tag found for 2D problem. Choose Plane_Stress or Plane_Strain")
                                    sys.exit(1)
                                else:
                                    ## Type of 2D problem
                                    self.type2d = self.doc["Discretization"]["Type"]
                        if not "Final_Time" in self.doc["Discretization"]:
                            print ("Error: No Final_Time tag found")
                            sys.exit(1)
                        else:
                            ## Final time of the problem
                            self.final_time = float(self.doc["Discretization"]["Final_Time"])
                        if not "Time_Steps" in self.doc["Discretization"]:
                            print ("Error: No Time_Steps tag found")
                            sys.exit(1)
                        else:
                            ## Amount of time steps
                            self.time_steps = int(self.doc["Discretization"]["Time_Steps"]) + 1
                            ## Time step size
                            self.delta_t = float(self.final_time  / (self.time_steps-1))
                        if not "Horizon_Factor_m_value" in self.doc["Discretization"]:
                            print ("Error: No Horizon_Factor tag found")
                            sys.exit(1)
                        else:
                            ## "m" value of the horizon factor
                            self.horizon_factor_m_value = float(self.doc["Discretization"]["Horizon_Factor_m_value"])
                        if not "Influence_Function" in self.doc["Discretization"]:
                            print ("Error: Influence_Function tag found")
                            sys.exit(1)
                        else:
                            ## Influence function
                            self.influence_function = self.doc["Discretization"]["Influence_Function"]
                        if "Safety_Factor" in self.doc["Discretization"]:
                            self.safety_factor = float(self.doc["Discretization"]["Safety_Factor"])
                        if not ("File") in self.doc["Discretization"]:
                            print ("Error: No File tag found")
                            sys.exit(1)
                        ## Object for handling the discrete nodes
                        self.geometry = geometry.Geometry()
                        self.geometry.readNodes(self.dim,self.doc["Discretization"]["File"]["Name"])
                        ## The minimal nodal spacing
                        self.delta_X = self.geometry.getMinDist()
                        ## Amount of nodes
                        self.num_nodes = self.geometry.amount
                        if "Boundary" in self.doc:
                            if not "Condition" in self.doc["Boundary"]:
                                print ("Error: No Condition tag found")
                                sys.exit(1)
                            else:
                                ## List of all conditions specified in the configuration file
                                self.conditions = []
                                for i in range(0,len(self.doc["Boundary"]["Condition"]["Value"])):
                                    self.conditions.append(condition.ConditionFromFile(self.doc["Boundary"]["Condition"]["Type"][i],self.doc["Boundary"]["Condition"]["File"][i],self.doc["Boundary"]["Condition"]["Value"][i],self.geometry.volumes,self.doc["Boundary"]["Condition"]["Direction"][i],self.doc["Boundary"]["Condition"]["Shape"][i]))
                            if not "Shape" in self.doc["Boundary"]:
                                print ("Error: No Shape tag found")
                                sys.exit(1)
                            else:
                                ## Type of the shape, e.g. Ramp
                                self.shape_type = self.doc["Boundary"]["Shape"]["Type"]
                                ## List of the values for specifying the shape
                                self.shape_values = self.doc["Boundary"]["Shape"]["Values"]

                    if not "Material" in self.doc:
                        print ("Error: Specify a material tag in your yaml")
                        sys.exit(1)
                    else:
                        if not "Type" in self.doc["Material"]:
                            print ("Error: No Type tag found")
                            sys.exit(1)
                        else:
                            ## Type of the material
                            self.material_type = self.doc["Material"]["Type"]
                            if self.material_type == "Elastic":
                                if self.dim == 1:
                                    if not "Young_Modulus" in self.doc["Material"]:
                                        print ("Error: No Young_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Young modulus of the material
                                        self.young_modulus = float(self.doc["Material"]["Young_Modulus"])
                                if self.dim >= 2:
                                    if not "Bulk_Modulus" in self.doc["Material"]:
                                        print ("Error: No Bulk_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Bulk modulus of the material
                                        self.bulk_modulus = float(self.doc["Material"]["Bulk_Modulus"])
                                    if not "Shear_Modulus" in self.doc["Material"]:
                                        print ("Error: No Shear_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Shear modulus of the material
                                        self.shear_modulus = float(self.doc["Material"]["Shear_Modulus"])
                            elif self.material_type == "Viscoelastic":
                                if self.dim == 1:
                                    if not "Relax_Modulus" in self.doc["Material"]:
                                        print ("Error: No Relax_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Relaxation modulus of the material
                                        self.relax_modulus = self.doc["Material"]["Relax_Modulus"]
                                if self.dim >= 2:
                                    if not "Relax_Bulk_Modulus" in self.doc["Material"]:
                                        print ("Error: No Relax_Bulk_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Relaxation Bulk modulus of the material
                                        self.relax_bulk_modulus = np.asarray(self.doc["Material"]["Relax_Bulk_Modulus"], dtype=np.float64)
                                    if not "Relax_Shear_Modulus" in self.doc["Material"]:
                                        print ("Error: No Relax_Shear_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Relaxation Shear modulus of the material
                                        self.relax_shear_modulus = np.asarray(self.doc["Material"]["Relax_Shear_Modulus"], dtype=np.float64)
                                if not "Relax_Time" in self.doc["Material"]:
                                    print ("Error: No Relax_Time tag found")
                                    sys.exit(1)
                                else:
                                    ## Relaxation times
                                    self.relax_time = np.asarray(self.doc["Material"]["Relax_Time"], dtype=np.float64)
                            else:
                                print ("Error in deck.py: Material type unknown, please use Elastic or Viscoelastic")
                                sys.exit(1)
                        ## List of all outputs specified in the configuration file
                        self.outputs = []
                        if "Output" in self.doc:
                            if  "CSV" in self.doc["Output"]:
                                if not "Type" in self.doc["Output"]["CSV"]:
                                    print ("Error: No Type tag found")
                                    sys.exit(1)
                                elif not "File" in self.doc["Output"]["CSV"]:
                                    print ("Error: No File tag found")
                                    sys.exit(1)
                                else:
                                    for i in range(0,len(self.doc["Output"]["CSV"]["File"])):
                                        self.outputs.append(output.OutputCSV("CSV",self.doc["Output"]["CSV"]["Type"][i],self.doc["Output"]["CSV"]["File"][i]))
                            if "VTK" in self.doc["Output"]:
                                if not "Path" in self.doc["Output"]["VTK"]:
                                    print ("Error: No Path tag found in VTK")
                                    sys.exit(1)
                                elif not "Type" in self.doc["Output"]["VTK"]:
                                    print ("Error: No Type tag found in VTK")
                                    sys.exit(1)
                                elif not "Slice" in self.doc["Output"]["VTK"]:
                                    print ("Error: No Slice tag found in VTK")
                                    sys.exit(1)
                                else:
                                    ## Visualization ToolKit (VTK) writer
                                    self.vtk_writer = vis.vtk_writer(self.doc["Output"]["VTK"]["Path"],self.doc["Output"]["VTK"]["Type"],self.doc["Output"]["VTK"]["Slice"])
                                    if self.vtk_writer.vtk_enabled == False:
                                        print ("Warning: VTK found, but no PyVTK is found, so there will be no output written.")
                            else:
                                self.vtk_writer = vis.vtk_writer()
                        else:
                            self.vtk_writer = vis.vtk_writer()

                        if not "Solver" in  self.doc:
                            print ("Error: No Solver tag found")
                            sys.exit(1)
                        else:
                            if not "Max_Iteration" in self.doc["Solver"]:
                                print ("Error: No Max_Iteration tag in Solver found")
                                sys.exit(1)
                            else:
                                ## Maximum number iteration
                                self.solver_max_it = self.doc["Solver"]["Max_Iteration"]
                            if not "Tolerance" in self.doc["Solver"]:
                                print ("Error: No Tolerance tag in Solver found")
                                sys.exit(1)
                            else:
                                ## Absolute tolerance of the solver
                                self.solver_tolerance = float(self.doc["Solver"]["Tolerance"])
                            if not "Jacobian_Perturbation" in self.doc["Solver"]:
                                print ("Error: No Jacobian_Perturbation tag in Solver found")
                                sys.exit(1)
                            else:
                                ## Perturbation factor for the Jacobian matrix
                                self.solver_perturbation = float(self.doc["Solver"]["Jacobian_Perturbation"])

                        if "Parallel" in self.doc:
                            if "Threads" in self.doc["Parallel"]:
                                self.num_threads = int(self.doc["Parallel"]["Threads"])

class DIC_deck():

    ## Constructor
    # Reads the configuration in the yaml file and stores the values
    # @param inputFile The path to the yaml file with the configuration
    def __init__(self,inputFile):
            if not os.path.exists(inputFile):
                print ("Error: Could not find " + inputFile)
                sys.exit(1)
            else:
                with open(inputFile,'r') as f:
                    ## Container of the tags parsed from the yaml file
                    self.doc = yaml.load(f)
                    if not "Material" in self.doc:
                        print ("Error: Specify a Material tag in your yaml")
                        sys.exit(1)
                    else:
                        if not "Type" in self.doc["Material"]:
                            print ("Error: No type tag found")
                            sys.exit(1)
                        else:
                            ## Type of the material
                            self.material_type = self.doc["Material"]["Type"]
                            if self.material_type == "Elastic":
                                if "Young_Modulus" in self.doc["Material"]:
                                    ## Young modulus of the material<commit_msg>Add a defualt yaml loader to avoid code explotation (closes #41)<commit_after># -*- coding: utf-8 -*-
#@author: <EMAIL>
#@author: <EMAIL>
#@author: <EMAIL>
import yaml
import os.path
from . import geometry
import sys
from . import output
from ..util import condition
from . import vis
from . import dic
import numpy as np

## Class handeling the input of the yaml file and storing the values
class PD_deck():

    ## Constructor
    # Reads the configuration in the yaml file and stores the values
    # @param inputFile The path to the yaml file with the configuration
    def __init__(self,inputFile):
            if not os.path.exists(inputFile):
                print ("Error: Could not find " + inputFile)
                sys.exit(1)
            else:
                with open(inputFile,'r') as f:
                    ## Container of the tags parsed from the yaml file
                    self.doc = yaml.load(f, Loader=yaml.FullLoader)
                    ## Safety factor for the computation of the radius
                    self.safety_factor = 1.001
                    ## Number of threads
                    self.num_threads = 1

                    if not "Discretization" in self.doc:
                        print ("Error: Specific a Discretization tag in your yaml")
                        sys.exit(1)
                    else:
                        if not "Dim" in self.doc["Discretization"]:
                            print ("Error: No Dim tag found")
                            sys.exit(1)
                        else:
                            ## Dimension of the problem
                            self.dim = int(self.doc["Discretization"]["Dim"])
                            if self.dim == 2:
                                if not "Type" in self.doc["Discretization"]:
                                    print ("Error: No Type tag found for 2D problem. Choose Plane_Stress or Plane_Strain")
                                    sys.exit(1)
                                else:
                                    ## Type of 2D problem
                                    self.type2d = self.doc["Discretization"]["Type"]
                        if not "Final_Time" in self.doc["Discretization"]:
                            print ("Error: No Final_Time tag found")
                            sys.exit(1)
                        else:
                            ## Final time of the problem
                            self.final_time = float(self.doc["Discretization"]["Final_Time"])
                        if not "Time_Steps" in self.doc["Discretization"]:
                            print ("Error: No Time_Steps tag found")
                            sys.exit(1)
                        else:
                            ## Amount of time steps
                            self.time_steps = int(self.doc["Discretization"]["Time_Steps"]) + 1
                            ## Time step size
                            self.delta_t = float(self.final_time  / (self.time_steps-1))
                        if not "Horizon_Factor_m_value" in self.doc["Discretization"]:
                            print ("Error: No Horizon_Factor tag found")
                            sys.exit(1)
                        else:
                            ## "m" value of the horizon factor
                            self.horizon_factor_m_value = float(self.doc["Discretization"]["Horizon_Factor_m_value"])
                        if not "Influence_Function" in self.doc["Discretization"]:
                            print ("Error: Influence_Function tag found")
                            sys.exit(1)
                        else:
                            ## Influence function
                            self.influence_function = self.doc["Discretization"]["Influence_Function"]
                        if "Safety_Factor" in self.doc["Discretization"]:
                            self.safety_factor = float(self.doc["Discretization"]["Safety_Factor"])
                        if not ("File") in self.doc["Discretization"]:
                            print ("Error: No File tag found")
                            sys.exit(1)
                        ## Object for handling the discrete nodes
                        self.geometry = geometry.Geometry()
                        self.geometry.readNodes(self.dim,self.doc["Discretization"]["File"]["Name"])
                        ## The minimal nodal spacing
                        self.delta_X = self.geometry.getMinDist()
                        ## Amount of nodes
                        self.num_nodes = self.geometry.amount
                        if "Boundary" in self.doc:
                            if not "Condition" in self.doc["Boundary"]:
                                print ("Error: No Condition tag found")
                                sys.exit(1)
                            else:
                                ## List of all conditions specified in the configuration file
                                self.conditions = []
                                for i in range(0,len(self.doc["Boundary"]["Condition"]["Value"])):
                                    self.conditions.append(condition.ConditionFromFile(self.doc["Boundary"]["Condition"]["Type"][i],self.doc["Boundary"]["Condition"]["File"][i],self.doc["Boundary"]["Condition"]["Value"][i],self.geometry.volumes,self.doc["Boundary"]["Condition"]["Direction"][i],self.doc["Boundary"]["Condition"]["Shape"][i]))
                            if not "Shape" in self.doc["Boundary"]:
                                print ("Error: No Shape tag found")
                                sys.exit(1)
                            else:
                                ## Type of the shape, e.g. Ramp
                                self.shape_type = self.doc["Boundary"]["Shape"]["Type"]
                                ## List of the values for specifying the shape
                                self.shape_values = self.doc["Boundary"]["Shape"]["Values"]

                    if not "Material" in self.doc:
                        print ("Error: Specify a material tag in your yaml")
                        sys.exit(1)
                    else:
                        if not "Type" in self.doc["Material"]:
                            print ("Error: No Type tag found")
                            sys.exit(1)
                        else:
                            ## Type of the material
                            self.material_type = self.doc["Material"]["Type"]
                            if self.material_type == "Elastic":
                                if self.dim == 1:
                                    if not "Young_Modulus" in self.doc["Material"]:
                                        print ("Error: No Young_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Young modulus of the material
                                        self.young_modulus = float(self.doc["Material"]["Young_Modulus"])
                                if self.dim >= 2:
                                    if not "Bulk_Modulus" in self.doc["Material"]:
                                        print ("Error: No Bulk_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Bulk modulus of the material
                                        self.bulk_modulus = float(self.doc["Material"]["Bulk_Modulus"])
                                    if not "Shear_Modulus" in self.doc["Material"]:
                                        print ("Error: No Shear_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Shear modulus of the material
                                        self.shear_modulus = float(self.doc["Material"]["Shear_Modulus"])
                            elif self.material_type == "Viscoelastic":
                                if self.dim == 1:
                                    if not "Relax_Modulus" in self.doc["Material"]:
                                        print ("Error: No Relax_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Relaxation modulus of the material
                                        self.relax_modulus = self.doc["Material"]["Relax_Modulus"]
                                if self.dim >= 2:
                                    if not "Relax_Bulk_Modulus" in self.doc["Material"]:
                                        print ("Error: No Relax_Bulk_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Relaxation Bulk modulus of the material
                                        self.relax_bulk_modulus = np.asarray(self.doc["Material"]["Relax_Bulk_Modulus"], dtype=np.float64)
                                    if not "Relax_Shear_Modulus" in self.doc["Material"]:
                                        print ("Error: No Relax_Shear_Modulus tag found")
                                        sys.exit(1)
                                    else:
                                        ## Relaxation Shear modulus of the material
                                        self.relax_shear_modulus = np.asarray(self.doc["Material"]["Relax_Shear_Modulus"], dtype=np.float64)
                                if not "Relax_Time" in self.doc["Material"]:
                                    print ("Error: No Relax_Time tag found")
                                    sys.exit(1)
                                else:
                                    ## Relaxation times
                                    self.relax_time = np.asarray(self.doc["Material"]["Relax_Time"], dtype=np.float64)
                            else:
                                print ("Error in deck.py: Material type unknown, please use Elastic or Viscoelastic")
                                sys.exit(1)
                        ## List of all outputs specified in the configuration file
                        self.outputs = []
                        if "Output" in self.doc:
                            if  "CSV" in self.doc["Output"]:
                                if not "Type" in self.doc["Output"]["CSV"]:
                                    print ("Error: No Type tag found")
                                    sys.exit(1)
                                elif not "File" in self.doc["Output"]["CSV"]:
                                    print ("Error: No File tag found")
                                    sys.exit(1)
                                else:
                                    for i in range(0,len(self.doc["Output"]["CSV"]["File"])):
                                        self.outputs.append(output.OutputCSV("CSV",self.doc["Output"]["CSV"]["Type"][i],self.doc["Output"]["CSV"]["File"][i]))
                            if "VTK" in self.doc["Output"]:
                                if not "Path" in self.doc["Output"]["VTK"]:
                                    print ("Error: No Path tag found in VTK")
                                    sys.exit(1)
                                elif not "Type" in self.doc["Output"]["VTK"]:
                                    print ("Error: No Type tag found in VTK")
                                    sys.exit(1)
                                elif not "Slice" in self.doc["Output"]["VTK"]:
                                    print ("Error: No Slice tag found in VTK")
                                    sys.exit(1)
                                else:
                                    ## Visualization ToolKit (VTK) writer
                                    self.vtk_writer = vis.vtk_writer(self.doc["Output"]["VTK"]["Path"],self.doc["Output"]["VTK"]["Type"],self.doc["Output"]["VTK"]["Slice"])
                                    if self.vtk_writer.vtk_enabled == False:
                                        print ("Warning: VTK found, but no PyVTK is found, so there will be no output written.")
                            else:
                                self.vtk_writer = vis.vtk_writer()
                        else:
                            self.vtk_writer = vis.vtk_writer()

                        if not "Solver" in  self.doc:
                            print ("Error: No Solver tag found")
                            sys.exit(1)
                        else:
                            if not "Max_Iteration" in self.doc["Solver"]:
                                print ("Error: No Max_Iteration tag in Solver found")
                                sys.exit(1)
                            else:
                                ## Maximum number iteration
                                self.solver_max_it = self.doc["Solver"]["Max_Iteration"]
                            if not "Tolerance" in self.doc["Solver"]:
                                print ("Error: No Tolerance tag in Solver found")
                                sys.exit(1)
                            else:
                                ## Absolute tolerance of the solver
                                self.solver_tolerance = float(self.doc["Solver"]["Tolerance"])
                            if not "Jacobian_Perturbation" in self.doc["Solver"]:
                                print ("Error: No Jacobian_Perturbation tag in Solver found")
                                sys.exit(1)
                            else:
                                ## Perturbation factor for the Jacobian matrix
                                self.solver_perturbation = float(self.doc["Solver"]["Jacobian_Perturbation"])

                        if "Parallel" in self.doc:
                            if "Threads" in self.doc["Parallel"]:
                                self.num_threads = int(self.doc["Parallel"]["Threads"])

class DIC_deck():

    ## Constructor
    # Reads the configuration in the yaml file and stores the values
    # @param inputFile The path to the yaml file with the configuration
    def __init__(self,inputFile):
            if not os.path.exists(inputFile):
                print ("Error: Could not find " + inputFile)
                sys.exit(1)
            else:
                with open(inputFile,'r') as f:
                    ## Container of the tags parsed from the yaml file
                    self.doc = yaml.load(f, Loader=yaml.FullLoader)
                    if not "Material" in self.doc:
                        print ("Error: Specify a Material tag in your yaml")
                        sys.exit(1)
                    else:
                        if not "Type" in self.doc["Material"]:
                            print ("Error: No type tag found")
                            sys.exit(1)
                        else:
                            ## Type of the material
                            self.material_type = self.doc["Material"]["Type"]
                            if self.material_type == "Elastic":
                                if "Young_Modulus" in self.doc["Material"]:
                                    ## Young modulus of the material
{'fraction_non_alphanumeric': 0.09050614346706645, 'fraction_numerical': 0.003780595117817684, 'mean_word_length': 0.9667970001922954, 'pattern_counts': {'":': 6, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 188, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6919066', 'n_tokens_mistral': 6957, 'n_tokens_neox': 6755, 'n_words': 1783}