Skip to content

Commit 9054c22

Browse files
committed
save all files
1 parent 55a6c79 commit 9054c22

File tree

394 files changed

+27759
-19341
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

394 files changed

+27759
-19341
lines changed

run/meshMotion/cylinderMotion/Allclean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ cd "${0%/*}" || exit # Run from this directory
44
#------------------------------------------------------------------------------
55

66
rm -rf cylinderMotionExperiment
7-
rm -f *.out *.err log*.* *.dat
7+
rm -f *.out *.err log*.* *.log *.dat
88

9-
#------------------------------------------------------------------------------
9+
#------------------------------------------------------------------------------

run/meshMotion/cylinderMotion/Allrun

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ cd "${0%/*}" || exit # Run from this directory
33
. ${WM_PROJECT_DIR:?}/bin/tools/CleanFunctions # Tutorial clean functions
44
#------------------------------------------------------------------------------
55

6+
./Allclean
7+
68
python cylinder-motion.py
79

8-
#------------------------------------------------------------------------------
10+
#------------------------------------------------------------------------------

run/meshMotion/cylinderMotion/cylinder-motion.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ def visualization_points(n_points):
112112

113113
# Make sure all datasets are avaialble in the smartredis database.
114114
local_time_index = 1
115+
learning_rate = 1e-02
116+
optimizer = optim.Adam(model.parameters(), lr=learning_rate)
117+
115118
while True:
116119

117120
print (f"Time step {local_time_index}")
@@ -178,9 +181,9 @@ def visualization_points(n_points):
178181
test_size=0.2, random_state=42)
179182

180183
# PYTORCH Training Loop
181-
optimizer = optim.Adam(model.parameters(), lr=1e-04)
182184
loss_func = nn.MSELoss()
183-
epochs = 10000
185+
epochs = 100000
186+
n_epochs = 0
184187
mean_mag_displ = torch.mean(torch.norm(displ_train, dim=1))
185188
validation_rmse = []
186189
model.train()
@@ -199,12 +202,16 @@ def visualization_points(n_points):
199202
optimizer.step()
200203

201204
# Forward pass on the validation data, with torch.no_grad() for efficiency
205+
n_epochs = n_epochs + 1
202206
with torch.no_grad():
203207
displ_pred_val = model(points_val)
204208
mse_loss_val = loss_func(displ_pred_val, displ_val)
205209
rmse_loss_val = torch.sqrt(mse_loss_val)
206210
validation_rmse.append(rmse_loss_val)
211+
if (rmse_loss_val < 1e-03):
212+
break
207213

214+
print (f"RMSE {validation_rmse[-1]}, number of epochs {n_epochs}")
208215
# Visualize validation RMSE
209216
#plt.loglog()
210217
#plt.title("Validation loss RMSE")
@@ -235,12 +242,12 @@ def visualization_points(n_points):
235242
# Update time index
236243
local_time_index = local_time_index + 1
237244

238-
if client.poll_key("end_time_index", 10, 10):
245+
if client.poll_key("end_time_index", 10, 100):
239246
print ("End time reached.")
240247
break
241248

242249
except Exception as e:
243250
print("Caught an exception: ", str(e))
244251

