Fri 16 May 23:06:54 CEST 2025

This commit is contained in:
sbosse 2025-05-16 23:08:50 +02:00
parent eab3d82653
commit 3e6dc85208

View File

@ -24,7 +24,7 @@ from SimNDT.core.materialLibrary import getMaterialLibrary
def read_scenario(sim_params, SimNDT_geom_objects, SimNDT_Bc_objs): def read_scenario(sim_params, SimNDT_geom_objects, SimNDT_Bc_objs, SimNDT_Mat_objs):
""" """
Reads and sets up the scenario based on the provided simulation parameters, geometric objects, and boundary conditions. Reads and sets up the scenario based on the provided simulation parameters, geometric objects, and boundary conditions.
@ -71,9 +71,9 @@ def read_geometry_objects(sim_params):
""" """
# geometric objects # geometric objects
# geometric objects # geometric objects
SimNDT_geom_objects = []
if "GeometricObjects" in sim_params.keys(): if "GeometricObjects" in sim_params.keys():
print("Showing {} GeometricObjects.".format(len(sim_params["GeometricObjects"]))) print("Showing {} GeometricObjects.".format(len(sim_params["GeometricObjects"])))
SimNDT_geom_objects = []
for geom_num in range(len(sim_params["GeometricObjects"])): for geom_num in range(len(sim_params["GeometricObjects"])):
geom_name = sim_params["GeometricObjects"][geom_num]["Name"] geom_name = sim_params["GeometricObjects"][geom_num]["Name"]
@ -126,7 +126,7 @@ def read_geometry_objects(sim_params):
print("Finished reading GeometricObjects.") print("Finished reading GeometricObjects.")
# print(repr(SimNDT_geom_objects)) # print(repr(SimNDT_geom_objects))
# print("\n") # print("\n")
return SimNDT_geom_objects return SimNDT_geom_objects
def read_materials(sim_params,Library): def read_materials(sim_params,Library):
""" """
@ -138,7 +138,7 @@ def read_materials(sim_params,Library):
Returns: Returns:
- SimNDT_Mat_objs: List of material objects. - SimNDT_Mat_objs: List of material objects.
""" """
# reading materials ######### # reading materials #########
if "Materials" in sim_params.keys(): if "Materials" in sim_params.keys():
print("Showing {} Materials.".format(len(sim_params["Materials"]))) print("Showing {} Materials.".format(len(sim_params["Materials"])))
SimNDT_Mat_objs = [] SimNDT_Mat_objs = []
@ -608,7 +608,35 @@ def checkSimulation(Scenario, Materials, Boundaries, Transducers, Inspection, Si
# If no valueerror is raised, then the simulation is ready to run # If no valueerror is raised, then the simulation is ready to run
print("Simulation is ready to run!!!") print("Simulation is ready to run!!!")
def enableSnapshot(sim_params): def read_import(sim_params,SimNDT_Scenario,SimNDT_Simulation):
print("Searching Import section...")
importIm = 0
importIabs = 0
importI = 0
if "Import" in sim_params.keys():
print("Found Import section.")
if "I" in sim_params["Import"].keys():
importI = sim_params["Import"]["I"]
if "Iabs" in sim_params["Import"].keys():
importIabs = sim_params["Import"]["Iabs"]
if "Im" in sim_params["Import"].keys():
importIm = sim_params["Import"]["Im"]
if "Rho" in sim_params["Import"].keys():
# must be imported later by the efit2d engine ...
SimNDT_Simulation.importRho = sim_params["Import"]["Rho"]
if "VT" in sim_params["Import"].keys():
# must be imported later by the efit2d engine ...
SimNDT_Simulation.importVT = sim_params["Import"]["VT"]
if "VL" in sim_params["Import"].keys():
# must be imported later by the efit2d engine ...
SimNDT_Simulation.importVL = sim_params["Import"]["VL"]
if importIm:
print("Reading Im from "+importIm)
importIm = np.load(importIm)
print (np.shape(importIm))
SimNDT_Simulation.update_numericalModel(SimNDT_Scenario,importIm,0)
def read_export(sim_params):
""" """
Enables and sets up snapshots for the simulation, including properties like step size, file path, and fields to save. Enables and sets up snapshots for the simulation, including properties like step size, file path, and fields to save.
@ -618,25 +646,69 @@ def enableSnapshot(sim_params):
Returns: Returns:
- SimNDT_SnapShots: The snapshots object. - SimNDT_SnapShots: The snapshots object.
""" """
print("Searching Export (Snapshot) section...")
if "Snapshot" in sim_params.keys(): if "Snapshot" in sim_params.keys():
step = sim_params["Snapshot"]["Step"] sim_params["Export"]["Export"] = sim_params["Export"]["Snapshot"]
save_filepath = sim_params["Snapshot"]["Save_filepath"] if "Export" in sim_params.keys():
filename = sim_params["Snapshot"]["Filename"] print("Found Export section.")
enableFields = sim_params["Snapshot"]["enableFields"] step = sim_params["Export"]["Step"]
enableNumPy = sim_params["Snapshot"]["enableNumPy"] save_filepath = sim_params["Export"]["Save_filepath"]
extension = sim_params["Snapshot"]["Extension"] filename = sim_params["Export"]["Filename"]
db = sim_params["Snapshot"]["dB"] if "enableFields" in sim_params["Export"].keys():
color = sim_params["Snapshot"]["Color"] enableFields = sim_params["Export"]["enableFields"]
field = sim_params["Snapshot"]["Field"] else:
enableSignals = sim_params["Snapshot"]["enableSignals"] enableFields = False
enableImages = sim_params["Snapshot"]["enableImages"] if "enableNumPy" in sim_params["Export"].keys():
enableVolume = sim_params["Snapshot"]["enableVolume"] enableNumPy = sim_params["Export"]["enableNumPy"]
enableView = sim_params["Snapshot"]["enableView"] else:
sensorShape = sim_params["Snapshot"]["sensorShape"] enableNumPy = True
sensorPlacement = sim_params["Snapshot"]["sensorPlacement"] extension = sim_params["Export"]["Extension"]
sensorSize = sim_params["Snapshot"]["sensorSize"] if "dB" in sim_params["Export"].keys():
db = sim_params["Export"]["dB"]
print("Steps for Snapshots="+str(step)) else:
db = 50
if "Color" in sim_params["Export"].keys():
color = sim_params["Export"]["Color"]
else:
color = 0
field = sim_params["Export"]["Field"]
if "Material" in sim_params["Export"].keys():
material = sim_params["Export"]["Material"]
else:
material = 0
if "enableSignals" in sim_params["Export"].keys():
enableSignals = sim_params["Export"]["enableSignals"]
else:
enableSignals = False
if "enableImages" in sim_params["Export"].keys():
enableImages = sim_params["Export"]["enableImages"]
else:
enableImages = False
if "enableMaterial" in sim_params["Export"].keys():
enableMaterial = sim_params["Export"]["enableMaterial"]
else:
enableMaterial = False
if "enableVolume" in sim_params["Export"].keys():
enableVolume = sim_params["Export"]["enableVolume"]
else:
enableVolume = False
if "enableView" in sim_params["Export"].keys():
enableView = sim_params["Export"]["enableView"]
else:
enableView = False
if "sensorShape" in sim_params["Export"].keys():
sensorShape = sim_params["Export"]["sensorShape"]
else:
sensorShape = []
if "sensorPlacement" in sim_params["Export"].keys():
sensorPlacement = sim_params["Export"]["sensorPlacement"]
else:
sensorPlacement = []
if "sensorSize" in sim_params["Export"].keys():
sensorSize = sim_params["Export"]["sensorSize"]
else:
sensorSize = 0
print("Steps for Export="+str(step))
# RunSimulation(self.filename, self.SimNDT_Simulation) # RunSimulation(self.filename, self.SimNDT_Simulation)
SimNDT_SnapShots = SnapShots( SimNDT_SnapShots = SnapShots(
Enable=True, Enable=True,
@ -649,8 +721,10 @@ def enableSnapshot(sim_params):
dB=db, dB=db,
Color=color, Color=color,
Field=field, Field=field,
Material=material,
enableSignals=enableSignals, enableSignals=enableSignals,
enableImages=enableImages, enableImages=enableImages,
enableMaterial=enableMaterial,
enableVolume=enableVolume, enableVolume=enableVolume,
enableView=enableView, enableView=enableView,
sensorShape=sensorShape, sensorShape=sensorShape,
@ -658,6 +732,8 @@ def enableSnapshot(sim_params):
sensorSize=sensorSize sensorSize=sensorSize
) )
return SimNDT_SnapShots return SimNDT_SnapShots
else:
print ("No Export/Snapshot section found. Fatal.")
def openSim(sim_params): def openSim(sim_params):
@ -699,7 +775,7 @@ def openSim(sim_params):
SimNDT_geom_objects = read_geometry_objects(sim_params) SimNDT_geom_objects = read_geometry_objects(sim_params)
SimNDT_Mat_objs = read_materials(sim_params,SimNDT_Library) SimNDT_Mat_objs = read_materials(sim_params,SimNDT_Library)
SimNDT_Bc_objs = read_boundaries(sim_params) SimNDT_Bc_objs = read_boundaries(sim_params)
SimNDT_Scenario = read_scenario(sim_params, SimNDT_geom_objects, SimNDT_Bc_objs) SimNDT_Scenario = read_scenario(sim_params, SimNDT_geom_objects, SimNDT_Bc_objs, SimNDT_Mat_objs)
SimNDT_Source = read_source(sim_params) SimNDT_Source = read_source(sim_params)
SimNDT_Signal = read_signal(sim_params) SimNDT_Signal = read_signal(sim_params)
@ -713,6 +789,7 @@ def openSim(sim_params):
SingleLaunchSetup(SimNDT_Scenario, SimNDT_Source, SimNDT_Inspection, SimNDT_Transd_objs, SimNDT_Signal) SingleLaunchSetup(SimNDT_Scenario, SimNDT_Source, SimNDT_Inspection, SimNDT_Transd_objs, SimNDT_Signal)
SimNDT_Simulation = read_simulation(sim_params) SimNDT_Simulation = read_simulation(sim_params)
# sets up simulation env # sets up simulation env
SimulationSetup(SimNDT_Scenario, SimNDT_Mat_objs, SimNDT_Transd_objs, SimNDT_Simulation) SimulationSetup(SimNDT_Scenario, SimNDT_Mat_objs, SimNDT_Transd_objs, SimNDT_Simulation)
# checking labels, setting inspection and fixing boundary if necessary # checking labels, setting inspection and fixing boundary if necessary
@ -721,7 +798,9 @@ def openSim(sim_params):
SimNDT_Receivers = read_receivers(sim_params) SimNDT_Receivers = read_receivers(sim_params)
SimNDT_SnapShots = enableSnapshot(sim_params) read_import(sim_params,SimNDT_Scenario,SimNDT_Simulation)
SimNDT_SnapShots = read_export(sim_params)
print("steps: ", SimNDT_SnapShots.Step) print("steps: ", SimNDT_SnapShots.Step)
print("Finished reading all parameters.") print("Finished reading all parameters.")
@ -729,7 +808,7 @@ def openSim(sim_params):
simPack = SimPack(SimNDT_Scenario, SimNDT_Mat_objs, \ simPack = SimPack(SimNDT_Scenario, SimNDT_Mat_objs, \
SimNDT_Bc_objs, SimNDT_Inspection, SimNDT_Source, \ SimNDT_Bc_objs, SimNDT_Inspection, SimNDT_Source, \
SimNDT_Transd_objs, SimNDT_Signal, SimNDT_Simulation, \ SimNDT_Transd_objs, SimNDT_Signal, SimNDT_Simulation, \
SimNDT_geom_objects, SimNDT_Receivers, SimNDT_SnapShots, SimNDT_Library) SimNDT_geom_objects, SimNDT_Receivers, SimNDT_SnapShots, SimNDT_Library)
return simPack return simPack
@ -754,11 +833,9 @@ def runEngine(simPack):
- SimNDT_SnapShots: The snapshots object. - SimNDT_SnapShots: The snapshots object.
""" """
engine = EngineController(simPack, simPack.SnapShots) engine = EngineController(simPack, simPack.SnapShots)
simPack.SimNDT_Engine = engine
state = engine.run() state = engine.run()