From 7e49156a2194c14091909b01f9f60b20f01ce227 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Wed, 15 Feb 2023 17:00:21 -0300 Subject: [PATCH] Refactoring due weird definitions --- pestfoamtest/resources/createPatchDict | 51 ++++++ pestfoamtest/resources/fvSchemes | 61 +++++++ pestfoamtest/src/foam.pest | 80 +++++---- pestfoamtest/src/lib.rs | 221 ++++++++++++++----------- 4 files changed, 282 insertions(+), 131 deletions(-) create mode 100644 pestfoamtest/resources/createPatchDict create mode 100644 pestfoamtest/resources/fvSchemes diff --git a/pestfoamtest/resources/createPatchDict b/pestfoamtest/resources/createPatchDict new file mode 100644 index 0000000..97e5c3e --- /dev/null +++ b/pestfoamtest/resources/createPatchDict @@ -0,0 +1,51 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2212 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object createPatchDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +pointSync false; + +patches +( + { + //- Master side patch + name AMI1; + patchInfo + { + type cyclicAMI; + matchTolerance 0.0001; + neighbourPatch AMI2; + transform noOrdering; + } + constructFrom patches; + patches (AMI); + } + + { + //- Slave side patch + name AMI2; + patchInfo + { + type cyclicAMI; + matchTolerance 0.0001; + neighbourPatch AMI1; + transform noOrdering; + } + constructFrom patches; + patches (AMI_slave); + } +); + + +// ************************************************************************* // diff --git a/pestfoamtest/resources/fvSchemes b/pestfoamtest/resources/fvSchemes new file mode 100644 index 0000000..11dff37 --- /dev/null +++ b/pestfoamtest/resources/fvSchemes @@ -0,0 +1,61 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: v2212 | +| \\ / A nd | Website: www.openfoam.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default Euler; +} + +gradSchemes +{ + default Gauss linear; +} + +divSchemes +{ + default none; + + div(phi,U) Gauss linearUpwind grad(U); + div(U) Gauss linear; + + div(phi,k) Gauss linearUpwind grad(U); + div(phi,omega) Gauss linearUpwind grad(U); + + div((nuEff*dev2(T(grad(U))))) Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear corrected; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default corrected; +} + +wallDist +{ + method meshWave; +} + + +// ************************************************************************* // diff --git a/pestfoamtest/src/foam.pest b/pestfoamtest/src/foam.pest index fa8afb4..513e2d0 100644 --- a/pestfoamtest/src/foam.pest +++ b/pestfoamtest/src/foam.pest @@ -1,37 +1,49 @@ whitespace = _{ " " | "\t" | "\r" | "\n" } +letters = _{ 'a'..'z' | 'A'..'Z' } +numbers = _{ '0'..'9' } +special_chars = _{ "_" | "(" | ")" | "." | "*" } + multi_comment = { "/*" ~ (!"*/" ~ ANY)* ~ "*/" } single_comment = { "//" ~ (!NEWLINE ~ ANY)* } -identifier = { ASCII_ALPHA+ ~ (ASCII_ALPHA | ASCII_DIGIT | "_")* } -rvalue = { ('a'..'z' | 'A'..'Z' | '0'..'9' | "_" | "." | "-")+ } -middle = { (whitespace | multi_comment)+ } - -include = { "#" ~ identifier ~ middle ~ "\"" ~ identifier ~ "\"" } -attribution = { identifier ~ middle ~ rvalue ~ ";" } -dictionary = { identifier ~ middle ~ "{" ~ ( - dictionary - | list - | attribution - | whitespace - | multi_comment - | single_comment - | include - )+ ~ "}" } -list_size = _{ ASCII_DIGIT+ ~ whitespace+ } -list_middle = { "(" ~ ( - dictionary - | rvalue - | list_middle - | whitespace - | multi_comment - | single_comment - )+ ~ ")" } -list = { identifier ~ middle ~ list_size? ~ list_middle ~ ";" } - -file = { SOI ~ ( - whitespace - | multi_comment - | single_comment - | dictionary - | list - | attribution)* - ~ EOI } + +in_between = { (whitespace | multi_comment)+ } + +definition = { letters ~ (letters | numbers | special_chars)+ } +value = { (letters | numbers | special_chars)+ } + +attribution = { definition ~ in_between+ ~ value ~ (in_between+ ~ value)* ~ ";" } + + +/* identifier = { letters+ ~ (!whitespace ~ (letters | numbers | "_" | "(" | ")" | "," | "*"))* } */ +/* rvalue = { ('a'..'z' | 'A'..'Z' | '0'..'9' | "_" | "." | "-" | "(" | ")")+ } */ + +/* include = { "#" ~ identifier ~ in_between ~ "\"" ~ identifier ~ "\"" } */ +/* attribution = { identifier ~ (in_between ~ rvalue)+ ~ ";" } */ +/* dictionary = { identifier ~ in_between ~ "{" ~ ( */ +/* dictionary */ +/* | list */ +/* | attribution */ +/* | whitespace */ +/* | multi_comment */ +/* | single_comment */ +/* | include */ +/* )+ ~ "}" } */ +/* list_size = _{ ASCII_DIGIT+ ~ whitespace+ } */ +/* list_middle = { "(" ~ ( */ +/* dictionary */ +/* | rvalue */ +/* | list_middle */ +/* | whitespace */ +/* | multi_comment */ +/* | single_comment */ +/* )+ ~ ")" } */ +/* list = { identifier ~ in_between ~ list_size? ~ list_middle ~ ";" } */ + +/* file = { SOI ~ ( */ +/* whitespace */ +/* | multi_comment */ +/* | single_comment */ +/* | dictionary */ +/* | list */ +/* | attribution)* */ +/* ~ EOI } */ diff --git a/pestfoamtest/src/lib.rs b/pestfoamtest/src/lib.rs index 0787445..0c9d534 100644 --- a/pestfoamtest/src/lib.rs +++ b/pestfoamtest/src/lib.rs @@ -22,122 +22,149 @@ mod parser { } #[test] - fn broken_multi() { - let parse = FoamParser::parse(Rule::multi_comment, "/* bad comment"); - assert!(parse.is_err()); - } - - #[test] - fn single_comment() { - let parse = FoamParser::parse(Rule::single_comment, "// this is comment"); - assert!(parse.is_ok()); - } - - #[test] - fn identifier() { - let parse = FoamParser::parse(Rule::identifier, "FoamFile"); - assert!(parse.is_ok()); - let parse = FoamParser::parse(Rule::identifier, "foam_file"); + fn definition() { + let parse = FoamParser::parse(Rule::definition, "foamFile"); + assert!(parse.is_ok(), "{:#?}", parse); + let parse = FoamParser::parse(Rule::definition, "div(phi,U)"); + assert!(parse.is_ok(), "{:#?}", parse); + let parse = FoamParser::parse(Rule::definition, "div((nuEff*dev2(T(grad(U)))))"); + assert!(parse.is_ok(), "{:#?}", parse); + let parse = FoamParser::parse(Rule::definition, "FoamFile"); + assert!(parse.is_ok(), "{:#?}", parse); + let parse = FoamParser::parse(Rule::definition, "foam_file"); assert!(parse.is_ok()); } - #[test] - fn broken_identifer() { - let parse = FoamParser::parse(Rule::identifier, "123"); - assert!(parse.is_err()); - - let parse = FoamParser::parse(Rule::identifier, "asd "); - assert!(parse.is_ok(), "{:?}", parse); - // XXX check if the identifier lost its space. - } - #[test] fn attribution() { let parse = FoamParser::parse(Rule::attribution, "version 2.0;"); - assert!(parse.is_ok(), "{:?}", parse); - } - - #[test] - fn broken_attribution() { - let parse = FoamParser::parse(Rule::attribution, "version 2.0"); - assert!(parse.is_err(), "{:?}", parse); - } - - #[test] - fn dictionary() { - let text = "FoamFile\n{\nversion 2.0;\nformat ascii;\nclass dictionary;\nlocation system;\nobject caseSetupDict;\n}"; - let parse = FoamParser::parse(Rule::dictionary, text); assert!(parse.is_ok(), "{:#?}", parse); - } - - #[test] - fn dict_in_dict() { - let text = "dict1 { dict2 { class bad; } }"; - let parse = FoamParser::parse(Rule::dictionary, text); + let parse = FoamParser::parse(Rule::attribution, "div(U) Gauss linear;"); assert!(parse.is_ok(), "{:#?}", parse); } #[test] - fn list() { - let text = "list_name ( 1 2 3 );"; - let parse = FoamParser::parse(Rule::list, text); - assert!(parse.is_ok(), "{:#?}", parse); - } - - #[test] - fn sized_list() { - let text = "list_name 3 ( 1 2 3 );"; - let parse = FoamParser::parse(Rule::list, text); - assert!(parse.is_ok(), "{:#?}", parse); - } -} - -#[cfg(test)] -mod file { - use super::*; - use pest::Parser; - - #[test] - fn chained_comments() { - let text = "/* this is one comment */\n// And this is another"; - let parse = FoamParser::parse(Rule::file, text); - assert!(parse.is_ok(), "{:?}", parse); - } - - #[test] - fn attribution_with_comment() { - let text = "version 2.0; // this is good"; - let parse = FoamParser::parse(Rule::file, text); - assert!(parse.is_ok(), "{:?}", parse); + fn broken_multi() { + let parse = FoamParser::parse(Rule::multi_comment, "/* bad comment"); + assert!(parse.is_err()); } #[test] - fn mid_comment() { - let text = "version /* this is comment */ 2.0;"; - let parse = FoamParser::parse(Rule::file, text); - assert!(parse.is_ok(), "{:?}", parse); + fn single_comment() { + let parse = FoamParser::parse(Rule::single_comment, "// this is comment"); + assert!(parse.is_ok()); } #[test] - fn complex() { - let text = "/* this is file */\nList ( 1\n2 // this is ok\n 3);"; - let parse = FoamParser::parse(Rule::file, text); - assert!(parse.is_ok(), "{:?}", parse); - } + fn broken_identifer() { + let parse = FoamParser::parse(Rule::value, "123"); + assert!(parse.is_err(), "{:#?}", parse); - // Note: the following files were retrieved from OpenFoam examples: - // https://develop.openfoam.com/Development/openfoam/-/tree/develop/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system - #[test] - fn control_dict() { - let text = include_bytes!("../resources/controlDict"); - let parse = FoamParser::parse(Rule::file, &std::str::from_utf8(text).unwrap()); + let parse = FoamParser::parse(Rule::value, "asd "); assert!(parse.is_ok(), "{:?}", parse); } - #[test] - fn block_mesh_dict() { - let text = include_bytes!("../resources/blockMeshDict"); - let parse = FoamParser::parse(Rule::file, &std::str::from_utf8(text).unwrap()); - assert!(parse.is_ok(), "{:?}", parse); - } + // #[test] + // fn attribution() { + // let parse = FoamParser::parse(Rule::attribution, "version 2.0;"); + // assert!(parse.is_ok(), "{:?}", parse); + // } + + // #[test] + // fn broken_attribution() { + // let parse = FoamParser::parse(Rule::attribution, "version 2.0"); + // assert!(parse.is_err(), "{:?}", parse); + // } + + // #[test] + // fn dictionary() { + // let text = "FoamFile\n{\nversion 2.0;\nformat ascii;\nclass dictionary;\nlocation system;\nobject caseSetupDict;\n}"; + // let parse = FoamParser::parse(Rule::dictionary, text); + // assert!(parse.is_ok(), "{:#?}", parse); + // } + + // #[test] + // fn dict_in_dict() { + // let text = "dict1 { dict2 { class bad; } }"; + // let parse = FoamParser::parse(Rule::dictionary, text); + // assert!(parse.is_ok(), "{:#?}", parse); + // } + + // #[test] + // fn list() { + // let text = "list_name ( 1 2 3 );"; + // let parse = FoamParser::parse(Rule::list, text); + // assert!(parse.is_ok(), "{:#?}", parse); + // } + + // #[test] + // fn sized_list() { + // let text = "list_name 3 ( 1 2 3 );"; + // let parse = FoamParser::parse(Rule::list, text); + // assert!(parse.is_ok(), "{:#?}", parse); + // } } + +// #[cfg(test)] +// mod file { +// use super::*; +// use pest::Parser; + +// #[test] +// fn chained_comments() { +// let text = "/* this is one comment */\n// And this is another"; +// let parse = FoamParser::parse(Rule::file, text); +// assert!(parse.is_ok(), "{:?}", parse); +// } + +// #[test] +// fn attribution_with_comment() { +// let text = "version 2.0; // this is good"; +// let parse = FoamParser::parse(Rule::file, text); +// assert!(parse.is_ok(), "{:?}", parse); +// } + +// #[test] +// fn mid_comment() { +// let text = "version /* this is comment */ 2.0;"; +// let parse = FoamParser::parse(Rule::file, text); +// assert!(parse.is_ok(), "{:?}", parse); +// } + +// #[test] +// fn complex() { +// let text = "/* this is file */\nList ( 1\n2 // this is ok\n 3);"; +// let parse = FoamParser::parse(Rule::file, text); +// assert!(parse.is_ok(), "{:?}", parse); +// } + +// // Note: the following files were retrieved from OpenFoam examples: +// // https://develop.openfoam.com/Development/openfoam/-/tree/develop/tutorials/incompressible/pimpleFoam/RAS/rotatingFanInRoom/system +// #[test] +// fn control_dict() { +// let text = include_bytes!("../resources/controlDict"); +// let parse = FoamParser::parse(Rule::file, &std::str::from_utf8(text).unwrap()); +// assert!(parse.is_ok(), "{:?}", parse); +// } + +// #[test] +// fn block_mesh_dict() { +// let text = include_bytes!("../resources/blockMeshDict"); +// let parse = FoamParser::parse(Rule::file, &std::str::from_utf8(text).unwrap()); +// assert!(parse.is_ok(), "{:?}", parse); +// } + +// // #[test] +// // fn create_patch_dict() { +// // let text = include_bytes!("../resources/createPatchDict"); +// // let parse = FoamParser::parse(Rule::file, &std::str::from_utf8(text).unwrap()); +// // assert!(parse.is_ok(), "{:?}", parse); +// // } + +// #[test] +// fn fv_scheme() { +// let text = include_bytes!("../resources/fvSchemes"); +// let parse = FoamParser::parse(Rule::file, &std::str::from_utf8(text).unwrap()); +// assert!(parse.is_ok(), "{:?}", parse); +// } +// }