How to Calculate the Lift Force, Lift Coefficient and Drag Coefficient with Ansys Pyfluent?
I'm following the code linked here which simulates the aerodynamics of an ahmed body. There's specifically a section where it calculates the drag force right here: session.tui.solve.report_definitions.add( "cd-mon1", "drag", "thread-names", "*ahmed*", "()", "scaled?", "yes", "force-vector", "1 0 0", "q", )
After this code is ran, it prints this in the terminal:<solver_session>.solution.report_definitions.drag["cd-mon1"] = {} solver.solution.report_definitions.drag['cd-mon1'] = {"zones" : ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear"]}
But I want to get more than that information, like lift and the coefficients. I added my own code to calculate the lift force here:session.tui.solve.report_definitions.add( "cl-mon1", "force", "thread-names", "*ahmed*", "()", "scaled?", "yes", "force-vector", "0 1 0", # Lift force is along the y-direction "q", )
When this line is run, the program completely freezes and I have no idea why. I think it might have something to do with the solver settings, because each specific "zone" is defined from what I can tell from the terminal, but it never specifically says in the code that the cd-mon1 is defined to "wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear" (at least from what I can tell). All in all, I'm having trouble calculating the other forces.
Best Answer
-
I recommend creating an issue in GitHub so that it can be properly assessed by the development team. Note that you can generate many appropriate PyFluent solver calls by running TUI commands while recording a Python journal. That can help to improve your PyFluent calls.
0
Answers
-
I've used a Python Journal to generate code doing the same functions, and I'm now getting different results. Luckily, it's actually giving back an error for us to dissect. Here's the newly generated code with the journal:
solver.tui.define.parameters.output_parameters.create('force', 'cd-mon1', 'force', 'wall_ahmed_body_main', 'wall_ahmed_body_rear', 'wall_ahmed_body_front', 'wheels', '()', '1', '0', '0') solver.tui.define.parameters.output_parameters.create('force', 'cl-mon1', 'force', 'wall_ahmed_body_front', 'wall_ahmed_body_rear', 'wall_ahmed_body_main', 'wheels', '()', '0', '1', '0') solver.parameters.output_parameters.report_definitions['parameter-1'] = {"report_definition" : "cd-mon1"} solver.parameters.output_parameters.report_definitions['parameter-2'] = {"report_definition" : "cl-mon1"} solver.solution.report_definitions.drag['cd-mon1'] = {"zones" : ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear", "wheels"]} solver.solution.report_definitions.lift['cl-mon1'] = {"zones" : ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear", "wheels"]}
Like what happened earlier, the error happens the second I try to calculate the lift on the last line of this code. But interestingly, if I make the lift code run before the drag code, then the error happens at the drag code. This seems to imply that the error is happening because they're both being calculated at the same time. But what's even more interesting is what error it spits out:
`Exception has occurred: RuntimeError
api-create-obj: object with same name exists
Error Object: cl-mon1
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNKNOWN details = "api-create-obj: object with same name exists Error Object: cl-mon1" debug_error_string = "UNKNOWN:Error received from peer {grpc_message:"api-create-obj: object with same name exists\nError Object: cl-mon1", grpc_status:2, created_time:"2024-10-03T18:34:39.7331845+00:00"}" >During handling of the above exception, another exception occurred:
File "C:\Users\forha\ahmedWB1_files\dp0\FFF\MECH\python_journal6", line 163, in
solver.solution.report_definitions.lift['cl-mon1'] = {"zones" : ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear", "wheels"]}
~~~~~~~~~~~^^^^^^^^^^^
RuntimeError: api-create-obj: object with same name exists
Error Object: cl-mon1`I have tried changing the name but I still get the error that an object with the same name exists, and I have no idea why. Also, my terminal says this:
`Information: Converting parameter cd-mon1 to report definition.
Information: Converting parameter cd-mon1 to report definition.
Information: Converting parameter cl-mon1 to report definition.
Information: Converting parameter cl-mon1 to report definition.
Information: No report definitions found. Add one to create output parameter.
Information: No report definitions found. Add one to create output parameter.
Information: No report definitions found. Add one to create output parameter.Information: No report definitions found. Add one to create output parameter.Information: No report definitions found. Add one to create output parameter.Information: No report definitions found. Add one to create output parameter.
Information: No report definitions found. Add one to create output parameter.
Information: No report definitions found. Add one to create output parameter.Error: api-create-obj: object with same name exists
Error Object: "cl-mon1"
Error: api-create-obj: object with same name exists
Error Object: "cl-mon1"`Again, if I put the line "solver.solution.report_definitions.drag['cd-mon1'] = {"zones" : ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear", "wheels"]}" after
"solver.solution.report_definitions.lift['cl-mon1'] = {"zones" : ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear", "wheels"]}`" I would get the same error.The final question I want to bring up is how to actually compute the drag/lift in the end. I this code at the end:
drag_val = solver.solution.report_definitions["cd-mon1"]".compute
But I just gives an error. I've tried many combinations of this formate, but to no avail. I think this should be a simple fix, I just need to find the correct function, but I haven't had any luck finding it.Sorry for taking so long to reply, and thanks for all of your help!
0 -
It appears that I've been mistaken once again. My claim that the order of the report definitions doesn't have an effect seems to be incorrect. I made that claim because in these lines of code:
solver.solution.report_definitions.drag['cl-mon1'] = {"zones" : ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear", "wheels"]} solver.solution.report_definitions.lift['cd-mon1'] = {"zones" : ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear", "wheels"]}
I would switch the places of cl-mon1 and cd-mon1 and I would get the same error at the solver.solution.report_definitions.lift. to get:
solver.solution.report_definitions.drag['cd-mon1'] = {"zones" : ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear", "wheels"]} solver.solution.report_definitions.lift['cl-mon1'] = {"zones" : ["wall_ahmed_body_main", "wall_ahmed_body_front", "wall_ahmed_body_rear", "wheels"]}
However, when I switch the places of solver.solution.report_definitions.drag and solver.solution.report_definitions.lift the error still happens at solver.solution.report_definitions.lift. So apparently, there's something intrinsically different with the solver.solution.report_definitions.lift function than the solver.solution.report_definitions.drag function. And yes, I still can't compute the number for either of them.
0