Transcript
Transcript
In this lesson, we will go through how we can set up and run an nTop C using two simple examples that will each demonstrate the two methods of either putting your inputs directly in the command line or by using an input JSON file to do the same thing. We will start with this first simple box example, which will show that first method, and so let’s create our box.I’m going to leave everything as is, and what we want to be able to do with this workflow is to have inputs and outputs here. Similarly to how we create our custom blocks, we want there to be three sections in our notebook: so inputs, the workflow itself, and the output. So we want to be able to change the length, width, and height of this box. So I will make each of these a variable by right-clicking on them and choosing Make Variable, and then putting these into the input section. We can also alternatively right-click and choose Make Model Input.And then this box itself, I’ll also make into a variable. We want to export the information about its surface area, and so I’m going to click on this white line, press S to search for Surface Area from Body, and then bringing this implicit box into the body input, we can right away see the calculation based on these current inputs that we have. So I’ll call this variable surface area. We can just drag and drop it or type it in to the output to choose it as our output.So now we do have that very short workflow and our three inputs and one output. What we can additionally do, if we want to go beyond this just one output, we can leave it as is and run nTop like this, or we can still, if we want a little bit more information out of this workflow, we want to export an STL file as well as another text file that prints the dimensions of the box and the corresponding surface area. We can do that using Export blocks. So I’ll type S and search for Export. The first one I will do is Export Mesh, and then the second one is Export Text for our text file.And once we fill these in, each of them, we’re going to generate those respective files into the path that we choose, and based on what inputs we give them here. So let’s start with that mesh. To be able to output this mesh, we have to first convert it into a mesh from implicit body. So double click into this input and choose Mesh from Implicit Body and bring in our box. And let’s collapse these so that we have a better view of the rest of the blocks. The tolerance, I will give 1 mm, and that should be fine. The path, I’ll leave open for now because they’ll be the same thing that we do for both of these two Export blocks.To export the text, we need to first think about what text we want to print, and what I want to have is the information about the dimensions. So in this case, it’ll be 10 by 10 by 10, and then print the surface area value, which is this 598.22 mm squared. To do that, we need to convert scalar to text, and there’s this block Text from Scalar. And we can bring in each value and give it a reference. Say if you want it to be in millimeters, you can put in 1 millimeter. So I’ll bring in the length as my first value, and then 1 mm as reference, and then precision 3 is fine. And we can see here that it says 10, which is that same value as we see above for this input. I’ll do the same for all other values. So duplicate, and instead of length, we’ll do width. And then again, duplicating this for height. And we’ll also want that same thing for surface area. So choose surface area. I’ll actually make the reference 1 to the power 6 and e to the 6, and make this position eight digits.Now that we have the text form of these scalar values, we can concatenate them together to form our text that we want to print. So to do that, I’ll grab the Concatenate Text block and bring in our length as the first item, our width as the second one, and the delimiter we can choose. In this case, I’ll use X for 10×10. And then doing the same thing again, nesting this first concatenate text into another concatenate block, we can add the third item, which is the height, and then giving it that same X in the middle. So 10 by 10 x 10 is now what we have, which corresponds to our length * width * height. I’m going to make this a variable called length * width * height, and let’s collapse this.Now we have these two information points: length with height, so the dimensions, and the surface area value. We can do that same concatenate text. The first item being this length with height, the second item, the scalar value converted into text for the surface area. But instead of that X, I’m going to this time add a few spaces and type in “surface area” and then maybe two more spaces and then click outside of that.If we go into the properties, we can see what this will look like. So that’s what I want to print out, and I’m satisfied with that. So I’ll make this into a variable called “text” and I’ll put this into our Text Export block.Now we have the content for both of our Mesh Export and Text Export blocks. The only thing we need to do is generate a path, and to do this, we also need to give each of them the file extension type. So let’s start with this first one, and we’ll use that same Concatenate Text block in order to achieve this. It’s grabbing that same block.This time, I’m going to go into my folder, which is this path right here, and I’ll paste it over. This is where I want the files to be exported out to, and I also want to give this exported mesh file a name which is called “box” and then “STL” file extension. And then the delimiter will be the forward or backward slash, it doesn’t matter. And this will be our output file path for the STL.I’m going to reuse the same path of the folder for the Export Text block as well. So I’ll put “output directory” as its variable name and then make this the same path right here. Now because we didn’t put in the file path, it’s erroring, so we need to make sure we remember to do that. So let’s X out of this and then do Concatenate Text here so that we can put in that directory and then name this file “surface area.txt” and the slash, and also just make this a variable so we can easily track this output file path text.Now we have these two export blocks with the designated file paths and extension type. And so I’m going to move this up and put this output directory variable into the input so that if we do want to change the path of this, everything that is included will also be in here. And now we see that there’s an incomplete block. We forgot to put in the path for this one. But if we were to just run, try to run nTop like this, it’s not going to work because we need to make sure that everything within the workflow that we’re going to use for nTop CL is computed. So let’s go ahead and put that in, and now it’s computed.If we open up our folder where we designated the file, that’s just the first run of that notebook. We see that it’s printing what we want it to, and it’s creating the STL file. And so we can start to run this on the command line. I’ll open up Windows PowerShell, and we will have to go into the right folder structure where we have the file save. And if you have the folder open, what you can do is hold Shift and right-click and then choose “Open PowerShell window here,” and that will be already in the right correct directory. And so you don’t have to go in and define your directory. But I will show how you can do that by going in using “CD” and then typing out your folder path.So I have this in nTop Basics and in the Box example folder. And we can check inside that folder by typing “dir” and pressing Enter. And so I have that nTop file and the STL and text that was generated just from running the nTop notebook from the GUI. And now if I want to go back into the folder structure, I can do “CD ..” and let’s check what we have here. I have previously created this “box with a space example” just to show that if you are creating your folders and file names, it’s good to not have any spaces in them because if we do want to go into those files…Now we have these two information points: length with height, so the dimensions, and the surface area value. We can do that same concatenate text. The first item being this length with height, the second item, the scalar value converted into text for the surface area. But instead of that X, I’m going to this time add a few spaces and type in “surface area” and then maybe two more spaces and then click outside of that.If we go into the properties, we can see what this will look like. So that’s what I want to print out, and I’m satisfied with that. So I’ll make this into a variable called “text” and I’ll put this into our Text Export block.Now we have the content for both of our Mesh Export and Text Export blocks. The only thing we need to do is generate a path, and to do this, we also need to give each of them the file extension type. So let’s start with this first one, and we’ll use that same Concatenate Text block in order to achieve this. It’s grabbing that same block.This time, I’m going to go into my folder, which is this path right here, and I’ll paste it over. This is where I want the files to be exported out to, and I also want to give this exported mesh file a name which is called “box” and then “STL” file extension. And then the delimiter will be the forward or backward slash, it doesn’t matter. And this will be our output file path for the STL.I’m going to reuse the same path of the folder for the Export Text block as well. So I’ll put “output directory” as its variable name and then make this the same path right here. Now because we didn’t put in the file path, it’s erroring, so we need to make sure we remember to do that. So let’s X out of this and then do Concatenate Text here so that we can put in that directory and then name this file “surface area.txt” and the slash, and also just make this a variable so we can easily track this output file path text.Now we have these two export blocks with the designated file paths and extension type. And so I’m going to move this up and put this output directory variable into the input so that if we do want to change the path of this, everything that is included will also be in here. And now we see that there’s an incomplete block. We forgot to put in the path for this one. But if we were to just run, try to run nTop like this, it’s not going to work because we need to make sure that everything within the workflow that we’re going to use for nTop CL is computed. So let’s go ahead and put that in, and now it’s computed.If we open up our folder where we designated the file, that’s just the first run of that notebook. We see that it’s printing what we want it to, and it’s creating the STL file. And so we can start to run this on the command line. I’ll open up Windows PowerShell, and we will have to go into the right folder structure where we have the file save. And if you have the folder open, what you can do is hold Shift and right-click and then choose “Open PowerShell window here,” and that will be already in the right correct directory. And so you don’t have to go in and define your directory. But I will show how you can do that by going in using “CD” and then typing out your folder path.So I have this in nTop Basics and in the Box example folder. And we can check inside that folder by typing “dir” and pressing Enter. And so I have that nTop file and the STL and text that was generated just from running the nTop notebook from the GUI. And now if I want to go back into the folder structure, I can do “CD ..” and let’s check what we have here. I have previously created this “box with a space example” just to show that if you are creating your folders and file names, it’s good to not have any spaces in them because if we do want to go into those files, let’s type “box” and then tab. We’ll need to add quotation marks around any kind of names or folders that have spaces in them, so this is just something to keep in mind. So, I’m tapping again just to get back to the Box example.Now we can start putting in our command for nTop. I can put in “nTop” and it will generate the menu of options of arguments that you can use to run nTop CL. For the first command, I’m going to just type “nTop” so that it runs and opens up a GUI so that we can more easily see what’s happening.We’ll need to input the variables that we have declared here as inputs, and the first one is the output directory. It has to be in the order of what shows up in the notebook, so I’m going to type in where I want this to be, which is in my nTop CL Basics folder. This is really convenient if you have something that you want to say, make another folder in the structure and then put the new files in there. You can do that with this input directory. For this, I’m going to do 2x2x2 and also save, then type the name of the nTop file and then press enter and it’ll open up that GUI.So we do have an error, and it is related to the units. This is because we only typed into the command line “222” as just numbers with no units. If the units were embedded into this input, then you wouldn’t have this problem. You can just put in “222” and then the notebook will recognize that it’s that embedded unit, millimeters. But since we don’t have this in our notebook, we can go back up. I just typed “up” and I’m going to go in and add millimeters into my input variables and then run this whole command again.It looks like this is working fine with no issues. The inputs are in there as 222, and then if we open up that folder, our text is now also saying 2x2x2 with that surface area value.Now I will run the nTop CL without the GUI this time and change that directory to our other folder that has the space in between. And let’s do 7 mm by 2 m and save box on top and let’s run that. So it’s not going to open up nTop.I made the mistake in that folder structure name. Instead of putting a space, I put in an underscore, so it errored. But after correcting this, we can see that the output files are generated in this box example with the space in between. And the file, since we typed in the -s, if we open that up, we’ll see that these numbers are saved in there as well.So that’s the first method. For the second method, which uses an input Json file to pass through to nTop CL, we will work with this lattice example. We’ll create a lattice that will be able to be changed based on the input lattice type and we’ll just simply output the lattice porosity value, which we’ll calculate within the workflow.So let’s start by grabbing the Rectangular Volume Lattice block. We’ll keep the volume relatively simple using a box, and the unit cell will be a unit a graph unit cell. And I’ll just choose simple cubic for now. And we’ll make this unit cell type into our variable called lattice type. We’ll put this into our input section. I’ll leave the unit c size to five and the thickness is, we’ll use, 0.5 mm. So we’ve created just a very simple structure and I’ll make this lattice variable called lattice.And we’ll calculate the porosity value by first getting the mass of each body. So I’ll get the MH Properties from Body block and duplicate it. The first one will do for the box. We’ll also make this into a variable so that we can use it again here. And the second mass we want is for the lattice and the density. I’ll keep to one for both because that’s not important for the calculation. And then to get the porosity value, I will divide the volume of the lattice, which we can get from that properties tab, and divide that by the volume of the box. And then we’ll subtract with this value. One minus this value will give us the porosity. And we’ll make this a variable and then put it into our output section.So right now, we have a full workflow that gives us the porosity of the lattice according to the input with the lattice type. This means that since we have a full workflow with all three parts of sections filled, we can save this and start our nTop CL. I can go into the folder where I am working out of and hold shift, right click and open Window PowerShell from there. And the first command I’ll do is to just generate our nTop input and output JSON template with the command -t and the name of the notebook. And that will run. We’ll wait to see our templates in this folder.If we open up this input template, we can see that it has the variable that we have put in the input section. If they’re more than one, then there will be an array of inputs in this same structure. And the name is lattice type. The type of the input is enum. If we try to do this type of input for the previous method, we won’t be able to do that because it can only support either string or integer type input values. But here we can do that. And we have the value here which we can change. So if I want to modify this to five, which is the index of the diamond type, and then save this file into that input template and let’s run nTop CL with velocity level two to see the runtime information. And I’m going to use the -dj for input and then use the input template as our input file and then create an output file called output.json and then type in our lattice nTop nTop file. Let’s see what this does.So it’s finished running, and if we look in the folder, we also see the output file here. This is the value if we change the input to Diamond, and let’s compare this 95076, which is the rounded up eight.If you also want to have a list of values that you want it to run through, we can change this input template to values and make it a list of say, zero, one, two, three, four, for the first five items in this list of lattice types. And I’ll save this as a new input file.[Music]And if we run this again with a different input file, let’s put output one. This will run five times, each with one of the inputs that we’ve put in. So you can see here, already with the runtime information, we’re getting a lot more information than the previous run.And it’s finished running. So if we open up that output one file, we are getting an array of values that correspond to our zero, one, two, three, and four input values for those lattice type indices. That’s it for the nTop CL part. You can scale up and do anything you want with this. Integrate with other software using Python codes or other languages, or any kind of MDO software.We have an example template Python file that you can use to get started and write your own code for what you want to do with it. What it does is imports necessary modules and goes into the current directory and the execution file for nTop. If you have it in a different path, you will need to change this. Otherwise, you can leave it as is and then just change this nTop file path to the file name that you’re working with, and save this script into that same folder.And you’re going to also need to copy and paste content from the input template that we did together earlier into here as well. Put in a for loop, and you’ll be able to run this through the nTop arguments that calls for nTop, creates input JSON file that will be added into that nTop call, and then returns an output file and prints the results.So I have a code for this example that has been modified from this template. So in addition, we’re getting time as well as a folder structure where we’ll put all the data of each execution into. With each execution of nTop, with this, we have the file name in here, and I’ve already copied and pasted our input template content into this input JSON variable and added the design variations of Lattice Type zero all the way to index four.It also creates a CSV file with a summary. So at the heading of the file, we’ll have Lattice Type for this design variation, and we’ll have porosity. And this for loop runs nTop CL for each of the inputs that we’re giving it and creating that input and output files as well as an nTop notebook with those inputs into that designated data folder.And we’ll also, with each run, get printed information on the screen of the Lattice Type and the porosity, as well as at the end, the total runtime. So let’s go ahead and run this code, and it’s starting the first iteration, already seeing the first results with this Lattice Type zero, simple cubic, and this is the value of the corresponding porosity.We have all the executions done, and let’s open up the folder. We have the output summary file in CSV format, so we get all of this information in one file as well as the data in each folder with input and output JSON files, as well as the saved notebook with the cache input variables for each of the runs.

