Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#307 from zhiminzhang0830/euler_bc
Browse files Browse the repository at this point in the history
update euler beam example
  • Loading branch information
HydrogenSulfate authored May 15, 2023
2 parents 691695f + e25b1cd commit 573cab1
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions examples/euler_beam/euler_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import paddle
import numpy as np

import ppsci
from ppsci.autodiff import hessian
Expand All @@ -22,8 +22,6 @@

if __name__ == "__main__":
args = config.parse_args()
# enable computation for fourth-order differentiation of matmul
paddle.fluid.core.set_prim_eager_enabled(True)
# set random seed for reproducibility
ppsci.utils.misc.set_random_seed(42)
# set training hyper-parameters
Expand Down Expand Up @@ -58,24 +56,49 @@
random="Hammersley",
name="EQ",
)
bc = ppsci.constraint.BoundaryConstraint(
{
"u0": lambda d: d["u"][0:1],
"u__x": lambda d: jacobian(d["u"], d["x"])[1:2],
"u__x__x": lambda d: hessian(d["u"], d["x"])[2:3],
"u__x__x__x": lambda d: jacobian(hessian(d["u"], d["x"]), d["x"])[3:4],
},
{"u0": 0, "u__x": 0, "u__x__x": 0, "u__x__x__x": 0},
bc1 = ppsci.constraint.BoundaryConstraint(
{"u0": lambda d: d["u"]},
{"u0": 0},
geom["interval"],
{**dataloader_cfg, "batch_size": 4},
{**dataloader_cfg, "batch_size": 1},
ppsci.loss.MSELoss("sum"),
evenly=True,
name="BC",
criteria=lambda x: np.isclose(x, 0.0),
name="BC1",
)
bc2 = ppsci.constraint.BoundaryConstraint(
{"u__x": lambda d: jacobian(d["u"], d["x"])},
{"u__x": 0},
geom["interval"],
{**dataloader_cfg, "batch_size": 1},
ppsci.loss.MSELoss("sum"),
criteria=lambda x: np.isclose(x, 0.0),
name="BC2",
)
bc3 = ppsci.constraint.BoundaryConstraint(
{"u__x__x": lambda d: hessian(d["u"], d["x"])},
{"u__x__x": 0},
geom["interval"],
{**dataloader_cfg, "batch_size": 1},
ppsci.loss.MSELoss("sum"),
criteria=lambda x: np.isclose(x, 1.0),
name="BC3",
)
bc4 = ppsci.constraint.BoundaryConstraint(
{"u__x__x__x": lambda d: jacobian(hessian(d["u"], d["x"]), d["x"])},
{"u__x__x__x": 0},
geom["interval"],
{**dataloader_cfg, "batch_size": 1},
ppsci.loss.MSELoss("sum"),
criteria=lambda x: np.isclose(x, 1.0),
name="BC4",
)
# wrap constraints together
constraint = {
pde_constraint.name: pde_constraint,
bc.name: bc,
bc1.name: bc1,
bc2.name: bc2,
bc3.name: bc3,
bc4.name: bc4,
}

# set optimizer
Expand Down

0 comments on commit 573cab1

Please sign in to comment.