@@ -198,14 +198,7 @@ def __init__(self, mesh, soln_space, weakform, data_space=[], ndim=2):
198198
199199 self .weakform = weakform
200200
201- # ! Need to implement
202- # Access the connectivity for each space
203- # Initialize the space type for each dof
204- # Stores info about whether the dof is associated H1/Hcurl/Hdiv/L2
205- # self.soln_dof = self.mesh.create_dof(self.soln_space, "soln")
206- # self.data_dof = self.mesh.create_dof(self.data_space, "data")
207- # self.geo_dof = self.mesh.create_dof(self.geo_space, "geo")
208-
201+ # Initialize Dof's
209202 self .soln_dof = DegreesOfFreedom (mesh , "H1" , "soln" )
210203 self .geo_dof = DegreesOfFreedom (mesh , "H1" , "geo" )
211204 self .data_dof = DegreesOfFreedom (mesh , "H1" , "data" )
@@ -214,55 +207,35 @@ def __init__(self, mesh, soln_space, weakform, data_space=[], ndim=2):
214207
215208 def create_model (self , module_name : str ):
216209 """Create and link the Amigo model"""
217-
218210 model = am .Model (module_name )
219211
220- # Get the degrees of freedom associated with H1
221- # self.soln_dof.add_source(model)
222- # self.data_dof.add_source(model)
223- # self.geo_dof.add_source(model)
224-
212+ # Get the names of things associated with H1
225213 input_names = self .soln_space .get_names ("H1" ) # rho
226214 data_names = self .data_space .get_names ("H1" ) # x, y
227215 geo_names = self .geo_space .get_names ("H1" ) # x, y
228216
229- # a generalized amigo source component
230- """
231- class DofSource(am.Component):
232- def __init__(self):
233- super().__init__()
234-
235- # Filter input values
236- self.add_input("rho")
237- self.add_data("x")
238- self.add_data("y")
239-
240- self.dof_src = DofSource()
241- model.add_component("src", nnodes, node_src)
242- """
217+ # Create amigo component with input names and geo names
243218 self .dof_src = DofSource (input_names = input_names , geo_names = geo_names )
219+
220+ # Add global mesh source component
244221 nnodes = mesh .get_num_nodes ()
245222 model .add_component ("src" , nnodes , self .dof_src )
246223
247224 # Build the elements for all domains
248225 domains = self .mesh .get_domains ()
249226 for domain in domains :
250227 for etype in domains [domain ]:
251- """
252- helmholtz = Helmholtz()
253- """
254228 # Build a finite-element for each weak form
255229 elem_name = f"Element{ etype } _{ domain } "
256230
257- # basis.TriangleLagrangeBasis() objects
258231 soln_basis = self .soln_dof .get_basis (
259- etype , "H1" , names = [ "rho" ] , kind = "input"
232+ etype , "H1" , names = input_names , kind = "input"
260233 )
261234 data_basis = self .data_dof .get_basis (
262- etype , "H1" , names = [ "x" , "y" ] , kind = "data"
235+ etype , "H1" , names = data_names , kind = "data"
263236 )
264237 geo_basis = self .geo_dof .get_basis (
265- etype , "H1" , names = [ "x" , "y" ] , kind = "data"
238+ etype , "H1" , names = geo_names , kind = "data"
266239 )
267240
268241 # Create the quadrature instance
@@ -277,6 +250,9 @@ def __init__(self):
277250 quadrature ,
278251 self .weakform ,
279252 etype ,
253+ input_names ,
254+ data_names ,
255+ geo_names ,
280256 )
281257
282258 # Get the connectivity
@@ -285,27 +261,31 @@ def __init__(self):
285261
286262 # Add the element/component
287263 nelems = conn .shape [0 ]
288- """
289- model.add_component("helmholtz", nelems, helmholtz)
290- """
291264 model .add_component (elem_name , nelems , elem )
292265
293266 # Link all the element dof to the component
294- """
295- model.link("helmholtz.y_coord", "src.y_coord", tgt_indices= self.geo_dof)
296- model.link("helmholtz.x_coord", "src.x_coord", tgt_indices= self.geo_dof)
297- model.link("helmholtz.rho", "src.rho", tgt_indices=self.soln_dof)
298- """
299- self .soln_dof .link_dof (model , "rho" , elem_name , conn )
300- self .geo_dof .link_dof (model , "x" , elem_name , conn )
301- self .geo_dof .link_dof (model , "y" , elem_name , conn )
267+ for name in input_names :
268+ self .soln_dof .link_dof (model , name , elem_name , conn )
269+
270+ for name in geo_names :
271+ self .geo_dof .link_dof (model , name , elem_name , conn )
302272
303273 return model
304274
305275
306276class FiniteElement (am .Component ):
307277 def __init__ (
308- self , name , soln_basis , data_basis , geo_basis , quadrature , weakform , etype
278+ self ,
279+ name ,
280+ soln_basis ,
281+ data_basis ,
282+ geo_basis ,
283+ quadrature ,
284+ weakform ,
285+ etype ,
286+ input_names = [],
287+ data_names = [],
288+ geo_names = [],
309289 ):
310290 super ().__init__ (name = name )
311291
@@ -323,18 +303,18 @@ def __init__(
323303
324304 # The x/y coordinates
325305 if etype == "CPS3" :
326- self .add_data ("x" , shape = (3 ,))
327- self .add_data ("y" , shape = (3 ,))
328-
329- # The implicit topology input/output
330- self .add_input ("rho" , shape = (3 ,))
306+ shape = (3 ,)
331307
332308 elif etype == "CPS4" :
333- self .add_data ("x" , shape = (4 ,))
334- self .add_data ("y" , shape = (4 ,))
309+ shape = (4 ,)
335310
336- # The implicit topology input/output
337- self .add_input ("rho" , shape = (4 ,))
311+ # Data
312+ for name in geo_names :
313+ self .add_data (name , shape = shape )
314+
315+ # Inputs
316+ for name in input_names :
317+ self .add_input (name , shape = shape )
338318
339319 # Set the arguments to the compute function for each quadrature point
340320 self .set_args (self .quadrature .get_args ())
@@ -366,7 +346,6 @@ def compute(self, **args):
366346
367347
368348def weakform (soln , data = None , geo = None ):
369- print (soln ["rho" ])
370349 u = soln ["rho" ]
371350 uvalue = u ["value" ]
372351 ugrad = u ["grad" ]
@@ -384,8 +363,6 @@ def weakform(soln, data=None, geo=None):
384363 # rho = data["rho"]["value"]
385364
386365 f = am .sin (x ) ** 2 * am .cos (y ) ** 2
387-
388- # return 0.5 * (uvalue**2 + basis.dot_product(ugrad, ugrad, n=2) - 2.0 * uvalue * f)
389366 return 0.5 * (uvalue ** 2 + basis .dot_product (ugrad , ugrad , n = 2 ) - 2.0 * uvalue * f )
390367
391368
0 commit comments