245252
finally:
246-
exp.stop(db)
253+
exp.stop(db)
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"schema info": {
3+
"schema_name": "entity manifest",
4+
"version": "0.0.4"
5+
},
6+
"experiment": {
7+
"name": "cylinderMotionExperiment",
8+
"path": "/home/jin/OpenFOAM/openfoam-smartsim/run/meshMotion/cylinderMotion/cylinderMotionExperiment",
9+
"launcher": "Local",
10+
"out_file": "/home/jin/OpenFOAM/openfoam-smartsim/run/meshMotion/cylinderMotion/cylinderMotionExperiment/.smartsim/telemetry/logs/smartsim.out",
11+
"err_file": "/home/jin/OpenFOAM/openfoam-smartsim/run/meshMotion/cylinderMotion/cylinderMotionExperiment/.smartsim/telemetry/logs/smartsim.err"
12+
},
13+
"runs": [
14+
{
15+
"run_id": "37755ce",
16+
"timestamp": 1761598029919685939,
17+
"model": [],
18+
"orchestrator": [
19+
{
20+
"name": "orchestrator",
21+
"type": "redis",
22+
"interface": [
23+
"lo"
24+
],
25+
"shards": [
26+
{
27+
"name": "orchestrator_0",
28+
"hostname": "127.0.0.1",
29+
"port": 8000,
30+
"cluster": false,
31+
"conf_file": null,
32+
"out_file": "/home/jin/OpenFOAM/openfoam-smartsim/run/meshMotion/cylinderMotion/cylinderMotionExperiment/.smartsim/telemetry/cylinderMotionExperiment/37755ce/database/orchestrator/orchestrator_0/orchestrator_0.out",
33+
"err_file": "/home/jin/OpenFOAM/openfoam-smartsim/run/meshMotion/cylinderMotion/cylinderMotionExperiment/.smartsim/telemetry/cylinderMotionExperiment/37755ce/database/orchestrator/orchestrator_0/orchestrator_0.err",
34+
"memory_file": "",
35+
"client_file": "",
36+
"client_count_file": "",
37+
"telemetry_metadata": {
38+
"status_dir": "/home/jin/OpenFOAM/openfoam-smartsim/run/meshMotion/cylinderMotion/cylinderMotionExperiment/.smartsim/telemetry/cylinderMotionExperiment/37755ce/database/orchestrator/orchestrator_0",
39+
"step_id": null,
40+
"task_id": "2713",
41+
"managed": false
42+
}
43+
}
44+
]
45+
}
46+
],
47+
"ensemble": []
48+
},
49+
{
50+
"run_id": "566a318",
51+
"timestamp": 1761598030553112680,
52+
"model": [
53+
{
54+
"name": "of_model",
55+
"path": "/home/jin/OpenFOAM/openfoam-smartsim/run/meshMotion/cylinderMotion/cylinderMotionExperiment/of_model",
56+
"exe_args": [
57+
"-case",
58+
"cylinder",
59+
"-parallel"
60+
],
61+
"run_settings": {
62+
"exe": [
63+
"/home/jin/OpenFOAM/OpenFOAM-v2412/platforms/linux64GccDPInt32Opt/bin/moveDynamicMesh"
64+
],
65+
"run_command": "/usr/bin/mpirun",
66+
"run_args": {
67+
"np": "4"
68+
}
69+
},
70+
"batch_settings": {},
71+
"params": {},
72+
"files": {
73+
"Symlink": [],
74+
"Configure": [],
75+
"Copy": []
76+
},
77+
"colocated_db": {},
78+
"telemetry_metadata": {
79+
"status_dir": "/home/jin/OpenFOAM/openfoam-smartsim/run/meshMotion/cylinderMotion/cylinderMotionExperiment/.smartsim/telemetry/cylinderMotionExperiment/566a318/model/of_model",
80+
"step_id": null,
81+
"task_id": "2929",
82+
"managed": false
83+
},
84+
"out_file": "/home/jin/OpenFOAM/openfoam-smartsim/run/meshMotion/cylinderMotion/cylinderMotionExperiment/.smartsim/telemetry/cylinderMotionExperiment/566a318/model/of_model/of_model.out",
85+
"err_file": "/home/jin/OpenFOAM/openfoam-smartsim/run/meshMotion/cylinderMotion/cylinderMotionExperiment/.smartsim/telemetry/cylinderMotionExperiment/566a318/model/of_model/of_model.err"
86+
}
87+
],
88+
"orchestrator": [],
89+
"ensemble": []
90+
}
91+
]
92+
}

run/meshMotion/wingMotion/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ which creates `mesh-motion_MachineLearning`, which has sub-folders for the Smart
2525
Both `Allrun.LaplaceMeshMotion` and `Allrun.MachineLearningMeshMotion` will compute mesh quality metrics (most important ones are non-orthogonality and skewness), and `.foam` files that ParaView needs to recognize OpenFOAM folders. A paraview state file is prepared that compares the decrease in non-orthogonality, visualizing the difference between Laplace non-orthogonality and MLP non-orthogonality, run it as
2626

2727
```
28-
wingMotion> paraview --state=visualize-non-orth-difference.pvsm
28+
wingMotion> paraview --state=diff.pvsm
2929
```
3030

3131
This will show how the Laplace causes an increase of non-orthogonality at the worst possible place - next to the airfoil. The increase is up to 35 degrees, w.r.t a simple MLP.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from torch.optim import Adam, LBFGS, Optimizer
2+
3+
class Adam_LBFGS(Optimizer):
4+
def __init__(self, params, switch_epochs, adam_params, lbfgs_params):
5+
# defaults = dict(switch_epoch=switch_epoch, adam_params=adam_params, lbfgs_params=lbfgs_params)
6+
7+
self.switch_epochs = sorted(switch_epochs)
8+
self.params = list(params)
9+
self.adam = Adam(self.params, **adam_params)
10+
self.lbfgs_params = lbfgs_params
11+
# self.lbfgs = LBFGS(self.params, **lbfgs_params)
12+
13+
super(Adam_LBFGS, self).__init__(self.params, defaults={})
14+
15+
self.state['epoch'] = 0
16+
17+
def step(self, closure=None):
18+
if self.state['epoch'] < self.switch_epochs[0]:
19+
self.adam.step(closure)
20+
else:
21+
# (Re)start LBFGS optimizer
22+
if self.state['epoch'] in self.switch_epochs:
23+
print(f'Starting LBFGS optimizer at epoch {self.state["epoch"]}')
24+
self.lbfgs = LBFGS(self.params, **self.lbfgs_params)
25+
self.lbfgs.step(closure)
26+
27+
self.state['epoch'] += 1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import numpy as np
2+
3+
def annealing_weight(epoch, T_start, T_end, sharpness=10):
4+
5+
if epoch < T_start:
6+
return 0.0
7+
elif epoch > T_end:
8+
return 1.0
9+
else:
10+
# 标准化到 [0,1]
11+
x = (epoch - T_start) / (T_end - T_start)
12+
# S 型函数,中心点在 0.5
13+
return float(1 / (1 + np.exp(-sharpness * (x - 0.5))))

0 commit comments

Comments
 (0)