sensotwin.lifetime_extrapolation.configuration
1from pyiron_base import Project 2from pyiron_base import PythonTemplateJob 3import os 4import hashlib 5import pyvista as pv 6import numpy as np 7from sensotwin.lifetime_extrapolation.simulation import remainingLifeTimePrediction 8from sensotwin.lifetime_extrapolation.simulation import processSimulation 9from ..temperature_selection.configuration import MaterialHardeningInputDataSet 10from ..defect_placement.configuration import DefectInputDataSet 11from ..stress_selection.configuration import StressStrainInputDataSet 12from ..store_connection import StoreConnection 13 14class StructureSimulation(PythonTemplateJob): 15 """Pyiron job class to execute structural simulation. 16 17 Second step in the simulation chain. 18 First calculates static loads for specified scenario and then uses those to calculate 19 damage states and expected remaining lifetime for all cells/layers of the wind turbine 20 """ 21 def __init__(self, project, job_name): 22 """Initialize job.""" 23 super().__init__(project, job_name) 24 self.input.cpu_cores=1 25 26 def run_static(self): 27 """Execute job.""" 28 wind_speed = self.input.stress_strain_input.get_wind_speed() 29 duration = self.input.stress_strain_input.get_duration() 30 31 # simulation expects the file path to exists before job has finished 32 if not os.path.exists(self.working_directory): 33 os.makedirs(self.working_directory) 34 relative_job_dir = self.working_directory.replace(os.getcwd() + "/", "") 35 36 mesh_list = remainingLifeTimePrediction.f_calculateRemainingLifeTime( 37 wind_speed = wind_speed, 38 simulation_time = duration, 39 working_dir = relative_job_dir, 40 num_cpus = self.input.cpu_cores, 41 ccx_input_files = self.input.ccx_input_files 42 ) 43 44 for mesh in mesh_list: 45 if "FATIGUE.vtu" in mesh: 46 self.output.mesh = mesh 47 if "FATIGUE.vtu" in mesh: 48 self.output.curing_mesh = mesh 49 50 self.output.remaining_lifetime = self.extract_remaining_lifetime_from_mesh() 51 self.status.finished = True 52 self.to_hdf() 53 54 def generate_ontology_label(self) -> str: 55 """Generate ontology label for saving results to triple store after execution.""" 56 return "__LifetimeExtrapolationSimulationProcess_{material_hardening_input}_{defect_placement_input}_{stress_strain_input}".format( 57 material_hardening_input = self.input.material_hardening_input.get_id(), 58 defect_placement_input = self.input.defect_placement_input.get_id(), 59 stress_strain_input = self.input.stress_strain_input.get_id() 60 ) 61 62 def save_simulation_to_ontology(self, conn: StoreConnection): 63 """Save completed job result to triple store.""" 64 label = self.generate_ontology_label() 65 query = """ 66 INSERT {{ 67 senso:{label}_Result a senso:TotalLifeTime ; 68 co:value {remaining_lifetime} . 69 senso:{label} a senso:LifetimeExtrapolationSimulationProcess ; 70 co:input senso:{material_hardening_input} ; 71 co:input senso:{defect_placement_input} ; 72 co:input senso:{stress_strain_input} ; 73 co:output senso:{label}_Result . 74 }} WHERE {{ }} 75 """.format(label = label, 76 material_hardening_input = self.input.material_hardening_input.generate_ontology_label(), 77 defect_placement_input = self.input.defect_placement_input.generate_ontology_label(), 78 stress_strain_input = self.input.stress_strain_input.generate_ontology_label(), 79 remaining_lifetime = self.output.remaining_lifetime) 80 conn.update_data(query) 81 82 def extract_remaining_lifetime_from_mesh(self): 83 """Extract maximum remaining lifetime from result mesh after job execution.""" 84 result_mesh = pv.read(self.output.mesh).cast_to_unstructured_grid() 85 min_values = [] 86 for scalar in result_mesh.cell_data: 87 if scalar.startswith("TFAT"): 88 min_values.append(np.nanmin(result_mesh[scalar])) 89 return np.min(min_values) 90 91 92class MaterialSimulation(PythonTemplateJob): 93 """Pyiron job class to execute material manufactoring simulation. 94 95 First step in the simulation chain. 96 Simulates material curing behaviour and then applies selected faults to mesh input files 97 for later steps 98 """ 99 def __init__(self, project, job_name): 100 """Initialize job.""" 101 super().__init__(project, job_name) 102 103 def run_static(self): 104 """Execute job.""" 105 # simulation expects the file path to exists before job has finished 106 if not os.path.exists(self.working_directory): 107 os.makedirs(self.working_directory) 108 relative_job_dir = self.working_directory.replace(os.getcwd() + "/", "") 109 110 output_files = processSimulation.simulate_process( 111 fvc = self.input.material_hardening_input.get_fibre_volume_content().get_value(), 112 time_data = self.input.material_hardening_input.get_temperature_graph().get_time_data(), 113 temperature_data = self.input.material_hardening_input.get_temperature_graph().get_temperature_data(), 114 defect_list = [x.to_simulation_input_dict() for x in self.input.defect_placement_input.get_defects()], 115 working_directory = relative_job_dir 116 ) 117 self.output.ccx_input_files = output_files 118 self.status.finished = True 119 self.to_hdf() 120 121 122def execute_job(pr: Project, 123 material_hardening_input: MaterialHardeningInputDataSet, 124 defect_placement_input: DefectInputDataSet, 125 stress_strain_input: StressStrainInputDataSet, 126 conn: StoreConnection=None): 127 """Execute chain of pyiron jobs the calculate remaining lifetime of wind turbine according to given scenario. 128 129 Args: 130 pr: Initialized pyiron project object 131 material_hardening_input: Parameters for material curing behaviour 132 defect_placement_input: Parameters for component manufactoring defects 133 stress_strain_input: Operational parameters for wind and duration of simulation 134 conn: If valid StoreConnection is passed, result will be saved to specified triple store 135 """ 136 name_hash = "{}_{}_{}".format(material_hardening_input.get_id(),defect_placement_input.get_id(), stress_strain_input.get_id()) 137 138 curing_job = pr.create_job(MaterialSimulation, job_name=("curing_", name_hash), delete_existing_job=True) 139 curing_job.input.material_hardening_input = material_hardening_input 140 curing_job.input.defect_placement_input = defect_placement_input 141 curing_job.input.stress_strain_input = stress_strain_input 142 curing_job.run() 143 144 structure_job = pr.create_job(StructureSimulation, job_name=("struct_", name_hash), delete_existing_job=True) 145 structure_job.input.material_hardening_input = material_hardening_input 146 structure_job.input.defect_placement_input = defect_placement_input 147 structure_job.input.stress_strain_input = stress_strain_input 148 structure_job.input.cpu_cores = 3 149 structure_job.input.ccx_input_files = curing_job.output.ccx_input_files 150 structure_job.run() 151 152 if conn: 153 structure_job.save_simulation_to_ontology(conn) 154 155def get_pyiron_project(project_path: str) -> Project: 156 """Get pyiron project object to use for simulation jobs. 157 158 Args: 159 project_path: Relative path for pyiron project folder 160 161 Returns: 162 Initialized pyiron project object 163 """ 164 return Project(path=project_path) 165 166def get_job_table(pr: Project): 167 return pr.job_table(auto_refresh_job_status=False)
15class StructureSimulation(PythonTemplateJob): 16 """Pyiron job class to execute structural simulation. 17 18 Second step in the simulation chain. 19 First calculates static loads for specified scenario and then uses those to calculate 20 damage states and expected remaining lifetime for all cells/layers of the wind turbine 21 """ 22 def __init__(self, project, job_name): 23 """Initialize job.""" 24 super().__init__(project, job_name) 25 self.input.cpu_cores=1 26 27 def run_static(self): 28 """Execute job.""" 29 wind_speed = self.input.stress_strain_input.get_wind_speed() 30 duration = self.input.stress_strain_input.get_duration() 31 32 # simulation expects the file path to exists before job has finished 33 if not os.path.exists(self.working_directory): 34 os.makedirs(self.working_directory) 35 relative_job_dir = self.working_directory.replace(os.getcwd() + "/", "") 36 37 mesh_list = remainingLifeTimePrediction.f_calculateRemainingLifeTime( 38 wind_speed = wind_speed, 39 simulation_time = duration, 40 working_dir = relative_job_dir, 41 num_cpus = self.input.cpu_cores, 42 ccx_input_files = self.input.ccx_input_files 43 ) 44 45 for mesh in mesh_list: 46 if "FATIGUE.vtu" in mesh: 47 self.output.mesh = mesh 48 if "FATIGUE.vtu" in mesh: 49 self.output.curing_mesh = mesh 50 51 self.output.remaining_lifetime = self.extract_remaining_lifetime_from_mesh() 52 self.status.finished = True 53 self.to_hdf() 54 55 def generate_ontology_label(self) -> str: 56 """Generate ontology label for saving results to triple store after execution.""" 57 return "__LifetimeExtrapolationSimulationProcess_{material_hardening_input}_{defect_placement_input}_{stress_strain_input}".format( 58 material_hardening_input = self.input.material_hardening_input.get_id(), 59 defect_placement_input = self.input.defect_placement_input.get_id(), 60 stress_strain_input = self.input.stress_strain_input.get_id() 61 ) 62 63 def save_simulation_to_ontology(self, conn: StoreConnection): 64 """Save completed job result to triple store.""" 65 label = self.generate_ontology_label() 66 query = """ 67 INSERT {{ 68 senso:{label}_Result a senso:TotalLifeTime ; 69 co:value {remaining_lifetime} . 70 senso:{label} a senso:LifetimeExtrapolationSimulationProcess ; 71 co:input senso:{material_hardening_input} ; 72 co:input senso:{defect_placement_input} ; 73 co:input senso:{stress_strain_input} ; 74 co:output senso:{label}_Result . 75 }} WHERE {{ }} 76 """.format(label = label, 77 material_hardening_input = self.input.material_hardening_input.generate_ontology_label(), 78 defect_placement_input = self.input.defect_placement_input.generate_ontology_label(), 79 stress_strain_input = self.input.stress_strain_input.generate_ontology_label(), 80 remaining_lifetime = self.output.remaining_lifetime) 81 conn.update_data(query) 82 83 def extract_remaining_lifetime_from_mesh(self): 84 """Extract maximum remaining lifetime from result mesh after job execution.""" 85 result_mesh = pv.read(self.output.mesh).cast_to_unstructured_grid() 86 min_values = [] 87 for scalar in result_mesh.cell_data: 88 if scalar.startswith("TFAT"): 89 min_values.append(np.nanmin(result_mesh[scalar])) 90 return np.min(min_values)
Pyiron job class to execute structural simulation.
Second step in the simulation chain. First calculates static loads for specified scenario and then uses those to calculate damage states and expected remaining lifetime for all cells/layers of the wind turbine
22 def __init__(self, project, job_name): 23 """Initialize job.""" 24 super().__init__(project, job_name) 25 self.input.cpu_cores=1
Initialize job.
27 def run_static(self): 28 """Execute job.""" 29 wind_speed = self.input.stress_strain_input.get_wind_speed() 30 duration = self.input.stress_strain_input.get_duration() 31 32 # simulation expects the file path to exists before job has finished 33 if not os.path.exists(self.working_directory): 34 os.makedirs(self.working_directory) 35 relative_job_dir = self.working_directory.replace(os.getcwd() + "/", "") 36 37 mesh_list = remainingLifeTimePrediction.f_calculateRemainingLifeTime( 38 wind_speed = wind_speed, 39 simulation_time = duration, 40 working_dir = relative_job_dir, 41 num_cpus = self.input.cpu_cores, 42 ccx_input_files = self.input.ccx_input_files 43 ) 44 45 for mesh in mesh_list: 46 if "FATIGUE.vtu" in mesh: 47 self.output.mesh = mesh 48 if "FATIGUE.vtu" in mesh: 49 self.output.curing_mesh = mesh 50 51 self.output.remaining_lifetime = self.extract_remaining_lifetime_from_mesh() 52 self.status.finished = True 53 self.to_hdf()
Execute job.
55 def generate_ontology_label(self) -> str: 56 """Generate ontology label for saving results to triple store after execution.""" 57 return "__LifetimeExtrapolationSimulationProcess_{material_hardening_input}_{defect_placement_input}_{stress_strain_input}".format( 58 material_hardening_input = self.input.material_hardening_input.get_id(), 59 defect_placement_input = self.input.defect_placement_input.get_id(), 60 stress_strain_input = self.input.stress_strain_input.get_id() 61 )
Generate ontology label for saving results to triple store after execution.
63 def save_simulation_to_ontology(self, conn: StoreConnection): 64 """Save completed job result to triple store.""" 65 label = self.generate_ontology_label() 66 query = """ 67 INSERT {{ 68 senso:{label}_Result a senso:TotalLifeTime ; 69 co:value {remaining_lifetime} . 70 senso:{label} a senso:LifetimeExtrapolationSimulationProcess ; 71 co:input senso:{material_hardening_input} ; 72 co:input senso:{defect_placement_input} ; 73 co:input senso:{stress_strain_input} ; 74 co:output senso:{label}_Result . 75 }} WHERE {{ }} 76 """.format(label = label, 77 material_hardening_input = self.input.material_hardening_input.generate_ontology_label(), 78 defect_placement_input = self.input.defect_placement_input.generate_ontology_label(), 79 stress_strain_input = self.input.stress_strain_input.generate_ontology_label(), 80 remaining_lifetime = self.output.remaining_lifetime) 81 conn.update_data(query)
Save completed job result to triple store.
83 def extract_remaining_lifetime_from_mesh(self): 84 """Extract maximum remaining lifetime from result mesh after job execution.""" 85 result_mesh = pv.read(self.output.mesh).cast_to_unstructured_grid() 86 min_values = [] 87 for scalar in result_mesh.cell_data: 88 if scalar.startswith("TFAT"): 89 min_values.append(np.nanmin(result_mesh[scalar])) 90 return np.min(min_values)
Extract maximum remaining lifetime from result mesh after job execution.
Inherited Members
- pyiron_base.jobs.job.template.TemplateJob
- input
- output
- to_hdf
- from_hdf
- pyiron_base.jobs.job.generic.GenericJob
- interactive_cache
- error
- version
- executable
- server
- queue_id
- logger
- restart_file_list
- restart_file_dict
- exclude_nodes_hdf
- exclude_groups_hdf
- job_type
- working_directory
- executor_type
- calculate_kwargs
- clear_job
- copy
- collect_logfiles
- get_calculate_function
- get_input_parameter_dict
- get_output_parameter_dict
- collect_output
- save_output
- suspend
- refresh_job_status
- write_input
- copy_to
- copy_file_to_working_directory
- copy_template
- remove
- remove_child
- remove_and_reset_id
- kill
- validate_ready_to_run
- check_setup
- reset_job_id
- run
- run_if_modal
- run_if_scheduler
- transfer_from_remote
- run_if_interactive
- run_if_interactive_non_modal
- interactive_close
- interactive_fetch
- interactive_flush
- send_to_database
- create_job
- update_master
- job_file_name
- to_dict
- from_dict
- from_hdf_args
- save
- convergence_check
- db_entry
- restart
- signal_intercept
- drop_status_to_aborted
- run_if_refresh
- set_input_to_read_only
- run_time_to_db
- pyiron_base.jobs.job.core.JobCore
- content
- files
- job_name
- name
- status
- job_id
- id
- database_entry
- parent_id
- master_id
- child_ids
- project_hdf5
- files_to_compress
- files_to_remove
- relocate_hdf5
- project
- job_info_str
- path
- check_if_job_exists
- show_hdf
- get_from_table
- to_object
- get
- load
- inspect
- is_master_id
- get_job_id
- list_files
- list_childs
- move_to
- rename
- compress
- decompress
- is_compressed
- self_archive
- self_unarchive
- is_self_archived
- pyiron_base.interfaces.has_groups.HasGroups
- list_groups
- list_nodes
- list_all
- pyiron_base.interfaces.object.HasStorage
- storage
- pyiron_base.interfaces.has_hdf.HasHDF
- rewrite_hdf
93class MaterialSimulation(PythonTemplateJob): 94 """Pyiron job class to execute material manufactoring simulation. 95 96 First step in the simulation chain. 97 Simulates material curing behaviour and then applies selected faults to mesh input files 98 for later steps 99 """ 100 def __init__(self, project, job_name): 101 """Initialize job.""" 102 super().__init__(project, job_name) 103 104 def run_static(self): 105 """Execute job.""" 106 # simulation expects the file path to exists before job has finished 107 if not os.path.exists(self.working_directory): 108 os.makedirs(self.working_directory) 109 relative_job_dir = self.working_directory.replace(os.getcwd() + "/", "") 110 111 output_files = processSimulation.simulate_process( 112 fvc = self.input.material_hardening_input.get_fibre_volume_content().get_value(), 113 time_data = self.input.material_hardening_input.get_temperature_graph().get_time_data(), 114 temperature_data = self.input.material_hardening_input.get_temperature_graph().get_temperature_data(), 115 defect_list = [x.to_simulation_input_dict() for x in self.input.defect_placement_input.get_defects()], 116 working_directory = relative_job_dir 117 ) 118 self.output.ccx_input_files = output_files 119 self.status.finished = True 120 self.to_hdf()
Pyiron job class to execute material manufactoring simulation.
First step in the simulation chain. Simulates material curing behaviour and then applies selected faults to mesh input files for later steps
100 def __init__(self, project, job_name): 101 """Initialize job.""" 102 super().__init__(project, job_name)
Initialize job.
104 def run_static(self): 105 """Execute job.""" 106 # simulation expects the file path to exists before job has finished 107 if not os.path.exists(self.working_directory): 108 os.makedirs(self.working_directory) 109 relative_job_dir = self.working_directory.replace(os.getcwd() + "/", "") 110 111 output_files = processSimulation.simulate_process( 112 fvc = self.input.material_hardening_input.get_fibre_volume_content().get_value(), 113 time_data = self.input.material_hardening_input.get_temperature_graph().get_time_data(), 114 temperature_data = self.input.material_hardening_input.get_temperature_graph().get_temperature_data(), 115 defect_list = [x.to_simulation_input_dict() for x in self.input.defect_placement_input.get_defects()], 116 working_directory = relative_job_dir 117 ) 118 self.output.ccx_input_files = output_files 119 self.status.finished = True 120 self.to_hdf()
Execute job.
Inherited Members
- pyiron_base.jobs.job.template.TemplateJob
- input
- output
- to_hdf
- from_hdf
- pyiron_base.jobs.job.generic.GenericJob
- interactive_cache
- error
- version
- executable
- server
- queue_id
- logger
- restart_file_list
- restart_file_dict
- exclude_nodes_hdf
- exclude_groups_hdf
- job_type
- working_directory
- executor_type
- calculate_kwargs
- clear_job
- copy
- collect_logfiles
- get_calculate_function
- get_input_parameter_dict
- get_output_parameter_dict
- collect_output
- save_output
- suspend
- refresh_job_status
- write_input
- copy_to
- copy_file_to_working_directory
- copy_template
- remove
- remove_child
- remove_and_reset_id
- kill
- validate_ready_to_run
- check_setup
- reset_job_id
- run
- run_if_modal
- run_if_scheduler
- transfer_from_remote
- run_if_interactive
- run_if_interactive_non_modal
- interactive_close
- interactive_fetch
- interactive_flush
- send_to_database
- create_job
- update_master
- job_file_name
- to_dict
- from_dict
- from_hdf_args
- save
- convergence_check
- db_entry
- restart
- signal_intercept
- drop_status_to_aborted
- run_if_refresh
- set_input_to_read_only
- run_time_to_db
- pyiron_base.jobs.job.core.JobCore
- content
- files
- job_name
- name
- status
- job_id
- id
- database_entry
- parent_id
- master_id
- child_ids
- project_hdf5
- files_to_compress
- files_to_remove
- relocate_hdf5
- project
- job_info_str
- path
- check_if_job_exists
- show_hdf
- get_from_table
- to_object
- get
- load
- inspect
- is_master_id
- get_job_id
- list_files
- list_childs
- move_to
- rename
- compress
- decompress
- is_compressed
- self_archive
- self_unarchive
- is_self_archived
- pyiron_base.interfaces.has_groups.HasGroups
- list_groups
- list_nodes
- list_all
- pyiron_base.interfaces.object.HasStorage
- storage
- pyiron_base.interfaces.has_hdf.HasHDF
- rewrite_hdf
123def execute_job(pr: Project, 124 material_hardening_input: MaterialHardeningInputDataSet, 125 defect_placement_input: DefectInputDataSet, 126 stress_strain_input: StressStrainInputDataSet, 127 conn: StoreConnection=None): 128 """Execute chain of pyiron jobs the calculate remaining lifetime of wind turbine according to given scenario. 129 130 Args: 131 pr: Initialized pyiron project object 132 material_hardening_input: Parameters for material curing behaviour 133 defect_placement_input: Parameters for component manufactoring defects 134 stress_strain_input: Operational parameters for wind and duration of simulation 135 conn: If valid StoreConnection is passed, result will be saved to specified triple store 136 """ 137 name_hash = "{}_{}_{}".format(material_hardening_input.get_id(),defect_placement_input.get_id(), stress_strain_input.get_id()) 138 139 curing_job = pr.create_job(MaterialSimulation, job_name=("curing_", name_hash), delete_existing_job=True) 140 curing_job.input.material_hardening_input = material_hardening_input 141 curing_job.input.defect_placement_input = defect_placement_input 142 curing_job.input.stress_strain_input = stress_strain_input 143 curing_job.run() 144 145 structure_job = pr.create_job(StructureSimulation, job_name=("struct_", name_hash), delete_existing_job=True) 146 structure_job.input.material_hardening_input = material_hardening_input 147 structure_job.input.defect_placement_input = defect_placement_input 148 structure_job.input.stress_strain_input = stress_strain_input 149 structure_job.input.cpu_cores = 3 150 structure_job.input.ccx_input_files = curing_job.output.ccx_input_files 151 structure_job.run() 152 153 if conn: 154 structure_job.save_simulation_to_ontology(conn)
Execute chain of pyiron jobs the calculate remaining lifetime of wind turbine according to given scenario.
Args: pr: Initialized pyiron project object material_hardening_input: Parameters for material curing behaviour defect_placement_input: Parameters for component manufactoring defects stress_strain_input: Operational parameters for wind and duration of simulation conn: If valid StoreConnection is passed, result will be saved to specified triple store
156def get_pyiron_project(project_path: str) -> Project: 157 """Get pyiron project object to use for simulation jobs. 158 159 Args: 160 project_path: Relative path for pyiron project folder 161 162 Returns: 163 Initialized pyiron project object 164 """ 165 return Project(path=project_path)
Get pyiron project object to use for simulation jobs.
Args: project_path: Relative path for pyiron project folder
Returns: Initialized pyiron project object