Source code for viiapackage.supports.shallow_foundation.create_material

### ===================================================================================================================
###   Create the material for shallow foundations
### ===================================================================================================================
# Copyright ©VIIA 2024

### ===================================================================================================================
###   1. Import modules
### ===================================================================================================================

# General imports
from __future__ import annotations
from typing import TYPE_CHECKING, List
import math
from pathlib import Path
from typing import Union, Dict, List, Tuple, Any

# References for functions and classes in the rhdhv_fem package
from rhdhv_fem.fem_tools import fem_read_file, fem_make_list_of_text
from rhdhv_fem.materials import UserSuppliedMaterialModel, RayleighDamping, InterfaceBehaviour, Surface3DInterfaceType

# References for functions and classes in the viiaPackage
if TYPE_CHECKING:
    from viiapackage.viiaStatus import ViiaProject


### ===================================================================================================================
###   2. Function to collect data for shallow foundation material from MYVIIA
### ===================================================================================================================

[docs]def viia_calculate_cut_off_value_for_stiffness( total_mass: float, area_foundation: float, cut_off_frequency: float = 50) -> float: """ Function to calculate the cut-off value for spring stiffness based on the mass of the building and the foundation area. Input: - total_mass (float): Total mass of the building(part), in [kg]. - area_foundation (float): Total area of the shallow foundation, in [m2]. - cut_off_frequency (float): Limit for the stiffness calculation to prevent base isolation behaviour, in [Hz]. Default value is 50 Hz. Output: - Returns the spring stiffness value, in [N/m/m2], as a float. """ # Calculate the spring stiffness return (cut_off_frequency * 2 * math.pi)**2 * total_mass / area_foundation
[docs]def viia_calculate_friction_coefficient( project: ViiaProject, mass: float, horizontal_capacity: float) -> float: """ This function calculates the friction coefficient based on the mass of the building and the horizontal capacity calculated by the geotechnical advisor. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - mass (float): Mass of the building(part), in [kg]. - horizontal_capacity (float): Value for the horizontal capacity of the shallow foundation, in [kN]. Output: - Returns the value of the friction coefficient, in [-], as a float. """ return horizontal_capacity * 1E3 / (mass * project.gravitational_acceleration)
[docs]def viia_convert_material_properties_from_myviia( project: ViiaProject, myviia_data: Dict[str, Any]) -> Dict[str, Any]: """ This function converts a record from the MYVIIA database to the required parameters in the viiaPackage. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - myviia_data (dict): Dictionary with the data from the controller of the MYVIIA tool. Output: - Returns dictionary with the retrieved data. Passes only data that could be retrieved from MYVIIA. No validation is performed on the output. """ # Check if the stiffnesses are provided, else use the cut-off value for the stiffnesses normal_stiffness = myviia_data['normal_stiffness'] if normal_stiffness is None: normal_stiffness = viia_calculate_cut_off_value_for_stiffness( total_mass=myviia_data['total_mass'], area_foundation=myviia_data['area_foundation']) shear_stiffness = myviia_data['shear_stiffness'] if shear_stiffness is None: shear_stiffness = viia_calculate_cut_off_value_for_stiffness( total_mass=myviia_data['total_mass'], area_foundation=myviia_data['area_foundation']) # Collect the properties return { 'normal_stiffness_modulus_z': normal_stiffness, 'shear_stiffness_modulus_x': shear_stiffness, 'shear_stiffness_modulus_y': shear_stiffness, 'rayleigh_mass_factor': 6.26231E-02, 'rayleigh_stiffness_factor': 5.30522E-04, 'material_parameters': [ viia_calculate_friction_coefficient( project=project, horizontal_capacity=myviia_data['capacity_horizontal'], mass=myviia_data['total_mass']), myviia_data['capacity_vertical']], 'initial_state_values': 0.0}
### =================================================================================================================== ### 3. Function to collect data for shallow foundation material from dat-file ### ===================================================================================================================
[docs]def viia_get_shallow_foundation_material_properties_from_file( project: ViiaProject, material_file: Union[Path, str]) \ -> Tuple[str, Dict[str, Union[float, int, List[Union[float, int]]]]]: """ Function to read material data file from DIANA (in DIANA syntax) and convert to dictionary with the required material properties for the shallow foundation flexbase material. This function does not validate the data. .. note:: This file is expected to be in a certain format. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - material_file (str or Path): Name of the dat-file that is located in the working directory, or full path of location of the dat-file. Output: - Returns dictionary with the retrieved data. Passes only data that could be retrieved from the file. No validation is performed on the output. """ # Convert input for file for correct file handling if not isinstance(material_file, Path): if '.dat' not in material_file: material_file += '.dat' material_file = project.workfolder_location / material_file # Check if the file exists in the provided location if not material_file.exists(): raise FileNotFoundError( f"ERROR: The input file for shallow foundation material could not be retrieved. " f"Looking for {material_file.as_posix()}.") # Read file data = fem_read_file(file=material_file) # Filter the data from the file properties = {} material_name = None mapping = { 'DSNZ': 'normal_stiffness_modulus_z', 'DSSX': 'shear_stiffness_modulus_x', 'DSSY': 'shear_stiffness_modulus_y', 'USRSTA': 'initial_state_values'} for line in data: line = line.replace('\t', '') for k, v in mapping.items(): if k in line: properties[v] = float(fem_make_list_of_text(line)[-1]) if 'NAME' in line: material_name = fem_make_list_of_text(line)[-1] if material_name != material_file.stem: project.write_log( "WARNING: The name of the material in the dat-file does not correspond to the name of the file. " "Note that the name of the file should be same as the material name in the file.") if 'RAYLEI' in line: rayleigh = fem_make_list_of_text(line) properties['rayleigh_mass_factor'] = float(rayleigh[-2]) properties['rayleigh_stiffness_factor'] = float(rayleigh[-1]) if 'USRVAL' in line: usrval = fem_make_list_of_text(line) properties['material_parameters'] = [float(usrval[-2]), float(usrval[-1])] # Check if name was present if not material_name: raise ValueError("ERROR: The name of the material for the flexbase material could not be found.") # Return the collected properties return material_name, properties
### =================================================================================================================== ### 4. Function to create shallow foundation material for flexbase ### ===================================================================================================================
[docs]def viia_create_shallow_foundation_material( project: ViiaProject, material_name: str, properties: Dict[str, Union[float, int, List[Union[float, int]]]]) -> InterfaceBehaviour: """ This function creates a material object for the shallow foundation flexbase interface behaviour. A dictionary with the material properties is converted to the required material model. Input: - project (obj): VIIA project object containing collections of fem objects and project variables. - material_name (str): Name of the shallow foundation flexbase material. - properties (dict): Dictionary with the required material properties for the shallow foundation flexbase interface behaviour. The following keys should be present: 'normal_stiffness_modulus_z', 'shear_stiffness_modulus_x', 'shear_stiffness_modulus_y', 'material_parameters', 'initial_state_values', 'rayleigh_mass_factor' and 'rayleigh_stiffness_factor'. All the values should be floats or integers, except input value for 'material_parameters' which should be a list of two floats or integers. Output: - Returns the material for interface behaviour, required for the surface interface for flexbase shallow foundations. """ # Set default Rayleigh values if not provided if 'rayleigh_mass_factor' not in properties: properties['rayleigh_mass_factor'] = 6.26231E-02 if 'rayleigh_stiffness_factor' not in properties: properties['rayleigh_stiffness_factor'] = 5.30522E-04 # Validate input for key in [ 'normal_stiffness_modulus_z', 'shear_stiffness_modulus_x', 'shear_stiffness_modulus_y', 'material_parameters', 'initial_state_values', 'rayleigh_mass_factor', 'rayleigh_stiffness_factor']: if key not in properties: raise ValueError( "ERROR: The properties dictionary is not correct, please check and provide correct properties.") for k, v in properties.items(): if k == 'material_parameters': if not isinstance(v, list) or len(v) != 2: raise ValueError( f"ERROR: Input for material properties '{k}' of shallow foundation material should be a list with " f"2 floats or integers.") for item in v: if not isinstance(item, (float, int)): raise ValueError( f"ERROR: Input for material properties '{k}' of shallow foundation material should be a list " f"with 2 floats or integers.") elif not isinstance(v, (float, int)): raise ValueError( f"ERROR: Input for material properties '{k}' of shallow foundation material should be a float or " f"integer.") # Check for boundaries of applicable stiffnesses, set by knowledge-team if not 1.0E7 <= properties['normal_stiffness_modulus_z'] <= 1.0E10: raise ValueError( f"ERROR: Input for the vertical stiffness of the boundary interface for the shallow foundation " f"{properties['normal_stiffness_modulus_z']} is outside the expected range 1E7 ≤ stiffness ≤ 1E10. " f"Please check your input.") if not 1.0E7 <= properties['shear_stiffness_modulus_x'] <= 1.0E10: raise ValueError( f"ERROR: Input for the horizontal stiffness of the boundary interface for the shallow foundation " f"{properties['shear_stiffness_modulus_x']} is outside the expected range 1E7 ≤ stiffness ≤ 1E10. " f"Please check your input.") if not 1.0E7 <= properties['shear_stiffness_modulus_y'] <= 1.0E10: raise ValueError( f"ERROR: Input for the horizontal stiffness of the boundary interface for the shallow foundation " f"{properties['shear_stiffness_modulus_y']} is outside the expected range 1E7 ≤ stiffness ≤ 1E10. " f"Please check your input.") # Create the interface type helper material model interface_type = Surface3DInterfaceType( normal_stiffness_modulus_z=properties['normal_stiffness_modulus_z'], shear_stiffness_modulus_x=properties['shear_stiffness_modulus_x'], shear_stiffness_modulus_y=properties['shear_stiffness_modulus_y']) # Create the material aspect for user supplied material models user_supplied_material = UserSuppliedMaterialModel( name='COULOMB', material_model_type='usrifc', # Two parameters required for the material parameters: # First material parameter is the friction angle for the horizontal capacity # The second material parameter is the vertical bearing capacity material_parameters=properties['material_parameters'], # One value required for the initial state values: # The value for the initial state is 0 initial_state_values=properties['initial_state_values']) # Create the Rayleigh damping material aspect rayleigh_damping = RayleighDamping( mass_factor=properties['rayleigh_mass_factor'], stiffness_factor=properties['rayleigh_stiffness_factor']) # Create the material model material_model = project.create_linear_elastic_interface_model( interface_type=interface_type, aspects=[rayleigh_damping, user_supplied_material]) # Create the material return project.create_user_defined_interface_behaviour( name=material_name, material_model=material_model)
### =================================================================================================================== ### 5. End of script ### ===================================================================================================================