Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions examples/temperature_final_part/input.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
steps:
- macroadditivefoam:
class: temperature_final_part
application: additivefoam
execute:
coarse: 0.5e-3
pad-xy: 5e-3
pad-sub: 12.7e-3
np: 24
n-cells-per-layer: 1
layer-time: 5
data:
build:
datatype: Peregrine
name: myna_output
path: ..
parts:
P5:
layers: [51, 52]
38 changes: 31 additions & 7 deletions src/myna/application/additivefoam/additivefoam.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def __init__(
help="Multiple by which to scale the STL file dimensions (default = 0.001, mm -> m)",
)

self.args = self.parser.parse_args()
self.args, _ = self.parser.parse_known_args()

super().set_procs()
super().check_exe(
Expand All @@ -100,6 +100,7 @@ def __init__(

def update_template_path(self):
"""Updates the template path parameter"""
print(self.args.template)
if self.args.template is None:
template_path = os.path.join(
os.environ["MYNA_APP_PATH"],
Expand All @@ -108,6 +109,7 @@ def update_template_path(self):
"template",
)
self.args.template = template_path
print(self.args.template)

def copy_template_to_dir(self, target_dir):
"""Copies the specified template directory to the specified target directory"""
Expand Down Expand Up @@ -182,6 +184,21 @@ def update_material_properties(self, case_dir):
+ f' -set "{absorption}" {case_dir}/constant/heatSourceDict'
)

def get_part_resource_template_dir(self, part):
"""Provides the path to the template directory in the myna_resources folder

Args:
part: The name of the part
"""
return os.path.join(
os.path.dirname(self.input_file),
"myna_resources",
part,
"additivefoam",
self.simulation_type,
"template",
)

def get_region_resource_template_dir(self, part, region):
"""Provides the path to the template directory in the myna_resources folder

Expand Down Expand Up @@ -311,7 +328,7 @@ def update_region_start_and_end_times(self, case_dir, bb_dict, scanpath_name):
end_time = np.round(end_time, 5)
self.update_start_and_end_times(case_dir, start_time, end_time)

def update_start_and_end_times(self, case_dir, start_time, end_time):
def update_start_and_end_times(self, case_dir, start_time, end_time, n_write=2):
"""Updates the case to adjust the start and end time by adjusting:"

- start and end times of the simulation in system/controlDict
Expand All @@ -322,6 +339,7 @@ def update_start_and_end_times(self, case_dir, start_time, end_time):
case_dir: case directory to update
start_time: start time of the simulation
end_time: end time of the simulation
n_write: number of times to write output (must be > 0)
"""
os.system(
f"foamDictionary -entry startTime -set {start_time} "
Expand All @@ -332,14 +350,20 @@ def update_start_and_end_times(self, case_dir, start_time, end_time):
+ f"{case_dir}/system/controlDict"
)
os.system(
f"foamDictionary -entry writeInterval -set {np.round(0.5 * (end_time - start_time), 5)} "
f"foamDictionary -entry writeInterval -set {np.round((1 / n_write) * (end_time - start_time), 8)} "
+ f"{case_dir}/system/controlDict"
)
source = os.path.abspath(os.path.join(case_dir, "0"))
target = os.path.abspath(os.path.join(case_dir, f"{start_time}"))
if os.path.exists(target):
shutil.rmtree(target)
shutil.move(source, target)
target = os.path.abspath(
os.path.join(
case_dir,
f"{int(start_time) if float(start_time).is_integer() else start_time}",
)
)
if target != source:
if os.path.exists(target):
shutil.rmtree(target)
shutil.move(source, target)

def update_heatsource_scanfile(self, case_dir, scanpath_name):
"""Updates the heatSourceDict to point to the specified scan path file
Expand Down
89 changes: 65 additions & 24 deletions src/myna/application/additivefoam/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,75 @@
# License: 3-clause BSD, see https://opensource.org/licenses/BSD-3-Clause.
#
import pandas as pd
import polars as pl


def convert_peregrine_scanpath(filename, export_path, power=1):
"""converts peregrine scan path units to additivefoam scan path units"""
df = pd.read_csv(filename, sep="\s+")
def convert_peregrine_scanpath(input_file, output_file, power=1):
"""Convert Myna scan path to an AdditiveFOAM-compatible scan path

# convert X & Y distances to meters
df["X(m)"] = df["X(mm)"] * 1e-3
df["Y(m)"] = df["Y(mm)"] * 1e-3
Args:
input_file: Myna scan path
output_file: AdditiveFOAM scan path to write
power: nominal power of the laser (default 1 makes equivalent to Myna "Pmod")
"""

# set Z value to zero
df["Z(m)"] = df["Z(mm)"] * 0
data = pl.read_csv(input_file, separator="\t")
data = data.rename(
{
"X(mm)": "X(mm)",
"Y(mm)": "Y(mm)",
"Z(mm)": "Z(mm)",
"Pmod": "Pmod",
"tParam": "tParam",
}
)
data = data.with_columns(
[
(pl.col("X(mm)") / 1000.0).alias("X(m)"), # Convert to meters
(pl.col("Y(mm)") / 1000.0).alias("Y(m)"), # Convert to meters
pl.lit(0.0).alias("Z(m)"), # Set Z to zero
(pl.col("Pmod") * power).alias("Power"), # Convert to Watts
]
).rename(
{"tParam": "Parameter"}
) # Rename to Parameter
data = data.select(["Mode", "X(m)", "Y(m)", "Z(m)", "Power", "Parameter"])
data.write_csv(output_file, separator="\t")

# format columns
round_cols = ["X(m)", "Y(m)", "Z(m)"]
df[round_cols] = df[round_cols].round(6)
for col in round_cols:
df[col] = df[col].map(
lambda x: f'{str(x).ljust(7+len(str(x).split(".")[0]),"0")}'
)

# set the laser power
df["Power(W)"] = df["Pmod"] * power
def get_scanpath_bounding_box(scanpath, file_format="myna"):
"""Returns the bounding box for given scanpath file(s) in meters

# write the converted path to a new file
df.to_csv(
export_path,
columns=["Mode", "X(m)", "Y(m)", "Z(m)", "Power(W)", "tParam"],
sep="\t",
index=False,
)
Args:
scanpath: file or list of files of scanpaths to find the bounding box
format: the format of the scanpath file ("myna" or "additivefoam")

Returns:
[[minx, miny, minz],[maxx, maxy, maxz]]
"""
if not isinstance(scanpath, list) and isinstance(scanpath, str):
scanpath = [scanpath]

xmin, ymin, zmin = [1e10] * 3
xmax, ymax, zmax = [-1e10] * 3

if file_format.lower() == "myna":
xcol, ycol, zcol = ["X(mm)", "Y(mm)", "Z(mm)"]
scale = 1e-3
elif file_format.lower() == "additivefoam":
xcol, ycol, zcol = ["X(m)", "Y(m)", "Z(m)"]
scale = 1

else:
assert file_format.lower() in ["myna", "additivefoam"]

for f in scanpath:
df = pd.read_csv(f, sep="\t")
xmin = min(xmin, df[xcol].min() * scale)
xmax = max(xmax, df[xcol].max() * scale)
ymin = min(ymin, df[ycol].min() * scale)
ymax = max(ymax, df[ycol].max() * scale)
zmin = min(zmin, df[zcol].min() * scale)
zmax = max(zmax, df[zcol].max() * scale)

return [[xmin, ymin, zmin], [xmax, ymax, zmax]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*---------------------------------------------------------------------------
AdditiveFOAM template input file (compatible with 1.0, OpenFOAM 10)

Created for simulation with Myna
---------------------------------------------------------------------------*/

ExaCA
{
type ExaCA;
libs ("libExaCAFunctionObject.so");

box ( 0.0495 -0.0495 -0.0003 ) ( 0.0505 -0.0485 0 );
dx 2.5e-6;
isoValue 1730;
}

// ************************************************************************* //
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,18 @@ timeFormat general;

timePrecision 8;

runTimeModifiable yes;
runTimeModifiable no;

adjustTimeStep yes;

maxCo 0.5;
maxFo 50;
maxAlphaCo 0.5;

maxDi 100;

maxAlphaCo 1;

functions
{
#includeFunc ExaCA
}
// ************************************************************************* //
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ divSchemes

laplacianSchemes
{
default Gauss linear corrected;
default Gauss linear corrected;
laplacian(kappa,T) Gauss harmonic corrected;
}

interpolationSchemes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*---------------------------------------------------------------------------
AdditiveFOAM template input file (compatible with 1.0, OpenFOAM 10)

Created for simulation with Myna
---------------------------------------------------------------------------*/

ExaCA
{
type ExaCA;
libs ("libExaCAFunctionObject.so");

box ( 0.172 0.072 -0.0003 ) ( 0.173 0.073 0 );
dx 2.5e-6;
isoValue 1730;
}


// ************************************************************************* //
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ runTimeModifiable yes;
adjustTimeStep yes;

maxCo 0.5;
maxFo 50;
maxAlphaCo 0.5;

maxDi 100;

maxAlphaCo 1;

functions
{
#includeFunc ExaCA
}
// ************************************************************************* //
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ divSchemes

laplacianSchemes
{
default Gauss linear corrected;
default Gauss linear corrected;
laplacian(kappa,T) Gauss harmonic corrected;
}

interpolationSchemes
Expand Down
Loading
Loading