CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

script for replacing block of code

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 14, 2013, 11:18
Default script for replacing block of code
  #1
Member
 
Join Date: Nov 2012
Posts: 83
Rep Power: 13
Henning86 is on a distinguished road
Im runnning OpenFoam on a server. im exchanging the data with samba and do the post processing with paraview on windows the problem is that paraview doesn't know the bc:

Code:
inflow
{
type uniformFixedValue; 
uniformValue table 
(
( 0 (0 0 0.0))
( 0.0005 (50 0 0.0)) 
( 0.0025(600 0 0)) 
);
}
so i can't see the velocity field. I want to replace the solution with a different BC for example

Code:
inflow
{
type fixedValue;
value uniform (600 0 0);
}
With that bc im able to see the the velocity field with paraview on the local windows machine.

I am looking for a script that is able to replace the whole String block with another one

I just manage do replace a string with a script in the subfolder my code for that is (which works but doesn't solve the problem):

Code:
#!/bin/bash
find . -name "*.txt" -exec sed -i 's/old/new/g' {} \;
Im unable to find a sed code that will do the job.

Can anybody post a script that will replace the bc with the other one?
Henning86 is offline   Reply With Quote

Old   March 14, 2013, 11:48
Default
  #2
Member
 
Join Date: Aug 2012
Posts: 68
Blog Entries: 1
Rep Power: 13
Nucleophobe is on a distinguished road
In vim, you *can* do multiline find-replace. Just use '\n' to capture newlines.

There's probably a better way, as this gets messy. But you can try:

Code:
:%s/inflow\n{\ntype uniformFixedValue; \nuniformValue table \n(\n( 0 (0 0 0.0))\n( 0.0005 (50 0 0.0)) \n( 0.0025(600 0 0)) \n);\n}/inflow\r{\rtype fixedValue;\rvalue uniform (600 0 0);\r}
The '\r' is also a carriage return. I don't understand why, but if you try to write the '\n' character, it turns into '\@'

Anyways, I just tried this and it worked.
Nucleophobe is offline   Reply With Quote

Old   March 15, 2013, 04:32
Default
  #3
Member
 
Join Date: Nov 2012
Posts: 83
Rep Power: 13
Henning86 is on a distinguished road
im really bad at scripting. so i just replaced sed with vim.tiny followed by the long command:

Code:
#!/bin/bash
find . -name "*.jsp" -exec vim.tiny :%s/inflow\n{\ntype uniformFixedValue; \nuniformValue table \n(\n( 0 (0 0 0.0))\n( 0.0005 (50 0 0.0)) \n( 0.0025(600 0 0)) \n);\n}/inflow\r{\rtype fixedValue;\rvalue uniform (600 0 0);\r}
This gives me an error.

Can vim be used in a script and is vim.tiny able to do that?

vim isn't installed at the server.

i sadly haven't worked with vim at all.
Henning86 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ICEM] Hexa to Sweep block conversion pertupd ANSYS Meshing & Geometry 1 June 19, 2010 21:37
Running Matlab script from Scheme code dhimans Fluent UDF and Scheme Programming 0 July 28, 2009 15:13
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 15:56
What is the Better Way to Do CFD? John C. Chien Main CFD Forum 54 April 23, 2001 08:10
own Code vs. commercial code Bernhard Mueck Main CFD Forum 10 February 16, 2000 10:07


All times are GMT -4. The time now is 20:38.